imTigger / laravel-job-status

Add ability to track Job progress, status and result dispatched to Queue.
MIT License
407 stars 60 forks source link

Monitor chained jobs? #19

Closed sheriffmarley closed 4 years ago

sheriffmarley commented 6 years ago

I need to chain multiple jobs. First job ImageResize second ShareOnSites, maybe there will be more in the Future. Till now I added them to the queue like

$job = ImageResize::withChain([
    new ShareOnSites
])->dispatch($image);

But i need to track them.

As far as I see it, for each job, even if they are chained, a new job status is created. So how can I track the second job as soon as the first one finished? I would store in in the image table as job_id column.

Can I get the second job_id in the handle() method of job two, or how would I have to do this?

Namoshek commented 6 years ago

From what I understand, the moment you call $this->prepareStatus() in the constructor of a job, you will have access to it through getJobStatusId(): https://github.com/imTigger/laravel-job-status/blob/8d0dc85bc09e7949ec0f7a3de90f4cf5b28e41ba/src/Trackable.php#L55-L65

So in theory, you should be able to use the following:

$shareJob = new ShareOnSites();
$job = ImageResize::withChain([
    $shareJob
])->dispatch($image);

// $job->getJobStatusId() == first job id
// $shareJob->getJobStatusId() == second job id
imTigger commented 4 years ago

You can use "Improve job_id capture" feature >= 1.0.0 to catch job_id on new jobs. It also works on chained jobs.