@@ -131,18 +131,22 @@ public function updateStatus($status, $result = null)
131
131
return ;
132
132
}
133
133
134
- $ statusInstance = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->payload [ ' prefix ' ] );
134
+ $ statusInstance = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->getPrefix () );
135
135
$ statusInstance ->update ($ status , $ result );
136
136
}
137
137
138
138
/**
139
139
* Return the status of the current job.
140
140
*
141
- * @return int The status of the job as one of the Resque_Job_Status constants.
141
+ * @return int|null The status of the job as one of the Resque_Job_Status constants or null if job is not being tracked .
142
142
*/
143
143
public function getStatus ()
144
144
{
145
- $ status = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->payload ['prefix ' ]);
145
+ if (empty ($ this ->payload ['id ' ])) {
146
+ return null ;
147
+ }
148
+
149
+ $ status = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->getPrefix ());
146
150
return $ status ->get ();
147
151
}
148
152
@@ -171,9 +175,9 @@ public function getInstance()
171
175
return $ this ->instance ;
172
176
}
173
177
174
- $ this ->instance = $ this ->getJobFactory ()->create ($ this ->payload ['class ' ], $ this ->getArguments (), $ this ->queue );
175
- $ this ->instance ->job = $ this ;
176
- return $ this ->instance ;
178
+ $ this ->instance = $ this ->getJobFactory ()->create ($ this ->payload ['class ' ], $ this ->getArguments (), $ this ->queue );
179
+ $ this ->instance ->job = $ this ;
180
+ return $ this ->instance ;
177
181
}
178
182
179
183
/**
@@ -248,13 +252,15 @@ public function fail($exception)
248
252
*/
249
253
public function recreate ()
250
254
{
251
- $ status = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->payload ['prefix ' ]);
252
255
$ monitor = false ;
253
- if ($ status ->isTracking ()) {
254
- $ monitor = true ;
256
+ if (!empty ($ this ->payload ['id ' ])) {
257
+ $ status = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->getPrefix ());
258
+ if ($ status ->isTracking ()) {
259
+ $ monitor = true ;
260
+ }
255
261
}
256
262
257
- return self ::create ($ this ->queue , $ this ->payload ['class ' ], $ this ->getArguments (), $ monitor , $ this ->payload [ ' prefix ' ] );
263
+ return self ::create ($ this ->queue , $ this ->payload ['class ' ], $ this ->getArguments (), $ monitor , null , $ this ->getPrefix () );
258
264
}
259
265
260
266
/**
@@ -288,14 +294,26 @@ public function setJobFactory(Resque_Job_FactoryInterface $jobFactory)
288
294
return $ this ;
289
295
}
290
296
291
- /**
292
- * @return Resque_Job_FactoryInterface
293
- */
294
- public function getJobFactory ()
295
- {
296
- if ($ this ->jobFactory === null ) {
297
- $ this ->jobFactory = new Resque_Job_Factory ();
298
- }
299
- return $ this ->jobFactory ;
300
- }
297
+ /**
298
+ * @return Resque_Job_FactoryInterface
299
+ */
300
+ public function getJobFactory ()
301
+ {
302
+ if ($ this ->jobFactory === null ) {
303
+ $ this ->jobFactory = new Resque_Job_Factory ();
304
+ }
305
+ return $ this ->jobFactory ;
306
+ }
307
+
308
+ /**
309
+ * @return string
310
+ */
311
+ private function getPrefix ()
312
+ {
313
+ if (isset ($ this ->payload ['prefix ' ])) {
314
+ return $ this ->payload ['prefix ' ];
315
+ }
316
+
317
+ return '' ;
318
+ }
301
319
}
0 commit comments