Skip to content

Instantly share code, notes, and snippets.

@chrismcintosh
Created December 12, 2023 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcintosh/af034c03dea9b8828cc008b3334f2985 to your computer and use it in GitHub Desktop.
Save chrismcintosh/af034c03dea9b8828cc008b3334f2985 to your computer and use it in GitHub Desktop.
<?php
/******************************************************************************************************
* Job Event Listeners
* https://github.com/laravel/framework/tree/10.x/src/Illuminate/Queue/Events
*/
Event::listen(function (JobTimedOut $event) {
Log::warning("Job Timed Out: {$event->job->resolveName()}", [
'job_uuid' => $event->job->uuid(),
'attempts' => $event->job->attempts(),
]);
});
Event::listen(function (JobFailed $event) {
Log::critical("Job Failed: {$event->job->resolveName()}", [
'job_uuid' => $event->job->uuid(),
'attempts' => $event->job->attempts(),
'exception' => $event->exception->getMessage(),
'exception_trace' => $event->exception->getTraceAsString(),
]);
});
Event::listen(function (JobReleasedAfterException $event) {
Log::warning("Job Released Back to Queue due to exception in: {$event->job->resolveName()}", [
'job_uuid' => $event->job->uuid(),
'attempts' => $event->job->attempts(),
]);
});
Event::listen(function (JobExceptionOccurred $event) {
Log::error("Job Exception Occurred: {$event->job->resolveName()}", [
'job_uuid' => $event->job->uuid(),
'attempts' => $event->job->attempts(),
'exception' => $event->exception->getMessage(),
'exception_trace' => $event->exception->getTraceAsString(),
]);
});
Event::listen(function (JobProcessing $event) {
Log::info("Job Processing: {$event->job->resolveName()} ID: {$event->job->uuid()} Attempts: {$event->job->attempts()}", [
'job_uuid' => $event->job->uuid(),
'attempts' => $event->job->attempts(),
]);
});
Event::listen(function (JobRetryRequested $event) {
Log::warning("Job Retry Requested");
});
Event::listen(function (JobQueued $event) {
Log::debug("Job Queued: {$event->id}");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment