/** * {@inheritDoc} */ public function delete(JobInterface $job) { foreach ($this->jobs as $key => $value) { if ($value->getId() === $job->getId()) { unset($this->jobs[$key]); } } }
/** * {@inheritDoc} */ public function processJob(JobInterface $job, QueueInterface $queue) { if (!$queue instanceof DoctrineQueueInterface) { return; } try { $job->execute($queue); $queue->delete($job); } catch (JobException\ReleasableException $exception) { $queue->release($job, $exception->getOptions()); } catch (JobException\BuryableException $exception) { $queue->bury($job, $exception->getOptions()); } catch (Exception $exception) { $queue->bury($job, array('message' => $exception->getMessage(), 'trace' => $exception->getTraceAsString())); } }
/** * {@inheritDoc} */ public function processJob(JobInterface $job, QueueInterface $queue) { if (!$queue instanceof BeanstalkdQueueInterface) { return WorkerEvent::JOB_STATUS_UNKNOWN; } /** * In Beanstalkd, 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 explicitly be removed */ try { $job->execute(); $queue->delete($job); return WorkerEvent::JOB_STATUS_SUCCESS; } catch (Exception $exception) { // Do nothing, the job will be reinserted automatically for another try return WorkerEvent::JOB_STATUS_FAILURE_RECOVERABLE; } }
/** * {@inheritDoc} */ public function processJob(JobInterface $job, QueueInterface $queue) { if (!$queue instanceof SqsQueueInterface) { return WorkerEvent::JOB_STATUS_UNKNOWN; } // 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 explicitly be removed try { $job->execute(); $queue->delete($job); return WorkerEvent::JOB_STATUS_SUCCESS; } catch (SqsException $sqsException) { // We want to retrigger SQS exception as they may include useful debugging information like lack of // permissions throw $sqsException; } catch (Exception $exception) { // Do nothing, the job will be reinserted automatically for another try return WorkerEvent::JOB_STATUS_FAILURE_RECOVERABLE; } }
/** * Serialize job to allow persistence * * The serialization format is a JSON object with keys "content", * "metadata" and "__name__". When a job is fetched from the SL, a job name * will be set and be available as metadata. An invokable job has no service * name and therefore the FQCN will be used. * * @param JobInterface $job The job to persist * @return string */ public function serializeJob(JobInterface $job) { $job->setMetadata('__name__', $job->getMetadata('__name__', get_class($job))); $data = ['content' => serialize($job->getContent()), 'metadata' => $job->getMetadata()]; return json_encode($data); }
/** * {@inheritDoc} */ public function delete(JobInterface $job) { $parameters = array('QueueUrl' => $this->queueOptions->getQueueUrl(), 'ReceiptHandle' => $job->getMetadata('receiptHandle')); $this->sqsClient->deleteMessage($parameters); }
/** * Reschedules a specific running job * * Note : see DoctrineQueue::parseOptionsToDateTime for schedule and delay options * * @param JobInterface $job * @param array $options * @throws Exception\LogicException */ public function release(JobInterface $job, array $options = array()) { $scheduled = $this->parseOptionsToDateTime($options); $update = 'UPDATE ' . $this->options->getTableName() . ' ' . 'SET status = ?, finished = ? , scheduled = ?, data = ? ' . 'WHERE id = ? AND status = ?'; $rows = $this->connection->executeUpdate($update, array(static::STATUS_PENDING, new DateTime(null, new DateTimeZone(date_default_timezone_get())), $scheduled, $job->jsonSerialize(), $job->getId(), static::STATUS_RUNNING), array(Type::SMALLINT, Type::DATETIME, Type::DATETIME, Type::STRING, Type::INTEGER, Type::SMALLINT)); if ($rows != 1) { throw new Exception\LogicException("Race-condition detected while updating item in queue."); } }
public function processJob(JobInterface $job, QueueInterface $queue) { return $job->execute(); }