Skip to content

Commit

Permalink
Merge pull request #49 from punktDeForks/feature/log-errors
Browse files Browse the repository at this point in the history
TASK: log errors on job failure
  • Loading branch information
daniellienert committed Jan 14, 2021
2 parents f78a130 + 221c7c5 commit e1e8efb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Classes/Job/JobManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
use Neos\Cache\Frontend\VariableFrontend;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Core\Booting\Scripts;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Property\PropertyMapper;
use Flowpack\JobQueue\Common\Exception as JobQueueException;
use Flowpack\JobQueue\Common\Queue\Message;
use Flowpack\JobQueue\Common\Queue\QueueManager;
use Psr\Log\LoggerInterface;

/**
* Job manager
Expand Down Expand Up @@ -62,6 +65,18 @@ class JobManager
*/
protected $flowSettings;

/**
* @Flow\Inject
* @var ThrowableStorageInterface
*/
protected $throwableStorage;

/**
* @Flow\Inject
* @var LoggerInterface
*/
protected $logger;

/**
* Put a job in the queue
*
Expand Down Expand Up @@ -120,10 +135,14 @@ public function waitAndExecute(string $queueName, $timeout = null): ?Message
$releaseOptions = isset($queueSettings['releaseOptions']) ? $queueSettings['releaseOptions'] : [];
$queue->release($message->getIdentifier(), $releaseOptions);
$this->emitMessageReleased($queue, $message, $releaseOptions, $exception);
$logMessage = $this->throwableStorage->logThrowable($exception);
$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);
} else {
$queue->abort($message->getIdentifier());
$this->emitMessageFailed($queue, $message, $exception);
$logMessage = $this->throwableStorage->logThrowable($exception);
$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);
}
} finally {
Expand Down

0 comments on commit e1e8efb

Please sign in to comment.