Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] allow scheduling of queued jobs #18235

Merged
merged 3 commits into from Mar 7, 2017

Conversation

@tomschlick
Copy link
Contributor

commented Mar 7, 2017

As proposed in laravel/ideas#457, this simple addition allows us to schedule a job to be queued at a specific interval.

This enables you do have something like this

# /app/Console/Kernel.php

$schedule->job(new Heartbeat())->everyFiveMinutes();

In this example, you might be scheduling a heartbeat to be run from the queue workers themselves. This is something I currently do in production which ping's Envoyer's heartbeat endpoints to tell me if a queue is backed up for too long.

Right now, if you want to do this you have to either create a dedicated command per job you want to schedule, or use the $schedule->call(); method passing in a closure which can be overly verbose for the Kernel file. This provides a clean abstraction to that.

tomschlick added 3 commits Mar 7, 2017
@leo108
Copy link

left a comment

Since this is a new feature, I think it's better to do the changes base on master branch

* @param \Illuminate\Contracts\Queue\ShouldQueue $job
* @return \Illuminate\Console\Scheduling\Event
*/
public function job(ShouldQueue $job)

This comment has been minimized.

Copy link
@leo108

leo108 Mar 7, 2017

Why not add a $name = null as the second parameter?

This comment has been minimized.

Copy link
@tomschlick

tomschlick Mar 7, 2017

Author Contributor

Name is used solely for the cache mutex name. I don't see a case where you'd want to set that as anything other than the full class name of the Job.

This comment has been minimized.

Copy link
@leo108

leo108 Mar 7, 2017

@tomschlick my bad, I mixed it up with the scheduled command name

@tomschlick

This comment has been minimized.

Copy link
Contributor Author

commented Mar 7, 2017

Features that don't have compatibility usually go on the current branch in this repo. Master is for 5.5.

@taylorotwell taylorotwell merged commit 0a9d6d0 into laravel:5.4 Mar 7, 2017

2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@taylorotwell

This comment has been minimized.

Copy link
Member

commented Mar 7, 2017

Merged with a few tweaks... I removed the ShouldQueue type-hint in case people are using jobs in a synchronous "command-bus" fashion, also allowed passing a string class name which will resolve the job from the container. Thanks!

@tomschlick

This comment has been minimized.

Copy link
Contributor Author

commented Mar 7, 2017

sounds good, thanks!

@tomschlick tomschlick deleted the tomschlick:patch-3 branch Mar 7, 2017

@LasseRafn

This comment has been minimized.

Copy link
Contributor

commented Mar 8, 2017

Wow... no more commands that queues jobs 🎉👍🏻

@dmason30

This comment has been minimized.

Copy link

commented Sep 7, 2017

@taylorotwell This should be added to the docs. Had to find this PR to find out if it this functionality existed. Doesn't appear to be in 5.4/5.5 docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.