Skip to content

Commit 3d0dea4

Browse files
authored
Update README.md
1 parent a2ea522 commit 3d0dea4

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)