[Proposal] Add an option to convert scheduled task commands to queue jobs #457
Description
The purpose of this proposal is to create an easier way to balance scheduled tasks between multiple servers.
We can only set up the schedule:run
cronjob in only one server right now, if there are many big scheduled tasks in a project, the server load of cronjob server may become very high and slow down the tasks which may cause unexpected problems.
For current version of Laravel (5.4), we can create a job that implements ShouldQueue
and create an artisan command that triggers the job to do what we want, but why not provide an easier way to do this?
For example, we make an artisan command class implements ShouldQueue
, when schedule:run
triggered, it finds that the scheduled task implements ShouldQueue
, then it dispatches a built-in job called RunScheduledTaskJob
.
Or add a method called queue
to Illuminate\Console\Scheduling\Event
class, so that we can define a scheduled task by
$schedule->command('foo:bar')->queue($queueName)->everyThirtyMinutes();
Activity
tomschlick commentedon Mar 7, 2017
It might be better just to eliminate the middleman there and allow the scheduling of jobs directly...
leo108 commentedon Mar 7, 2017
@tomschlick good idea, but sometimes we may need to run the scheduled task manually, so I think we still need a way to convert artisan command to queue job.
tomschlick commentedon Mar 7, 2017
I'm going to look into this tonight to see how viable it is... I really like this as I have a few commands that only exist to throw jobs in the queue every X minutes.
tomschlick commentedon Mar 7, 2017
Just added a PR for it! :)
tomschlick commentedon Mar 7, 2017
PR was merged. This can prob be closed.