Cake 3.x How to setup a queue technology for jobs and news feeds?

江枫思渺然 提交于 2020-07-19 18:32:44

问题


I am using Cake 3.x

I need to have the following things set up.

  1. A job queue to queue jobs that require long processing in the background
  2. A feed (like Facebook Feed) that informs various users of what's happening within the app

This is what I have in terms of requirements:

Job Queue

This needs to be persistent and reliable. Meaning to say if the server suddenly rebooted, any jobs queued but not yet executed will still be there waiting to be processed upon reboot.

News Feed / Activity Stream

This need not be persistent and can be delayed. Just like Facebook. Basically it's to display events that have happened.

Something like

User1 commented on your post. (2 seconds ago)
User2 liked your post. (3 mins ago)
User2 & User1 favorited your post (5 mins ago)

What Queue should I use within context of a Cake3 web app?

What queue technology should I use for

  1. job queue (persistence required, order of the jobs is also important)
  2. news feed / activity stream (no need for persistence, order is not important)

within the context of a Cake 3.x web app?

I am a newbie to queue technology. I am happy to use even cloud computing queue services like Amazon Message Queuing Service (SQS).

I would prefer a solution that works well with CakePHP 3.x architecture. Perhaps a CakePHP plugin?

I am also okay to setup 2 different queue technologies to satisfy the 2 different requirements.


回答1:


A popular Cakephp plugin that supports Cake 2 & 3: https://github.com/dereuromark/cakephp-queue

I believe it would suit you well for your job queue. However, it wouldn't be too difficult to code one from scratch. You could have a table with the following attributes, for instance: job_type, priority, min_execute_date, completed, etc. Then schedule a cron job to execute a custom Shell of your own that would query that table and look for jobs with the highest priority that haven't completed yet. It would check the job_type and run the relevant tasks. If they successfully complete, mark them as completed. This setup wouldn't ever miss a job.

The news feed could be similar but I don't think you would need a scheduler. Just incorporate it into your application logic. You'd have a newsfeed that would just be a running list of the most recent items. What you are speaking of sounds like notifications. For notifications you could just set them as viewed once they click on them or view them, which at that point you could either remove them from the list or style them.



来源:https://stackoverflow.com/questions/33991651/cake-3-x-how-to-setup-a-queue-technology-for-jobs-and-news-feeds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!