/** * Modify task in queue * @param Task $task * @throws Exceptions\QueueException * @return Task */ public function modify_task($task) { if (!$task instanceof Task) { return false; } $need_commit = false; if ($task->have_subtasks()) { $need_commit = true; $database_data = $this->driver->prepare_modify($task->get_uniqid()); if (is_null($database_data)) { throw new QueueException('Task for modify not found'); } foreach ($database_data as $id => $task_database_data) { /** * @var Task $modify_task */ $current_task = $id == 0 ? $task : $task->sub_tasks()->get($task_database_data[TaskConst::UNIQID]); $current_task_data = $current_task->to_array(); //check not modified parameters foreach ($this->not_modifiable_parameters as $not_modifiable_parameter) { if ($current_task_data[$not_modifiable_parameter] != $task_database_data[$not_modifiable_parameter]) { throw new QueueException("Parameter {$not_modifiable_parameter} was changed"); } } $diff = array_diff($current_task_data, $task_database_data); $current_task->set_array($diff); } $task->set_subtasks_quantity_not_performed(0)->set_subtasks_error(0); $have_in_process = false; foreach ($task->sub_tasks()->get_all() as $sub_task) { if ($sub_task->get_status() == Task::STATUS_IN_PROCESS) { $have_in_process = true; } switch ($sub_task->get_status()) { case Task::STATUS_CALLBACK_ERROR: $task->completed_error(Task::STATUS_CALLBACK_ERROR); case Task::STATUS_ERROR: $task->inc_subtasks_error(); if ($sub_task->settings()->get_nested_settings('error_break')) { $task->completed_error(); } break; case Task::STATUS_NEW: $task->inc_subtasks_quantity_not_performed(); break; } } if (!$have_in_process && $task->get_subtasks_quantity_not_performed() == 0 && !in_array($task->get_status(), array(Task::STATUS_ERROR, Task::STATUS_CALLBACK_ERROR))) { if ($task->get_subtasks_error() > 0) { $task->completed_error(Task::STATUS_DONE_WITH_ERROR); } else { $task->completed_ok(); } } $this->driver->modify_task($task->sub_tasks()->get_perform_task()); } $this->driver->modify_task($task, $need_commit); return $task; }
/** * Set current perform sub task * This task already have status "IN_PROCESS" in base * @param \PhpQueue\Task $perform_task * @return $this */ public function add_perform_task(Task $perform_task) { $this->perform_task = $perform_task->get_uniqid(); $this->add($perform_task); return $this; }
/** * Modify task in queue * @param Task $task * @param bool $need_commit Transaction commit required * @return bool */ public function modify_task(Task $task, $need_commit = false) { if (is_null($this->file_handler)) { $this->lock_file(); } $xml_dom = $this->get_xml_dom(); $task_xml = $xml_dom->xpath("//" . self::TASK_XML . "[@" . TaskConst::UNIQID . "='" . $task->get_uniqid() . "']"); $task_xml = $task_xml[0]; foreach ($task->get($this->index_row) as $item_name => $item_value) { $task_xml[$item_name] = $item_value; } $this->save_task($task); $this->save_xml_dom($xml_dom); $this->release_file(); return $this; }