/** * @covers \Qutee\Task::setName * @covers \Qutee\Task::setMethodName */ public function testSettingMethodNameViaName() { $this->assertEquals('run', $this->object->getMethodName()); $this->object->setName('TaskName::methodName'); $this->assertEquals('TaskName', $this->object->getName()); $this->assertEquals('methodName', $this->object->getMethodName()); }
/** * * @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; }
/** * Get class of the task, run it's default method or method specified in * task data [method] * * @param Task $task */ protected function _runTask(Task $task) { $taskClassName = $task->getClassName(); if (!class_exists($taskClassName)) { throw new \InvalidArgumentException(sprintf('Task class "%s" not found', $taskClassName)); } $taskObject = new $taskClassName(); if ($taskObject instanceof TaskInterface) { $taskObject->setData($task->getData()); $taskObject->run(); return $taskObject; } else { $methodName = $task->getMethodName(); $taskObject->{$methodName}($task->getData()); } }