/** * * @param \Qutee\Task $task * * @return \Qutee\Persistor\Pdo */ public function addTask(Task $task) { // Check if the task is unique and already exists if ($task->isUnique() && $this->_hasTaskByUniqueId($task->getUniqueId())) { return $this; } $statement = $this->_getPdo()->prepare(sprintf(' INSERT INTO %s SET name = :name, method_name = :method_name, data = :data, priority = :priority, unique_id = :unique_id, created_at = NOW() ', $this->_options['table_name'])); $statement->execute(array(':name' => $task->getName(), ':method_name' => $task->getMethodName(), ':data' => serialize($task), ':priority' => $task->getPriority(), ':unique_id' => $task->isUnique() ? $task->getUniqueId() : null)); return $this; }
/** * * @param \Qutee\Task $task * * @return string */ protected function _createKey(\Qutee\Task $task) { if ($task->isUnique()) { $key = sprintf('task:%s:%s', $task->getName(), $task->getUniqueId()); } else { $key = sprintf('task:%s:%s', $task->getName(), uniqid('', true)); } return $key; }
/** * @covers \Qutee\Task::__construct * @depends testCanSetAndGetName * @depends testCanSetAndGetData */ public function testCanSettAttributesUpponInstantiation() { $data = array('test' => 'data'); $task = new Task('TaskName', $data, Task::PRIORITY_HIGH, 'unique_identifier', 'methodName'); $this->assertEquals('TaskName', $task->getName()); $this->assertEquals($data, $task->getData()); $this->assertEquals('methodName', $task->getMethodName()); $this->assertEquals(3, $task->getPriority()); $this->assertEquals(md5('TaskNameunique_identifier'), $task->getUniqueId()); }