Skip to content

Commit

Permalink
Create Exception from Error and extend from Resque_Worker to be compa…
Browse files Browse the repository at this point in the history
…tible with resque failed jobs
  • Loading branch information
Marcos Gómez committed Mar 16, 2017
1 parent b478e44 commit 34efe2b
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions WorkerSingle.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Chris Boulton <chris@bigcommerce.com>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class WorkerSingle
class WorkerSingle extends \Resque_Worker
{
/**
* @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface
Expand Down Expand Up @@ -215,13 +215,19 @@ public function perform(\Resque_Job $job)
try {
\Resque_Event::trigger('afterFork', $job);
$job->perform();
}
catch (\Error $e) {
$this->logger->log(LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
$job->fail($e);
return;
}
catch(\Exception $e) {
} catch (\Error $e) {
$exception = new \ErrorException(
$e->getMessage(),
$e->getCode(),
1,
$e->getFile(),
$e->getLine()
);

$this->logger->log(LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $exception));
$job->fail($exception);
return;
} catch(\Exception $e) {
$this->logger->log(LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
$job->fail($e);
return;
Expand Down

0 comments on commit 34efe2b

Please sign in to comment.