Skip to content

Commit

Permalink
BUGFIX: When working on job, catch Throwable
Browse files Browse the repository at this point in the history
When working on a job, any `\Exception` is caught and the job in the
queue is released (retry or failure). In case of a `\Throwable` _not_
being an `\Exception`, this does not happen and the job is never "un-
reserved".

This change catches `\Throwable` instead to fix this.
  • Loading branch information
kdambekalns authored and bwaidelich committed Jul 28, 2022
1 parent 7dd6a6a commit 87b5738
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions Classes/Job/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,23 @@ public function waitAndExecute(string $queueName, $timeout = null): ?Message
} else {
$this->executeJobForMessage($queue, $message);
}
} catch (\Exception $exception) {
} catch (\Throwable $throwable) {
$maximumNumberOfReleases = isset($queueSettings['maximumNumberOfReleases']) ?
(int)$queueSettings['maximumNumberOfReleases'] :
self::DEFAULT_MAXIMUM_NUMBER_RELEASES;
if ($message->getNumberOfReleases() < $maximumNumberOfReleases) {
$releaseOptions = isset($queueSettings['releaseOptions']) ? $queueSettings['releaseOptions'] : [];
$queue->release($message->getIdentifier(), $releaseOptions);
$this->emitMessageReleased($queue, $message, $releaseOptions, $exception);
$logMessage = $this->throwableStorage->logThrowable($exception);
$this->emitMessageReleased($queue, $message, $releaseOptions, $throwable);
$logMessage = $this->throwableStorage->logThrowable($throwable);
$this->logger->error($logMessage, LogEnvironment::fromMethodName(__METHOD__));
throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - RELEASE', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056583, $exception);
throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - RELEASE', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056583, $throwable);
} else {
$queue->abort($message->getIdentifier());
$this->emitMessageFailed($queue, $message, $exception);
$logMessage = $this->throwableStorage->logThrowable($exception);
$this->emitMessageFailed($queue, $message, $throwable);
$logMessage = $this->throwableStorage->logThrowable($throwable);
$this->logger->error($logMessage, LogEnvironment::fromMethodName(__METHOD__));
throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - ABORTING', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056584, $exception);
throw new JobQueueException(sprintf('Job execution for job (message: "%s", queue: "%s") failed (%d/%d trials) - ABORTING', $message->getIdentifier(), $queue->getName(), $message->getNumberOfReleases() + 1, $maximumNumberOfReleases + 1), 1334056584, $throwable);
}
} finally {
if ($messageCacheIdentifier !== null) {
Expand Down

0 comments on commit 87b5738

Please sign in to comment.