imTigger / laravel-job-status

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

The job_id is not stored into job_statuses #30

Closed ayelen117 closed 4 years ago

ayelen117 commented 5 years ago

job_id is NULL

laravel-job-status": "^0.2.2", framework": "5.8.*",

crashkonijn commented 5 years ago

That probably has to do with the fact that it's being stored in the before event, which is being called right before the job is processed.

If you call queue:work the id's should become visible.

crashkonijn commented 5 years ago

@imTigger I've created a solution to this problem, since the branch also has the changes for #33 I'll wait with the PR.

If you create a job that uses this Dispatchable trait it will immediately save the correct job_id & queue to the JobStatus model.

Ps. If you're willing to make a breakable change for a newer version I'd suggest adding a TrackableJob interfact, so we can replace/simplify stuff like this to if ($job instanceof TrackableJob)

imTigger commented 5 years ago

What is the queue driver used in this case?

The PendingDispatch seems another story. $ret = TrackableJob::dispatch([]); // returns PendingDispatch instead of anything we can access the job / id. Overriding PendingDispatch & Dispatchable seems the only solution that can get the stored id.

Another solution without extending core functions would be supply the "id" when calling "$this->prepareStatus(['key' => 'some-unique-key']);" In this way we need to add an additional column to job_statuses and generate the unique key ourselves. And use that unique to search JobStatus entity.

Anyway, PR is always welcome :)

crashkonijn commented 5 years ago

I'm using the database driver and are experiencing this issue, although I can imagine that this issue would be present with any driver. (Unless Laravel throws these events at different stages but I can't image that's the case.)

I am using Laravel 5.5 although I don't expect that to matter much.

Personally I'd prefer overriding the Dispatchable trait, but that's a personal preference I guess.

imTigger commented 5 years ago

I am testing with different dispatch methods (DispatchJobs trait, Job::dispatch(), now, chain, delay, Listener) The result is quite inconsistent, some events are missed. Still trying to get some more consistent result, will document my findings later.

imTigger commented 4 years ago

Please try to use "Improve job_id capture" feature in setup step 5 in latest version.