We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Task Queue Implementation

Hello guys,

I have experience in Drupal and recently migrated to Phalcon development.

I would like to implement a queue of tasks to be executed through a cron call, just like Drupal does.

I'm using a very good SidRoberts library for the cron implementation in Phalcon, but I still have to do the task queue implementation to use cron.

Has anyone done the implementation of this solution?

Thank you all for the help.



3.4k
edited Mar '17

Hi H,

Thanks for the quick response.

I have already set up and run the tasks correctly in my environment. I've also done the SidRoberts cron install and make his calls via crontab, as specified in his github (this cron Is nothing more than a specific task).

I just want to know how I can implement a task queue. The implementation would look like this: through a controller action I would be able to add a call to a cron job.

For this to work correctly, I need to know how I can integrate a cli task into a Phalcon controller.

Thank you for your attention.

Are you asking how to set up Tasks?



3.4k

I'm unsure if I'm understanding correctly, but you'd pass the controller and action as a parameter on the cron.

For example;

# Get the cli to call the voucher controller  then the report action
php -f cli.php voucher report

If you want to trigger a job in x seconds from a controller, have a look at the beanstalk queue and get the queue to trigger something.

Hi H,

Thanks for the quick response.

I have already set up and run the tasks correctly in my environment. I've also done the SidRoberts cron install and make his calls via crontab, as specified in his github (this cron Is nothing more than a specific task).

I just want to know how I can implement a task queue. The implementation would look like this: through a controller action I would be able to add a call to a cron job.

For this to work correctly, I need to know how I can integrate a cli task into a Phalcon controller.

Thank you for your attention.

Are you asking how to set up Tasks?

Hello H, thank you very much for your response.

I deployed the solution using the standard Phalcon queue and the Cron class, as previously reported. The solution worked very well and exceeded my expectations. This implementation is satisfactory so far.

As I'm developing a multi-server project, we may have trouble using it on Windows servers. The beanstalkd service works great for Linux servers, however there are some limitations to its installation on Windows servers.

Is there any alternative to implement this queue without using the beanstalkd service installed? Is it possible to implement the queue using a database just like it is done in Drupal?

I'm unsure if I'm understanding correctly, but you'd pass the controller and action as a parameter on the cron.

For example;

# Get the cli to call the voucher controller  then the report action
php -f cli.php voucher report

If you want to trigger a job in x seconds from a controller, have a look at the beanstalk queue and get the queue to trigger something.

Hi H,

Thanks for the quick response.

I have already set up and run the tasks correctly in my environment. I've also done the SidRoberts cron install and make his calls via crontab, as specified in his github (this cron Is nothing more than a specific task).

I just want to know how I can implement a task queue. The implementation would look like this: through a controller action I would be able to add a call to a cron job.

For this to work correctly, I need to know how I can integrate a cli task into a Phalcon controller.

Thank you for your attention.

Are you asking how to set up Tasks?



3.4k
Accepted
answer

Hi,

Sorry for the late reply, unfortunately I cannot help you as I have no experience with Windows servers.

However, you could use Gearman - https://php.net/manual/en/book.gearman.php - and instead use that API instead of Phalcon\Queue\Beanstalk.

Hello H, thank you very much for your response.

I deployed the solution using the standard Phalcon queue and the Cron class, as previously reported. The solution worked very well and exceeded my expectations. This implementation is satisfactory so far.

As I'm developing a multi-server project, we may have trouble using it on Windows servers. The beanstalkd service works great for Linux servers, however there are some limitations to its installation on Windows servers.

Is there any alternative to implement this queue without using the beanstalkd service installed? Is it possible to implement the queue using a database just like it is done in Drupal?

I'm unsure if I'm understanding correctly, but you'd pass the controller and action as a parameter on the cron.

For example;

# Get the cli to call the voucher controller  then the report action
php -f cli.php voucher report

If you want to trigger a job in x seconds from a controller, have a look at the beanstalk queue and get the queue to trigger something.

Hi H,

Thanks for the quick response.

I have already set up and run the tasks correctly in my environment. I've also done the SidRoberts cron install and make his calls via crontab, as specified in his github (this cron Is nothing more than a specific task).

I just want to know how I can implement a task queue. The implementation would look like this: through a controller action I would be able to add a call to a cron job.

For this to work correctly, I need to know how I can integrate a cli task into a Phalcon controller.

Thank you for your attention.

Are you asking how to set up Tasks?