Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Phalcon Cli, beanstalkd worker + multi-module app

Hi, This is my first phalcon-based project, I have started with multi-module structure and everything seems good. Now I am trying to add image processing using beanstalkd. However, I am not quite sure what is the best practice to build a beanstalkd worker.

Using the doc as example; roll a standalone PHP scrip for image processing. Just like:

<?php 
while (($job = $queue->peekReady()) !== false) 
{ 
    $message = $job->getBody(); 
    // do image processing here 
    $job->delete(); 
}

But this requires phalcon framework in the firstplace. So I have to build a CLI app.

Question: I have already got a multi-module app, how do I re-use all the model classes in a CLI app? I am still learning the bootstrapping file. Is the CLI app sitting on totally seperat router and has nothing in common with the web app?



44.6k
Accepted
answer

I have what I think is a pretty advanced multi-module system. Check out my app/phalcon setup. In particular observe how I bootstrap both environments and also how I separate the services. In short services, services_web and then in the CLI module if it is later needed and not relevant to the web. Then later if its necessary to have somethig particular to all web related modules then a base Module class can be made for those as well.

Please share some of your generic beanstalk code and revelations as I'll be needing that later. I'll likely incorporate the generic aspects of it into my open source project.

Question: I have already got a multi-module app, how do I re-use all the model classes in a CLI app? I am still learning the bootstrapping file. Is the CLI app sitting on totally seperat router and has nothing in common with the web app?

So for I've found that having all of the models in the common directory is working for me alright. In my private project there are two database connections and you can set this in each model. I've created two base classes that models inherit from depending upon where they are stored/organized. I haven't needed to put models into a particular module yet but I may end up doing that particularly for job control models in the CLI module. So please let me know of some of your findings there.