コード例 #1
0
ファイル: TaskList.php プロジェクト: tenside/core
 /**
  * Add the task to the list.
  *
  * @param string         $type     The type name.
  *
  * @param JsonArray|null $metaData The (optional) meta data.
  *
  * @return string
  *
  * @throws \InvalidArgumentException When no task instance can be created from the meta data.
  */
 public function queue($type, JsonArray $metaData = null)
 {
     $taskId = $this->generateId();
     if (null === $metaData) {
         $metaData = new JsonArray();
     }
     $metaData->set(Task::SETTING_ID, $taskId)->set(Task::SETTING_TYPE, $type)->set('status', Task::STATE_PENDING)->set(Task::SETTING_CREATED_AT, date('c'));
     $taskFile = new JsonFile($this->taskIdToFileName($taskId), null);
     $taskFile->setData($metaData->getData());
     $taskFile->save();
     if (!$this->createTaskFromMetaData($taskFile)) {
         unlink($taskFile->getFilename());
         throw new \InvalidArgumentException('Could not create task of type "' . $metaData->get('type') . '"');
     }
     $this->getConfig()->set($taskId, $metaData->getData());
     return $taskId;
 }