Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Worker catch any exception
Browse files Browse the repository at this point in the history
In SQS jobs are automatically reinserted if something bad happen, for
further processing. Not catching exception makes the worker stop
  • Loading branch information
bakura10 committed Jan 19, 2014
1 parent 90e7d39 commit ba6720a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/SlmQueueSqs/Worker/SqsWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Exception;
use SlmQueue\Job\JobInterface;
use SlmQueue\Queue\QueueAwareInterface;
use SlmQueue\Queue\QueueInterface;
use SlmQueue\Worker\AbstractWorker;
use SlmQueueSqs\Queue\SqsQueue;
use SlmQueueSqs\Queue\SqsQueueInterface;

/**
Expand All @@ -26,8 +24,12 @@ public function processJob(JobInterface $job, QueueInterface $queue)

// In SQS, if an error occurs (exception for instance), the job is automatically reinserted
// into the queue after a configured delay (the "visibility_timeout" option). If the job executed
// correctly, it must explicitely be removed
$job->execute();
$queue->delete($job);
// correctly, it must explicitly be removed
try {
$job->execute();
$queue->delete($job);
} catch (Exception $exception) {
// Do nothing, the job will be reinserted automatically for another try
}
}
}

0 comments on commit ba6720a

Please sign in to comment.