/** * @see QueueInterface::push() */ public function push(TaskInterface $task) { $eta = $task->getEta() ?: new \DateTime(); $data = array('eta' => new \MongoDate($eta->getTimestamp()), 'task' => $this->serializer->serialize($task)); $result = $this->collection->insert($data, array('safe' => true)); if (!$result['ok']) { throw new \RuntimeException($result['errmsg']); } }
/** * @see QueueInterface::push() */ public function push(TaskInterface $task) { $eta = $task->getEta() ?: new \DateTime(); $score = $eta->getTimestamp(); $unique = $this->redis->incr('sequence'); $member = $unique . '@' . $this->serializer->serialize($task); $result = $this->redis->zAdd('tasks', $score, $member); if (!$result) { throw new \RuntimeException(sprintf('Unable to push the task %s.', $task)); } }
/** * @see QueueInterface::push() */ public function push(TaskInterface $task) { $sql = 'INSERT INTO ' . $this->tableName . ' (eta, task) VALUES (:eta, :task)'; $stmt = $this->prepareStatement($sql); $eta = $task->getEta() ?: new \DateTime(); $stmt->bindValue(':eta', $eta->format(static::DATETIME_FORMAT)); $stmt->bindValue(':task', $this->serializer->serialize($task)); if (!$stmt->execute()) { $err = $stmt->errorInfo(); throw new \RuntimeException($err[2]); } }
public function shutdown() { if (!$this->currentTask) { return; } if ($err = error_get_last()) { $this->logger->err(sprintf('Worker died while working on task %s. Last error "%s" occurred in %s on line %d.', $this->currentTask, $err['message'], $err['file'], $err['line'])); } if (!$this->isCurrentTaskProcessed) { if ($this->currentTask->reschedule()) { $this->currentQueue->push($this->currentTask); } else { $this->logger->err(sprintf('Task %s failed.', $this->currentTask)); } } }
/** * @see QueueInterface::push() */ public function push(TaskInterface $task) { $eta = $task->getEta() ?: new \DateTime(); $this->innerQueue->insert($task, array(-$eta->getTimestamp(), $this->queueOrder--)); }