@@ -131,18 +131,22 @@ public function updateStatus($status, $result = null)
131131 return ;
132132 }
133133
134- $ statusInstance = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->payload [ ' prefix ' ] );
134+ $ statusInstance = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->getPrefix () );
135135 $ statusInstance ->update ($ status , $ result );
136136 }
137137
138138 /**
139139 * Return the status of the current job.
140140 *
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 .
142142 */
143143 public function getStatus ()
144144 {
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 ());
146150 return $ status ->get ();
147151 }
148152
@@ -171,9 +175,9 @@ public function getInstance()
171175 return $ this ->instance ;
172176 }
173177
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 ;
177181 }
178182
179183 /**
@@ -248,13 +252,15 @@ public function fail($exception)
248252 */
249253 public function recreate ()
250254 {
251- $ status = new Resque_Job_Status ($ this ->payload ['id ' ], $ this ->payload ['prefix ' ]);
252255 $ 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+ }
255261 }
256262
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 () );
258264 }
259265
260266 /**
@@ -288,14 +294,26 @@ public function setJobFactory(Resque_Job_FactoryInterface $jobFactory)
288294 return $ this ;
289295 }
290296
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+ }
301319}
0 commit comments