Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Created November 28, 2019 15:43
Show Gist options
  • Save stevebauman/3d6babeb58c5d5381beb3118b221794e to your computer and use it in GitHub Desktop.
Save stevebauman/3d6babeb58c5d5381beb3118b221794e to your computer and use it in GitHub Desktop.
Run Laravel queue's from an HTTP endpoint
<?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