Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Laravel 5.5, how to get the Job ID after we dispatch a job to the job queue?

Until Laravel 5.4, the dispatch() method returned the queue job id.

$job = (new JobClass())->onQueue('queuename');
$jobId = dispatch($job);

dd($jobId); // prints the job id

In 5.5, it returns a PendingDispatch object, which does not seem to have a method to retrieve the job id.

I've already tried with dispatch_now(), but it executes the job immediately and synchronously, while I want it to be executed in the background.

like image 243
SteveVg Avatar asked Oct 17 '17 08:10

SteveVg


1 Answers

You might also consider using DispatchesJobs trait:

class MyClassName()
{
    use DispatchesJobs;

    ....

    $job = (new JobClass())->onQueue('queuename');

    $jobId = $this->dispatch($job);
like image 114
alexeydemin Avatar answered Sep 27 '22 18:09

alexeydemin