You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use your own JobStatus model you can change the model in `config/job-status.php`
63
+
64
+
```php
65
+
return [
66
+
'model' => App\JobStatus::class,
67
+
];
68
+
69
+
```
70
+
71
+
#### 5. Improve job_id capture (optional)
61
72
62
73
The first laravel event that can be captured to insert the job_id into the JobStatus model is the Queue::before event. This means that the JobStatus won't have a job_id until it is being processed for the first time.
63
74
64
75
If you would like the job_id to be stored immediately you can add the `LaravelJobStatusServiceProvider` to your `config/app.php`, which tells laravel to use our `Dispatcher`.
To use your own JobStatus model you can change the model in `config/job-status.php`
85
+
Laravel support only one transcation per database connection.
75
86
76
-
```php
77
-
return [
78
-
'model' => App\JobStatus::class,
79
-
];
80
-
```
87
+
All changes made by JobStatus are also within transaction and therefore invisible to other connnections (e.g. progress page)
88
+
89
+
If your job will update progress within transaction, copy your connection in `config/database.php` under another name like `'mysql-job-status'` with same config.
90
+
91
+
Then set your connection to `'database_connection' => 'mysql-job-status'` in `config/job-status.php`
81
92
82
93
### Usage
83
94
@@ -148,7 +159,9 @@ class YourController {
148
159
<?php
149
160
$jobStatus = JobStatus::find($jobStatusId);
150
161
```
151
-
### Common Caveat
162
+
### Troubleshooting
163
+
164
+
#### Call to undefined method ...->getJobStatusId()
152
165
153
166
Laravel provide many ways to dispatch Jobs. Not all methods return your Job object, for example:
154
167
@@ -157,14 +170,23 @@ Laravel provide many ways to dispatch Jobs. Not all methods return your Job obje
157
170
YourJob::dispatch(); // Returns PendingDispatch instead of YourJob object, leaving no way to retrive `$job->getJobStatusId();`
158
171
```
159
172
160
-
Workarounds: Create your own key
173
+
If you really need to dispatch job in this way, workarounds needed: Create your own key
161
174
162
175
1. Create migration adding extra key to job_statuses table.
163
176
164
177
2. In your job, generate your own unique key and pass into `prepareStatus();`, `$this->prepareStatus(['key' => $params['key']]);`
165
178
166
179
3. Find JobStatus another way: `$jobStatus = JobStatus::whereKey($key)->firstOrFail();`
167
180
181
+
#### Status not updating until transaction commited
182
+
183
+
On version >= 1.1, dedicated database connection support is added.
184
+
185
+
Therefore JobStatus updates can be saved instantly even within your application transaction.
0 commit comments