Support the ongoing development of Laravel.io →
posted 9 years ago
Queues Jobs
Last updated 2 years ago.
0

One approach that comes to mind, is pushing the next scheduled jobs to a queue. When each job runs, it checks what time it next needs to run, then pushes the next instance of itself to the queue, to run at that time. So far as I can see, you cannot specify a run time for a queued job - you can only specify a delay from now. Ideally a specific runtime would be good (I haven't checked the queue table - maybe it does already work like that under the hood).

The types of schedules I have, will be jobs that need to be run the last Friday of a month, every Monday each two weeks, every Thursday at 5pm, every day at noon - a good mix of all these types of schedules.

Last updated 9 years ago.
0

There is an interesting approach here: https://github.com/chrisboulton/php-resque-scheduler

Instead of using the delay to push a tonne of jobs to a queue and having them all fire off at different times, it keeps the future jobs in a separate table. That table can keep track of the last run time. A regular job can then scan that table to find any jobs that need to be run. Any it finds can be pushed onto a queue for processing, and the scheduled job can then be updated to indicate what the next time is that it should be run. There may be some code I can pinch from that package.

I guess what I need is for a regular job (every five minutes, for example) to be able to ask the question "what needs to be run now, including any jobs in the past that we have missed" and to be able to put any jobs it is told need to be run now, into a queue, and to update the list to indicate which have now been taken on board.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

judgej judgej Joined 4 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.