I know you can listen to job events using before
, after
and failing
hooks:
https://laravel.com/docs/5.6/queues#job-events
Queue::before(function (JobProcessing $event) {
// $event->connectionName
// $event->job
// $event->job->payload()
});
I only want certain jobs to be picked up here though. These jobs are the ones that extend from a certain abstract base class called AbstractTask
. Normally I would simply perform an instanceof
check but something like this won't work:
$job instanceof AbstractTask
Is there any way I can mark a job to be picked up by these Job Events?
Edit
It seems the actual Job that I want(which is my very own Job class) can be found within the $event->job
like so:
$payload = json_decode($job->getRawBody());
$data = unserialize($payload->data->command);
if ($data instanceof AbstractTask) {
dd($data);
}
I find it hard to believe that there is not an easier way to fetch the underlying Job which actually is being processed so I made a Github issue as well: