Skip to content

Commit

Permalink
Support fatal exceptions which bury beanstalkd jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
ronanchilvers committed Sep 30, 2019
1 parent 026dfa9 commit f59fd96
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/Queue/Exception/FatalException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Ronanchilvers\Foundation\Queue\Exception;

use Exception;

/**
* Exception thrown for failed jobs which will not be re-run
*
* @author Ronan Chilvers <ronan@d3r.com>
*/
class FatalException extends Exception
{}
11 changes: 6 additions & 5 deletions src/Queue/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Carbon\Carbon;
use Exception;
use Pheanstalk\Pheanstalk;
use Pheanstalk\Contract\PheanstalkInterface;
use Pheanstalk\Pheanstalk;
use Psr\Log\LoggerInterface;
use Ronanchilvers\Foundation\Psr\Traits\LoggerAwareTrait;
use Ronanchilvers\Foundation\Queue\Exception\FailedJobException;
use Ronanchilvers\Foundation\Queue\Exception\FatalException;
use Ronanchilvers\Foundation\Queue\Exception\InvalidPayloadException;
use Ronanchilvers\Foundation\Queue\Handler\ClassJobHandler;
use Ronanchilvers\Foundation\Queue\Job\DispatchableInterface;
Expand Down Expand Up @@ -116,10 +117,10 @@ public function watch($queue, $timeout = 5, $maxIterations = null, OutputInterfa

$output->writeln('Deleting job : ' . $queueJob->getId());
$this->connection->delete($queueJob);
// } catch (FatalException $ex) {
// $this->logger->error('Fatal : ' . $ex->getMessage(), ['exception' => $ex]);
// $output->writeln('Burying job after fatal exception : ' . $queueJob->getId());
// $this->connection->bury($queueJob);
} catch (FatalException $ex) {
$this->logger->error('Fatal : ' . $ex->getMessage(), ['exception' => $ex]);
$output->writeln('Burying job after fatal exception : ' . $queueJob->getId());
$this->connection->bury($queueJob);
} catch (Exception $ex) {
$this->logger->error($ex->getMessage(), ['exception' => $ex]);
$output->writeln('Releasing failed job : ' . $queueJob->getId());
Expand Down

0 comments on commit f59fd96

Please sign in to comment.