File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed
Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -107,10 +107,17 @@ In your Job dispatcher, call `$job->getJobStatusId()` to get `$jobStatusId`:
107107
108108``` php
109109<?php
110- $job = new TrackableJob([]);
111- $this->dispatch($job);
112110
113- $jobStatusId = $job->getJobStatusId();
111+ class YourController {
112+ use DispatchesJobs;
113+
114+ function go() {
115+ $job = new TrackableJob([]);
116+ $this->dispatch($job);
117+
118+ $jobStatusId = $job->getJobStatusId();
119+ }
120+ }
114121```
115122
116123` $jobStatusId ` can be used elsewhere to retrieve job status, progress and output.
@@ -119,6 +126,22 @@ $jobStatusId = $job->getJobStatusId();
119126<?php
120127$jobStatus = JobStatus::find($jobStatusId);
121128```
129+ ### Common Caveat
130+
131+ Laravel provide many ways to dispatch Jobs. Not all methods return your Job object, for example:
132+
133+ ``` php
134+ <?php
135+ YourJob::dispatch(); // Returns PendingDispatch instead of YourJob object, leaving no way to retrive `$job->getJobStatusId();`
136+ ```
137+
138+ Workarounds: Create your own key
139+
140+ 1 . Create migration adding extra key to job_statuses table.
141+
142+ 2 . In your job, generate your own unique key and pass into ` prepareStatus(); ` , ` $this->prepareStatus(['key' => $params['key']]); `
143+
144+ 3 . Find JobStatus another way: ` $jobStatus = JobStatus::whereKey($key)->firstOrFail(); `
122145
123146## Documentations
124147
You can’t perform that action at this time.
0 commit comments