Skip to content

Commit bd514b8

Browse files
committed
Merge 'Invoiced/php7_errors' into old-pulls
Closes chrisboulton/php-resque#316
2 parents f86211b + f993b9f commit bd514b8

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

lib/Resque/Failure.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public static function create($payload, Exception $exception, Resque_Worker $wor
2828
new $backend($payload, $exception, $worker, $queue);
2929
}
3030

31+
/**
32+
* Create a new failed job on the backend from PHP 7 errors.
33+
*
34+
* @param object $payload The contents of the job that has just failed.
35+
* @param \Error $exception The PHP 7 error generated when the job failed to run.
36+
* @param \Resque_Worker $worker Instance of Resque_Worker that was running this job when it failed.
37+
* @param string $queue The name of the queue that this job was fetched from.
38+
*/
39+
public static function createFromError($payload, Error $exception, Resque_Worker $worker, $queue)
40+
{
41+
$backend = self::getBackend();
42+
new $backend($payload, $exception, $worker, $queue);
43+
}
44+
3145
/**
3246
* Return an instance of the backend for saving job failures.
3347
*

lib/Resque/Job.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,21 @@ public function fail($exception)
223223
));
224224

225225
$this->updateStatus(Resque_Job_Status::STATUS_FAILED);
226-
Resque_Failure::create(
227-
$this->payload,
228-
$exception,
229-
$this->worker,
230-
$this->queue
231-
);
226+
if ($exception instanceof Error) {
227+
Resque_Failure::createFromError(
228+
$this->payload,
229+
$exception,
230+
$this->worker,
231+
$this->queue
232+
);
233+
} else {
234+
Resque_Failure::create(
235+
$this->payload,
236+
$exception,
237+
$this->worker,
238+
$this->queue
239+
);
240+
}
232241
Resque_Stat::incr('failed');
233242
Resque_Stat::incr('failed:' . $this->worker);
234243
}

lib/Resque/Worker.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ public function perform(Resque_Job $job)
268268
$result = $job->perform();
269269
}
270270
catch(Exception $e) {
271-
$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
271+
$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e));
272+
$job->fail($e);
273+
return;
274+
}
275+
catch(Error $e) {
276+
$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {exception}', array('job' => $job, 'exception' => $e));
272277
$job->fail($e);
273278
return;
274279
}

0 commit comments

Comments
 (0)