Created
November 28, 2019 15:43
-
-
Save stevebauman/3d6babeb58c5d5381beb3118b221794e to your computer and use it in GitHub Desktop.
Run Laravel queue's from an HTTP endpoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Route::get('/queue', function () { | |
echo "Starting Queue...<br/>"; | |
ob_flush(); | |
flush(); | |
Queue::before(function (JobProcessing $event) { | |
$message = "Processing {$event->job->resolveName()}..."; | |
info($message); | |
echo "$message<br/>"; | |
ob_flush(); | |
flush(); | |
}); | |
Queue::after(function (JobProcessed $event) { | |
$message = "Processed {$event->job->resolveName()}"; | |
info($message); | |
echo "$message<br/>"; | |
ob_flush(); | |
flush(); | |
}); | |
Queue::looping(function () { | |
echo "Running queue...<br/>"; | |
ob_flush(); | |
flush(); | |
}); | |
Queue::stopping(function () { | |
echo "Queue finished.<br/>"; | |
ob_flush(); | |
flush(); | |
}); | |
Artisan::call('queue:work', ['--stop-when-empty' => true, '--tries' => 3]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment