{@inheritdoc}

@throws \InvalidArgumentException For unsupported task types.
543903
public function createInstance($taskType, JsonArray $metaData)
    {
        if (!($factory = $this->getFactoryForType($taskType)) instanceof TaskFactoryInterface) {
            throw new \InvalidArgumentException('Do not know how to create task.');
        }

        return $factory->createInstance($taskType, $metaData);
    }
1035159
private function interactForTaskConfigurations(OutputStyle $io)
    {
        $io->writeln(' Add tasks:');

        $addTask = true;
        while ($addTask) {
            $taskQuestion = new Question('Search for a task');
            $taskQuestion->setAutocompleterValues($this->getAvailableTasks());
            $taskQuestion->setValidator(function ($answer) {
                if (class_exists($answer) === false && class_exists('Accompli\\Task\\'.$answer) === true) {
                    $answer = 'Accompli\\Task\\'.$answer;
                }
                if (class_exists($answer) === false || in_array(TaskInterface::class, class_implements($answer)) === false) {
                    throw new InvalidArgumentException(sprintf('The task "%s" does not exist.', $answer));
                }

                return $answer;
            });

            $task = $io->askQuestion($taskQuestion);

            $taskConfiguration = array_merge(
                array(
                    'class' => $task,
                ),
                $this->getTaskConfigurationParameters($task)
            );

            $this->configuration['events']['subscribers'][] = $taskConfiguration;

            $addTask = $io->confirm('Add another task?');
        }
    }
225124
private function run(TaskExecutionInterface $execution)
    {
        $start = microtime(true);
        $execution->setStartTime(new \DateTime());
        $execution->setStatus(TaskStatus::RUNNING);
        $this->taskExecutionRepository->save($execution);

        try {
            $execution = $this->hasPassed($execution, $this->handle($execution));
        } catch (ExitException $exception) {
            throw $exception;
        } catch (\Exception $exception) {
            $execution = $this->hasFailed($execution, $exception);
        } finally {
            $this->finalize($execution, $start);
        }
    }
605219
public function registerTask($task, $method)
	{
		if (in_array(strtolower($method), $this->_taskMap))
		{
			$this->_taskMap[strtolower($task)] = $method;
		}

		return $this;
	}
653219
public function setStep($step)
    {
        if (is_int($step)) {
            $this->step = $step;
        } else {
            $msg = "'Step' must be an integer, '" . gettype($step) . "' given.";
            throw new InvalidArgumentException($msg);
        }
    }
1277598
public function setTarget(string $target): void
    {
        $path = realpath($target);
        if (false === $path) {
            if (@mkdir($target, 0755, true)) {
                $path = realpath($target);
            } else {
                throw new InvalidArgumentException(
                    'Target directory (' . $target . ') does not exist and could not be created'
                );
            }
        }

        if (!is_dir($path) || !is_writable($path)) {
            throw new InvalidArgumentException('Given target (' . $target . ') is not a writable directory');
        }

        $this->target = $path;
    }
882775
private function abortPending(TaskInterface $task)
    {
        if (!$execution = $this->taskExecutionRepository->findPending($task)) {
            return false;
        }

        $execution->setStatus(TaskStatus::ABORTED);
        $this->taskExecutionRepository->save($execution);

        return true;
    }
11766
public function execute() {
        if (!$this->built) {
            throw new base_task_exception('base_task_not_built', $this->name);
        }
        if ($this->executed) {
            throw new base_task_exception('base_task_already_executed', $this->name);
        }

        // Starts progress based on the weight of this task and number of steps.
        $progress = $this->get_progress();
        $progress->start_progress($this->get_name(), count($this->steps), $this->get_weight());
        $done = 0;

        // Execute all steps.
        foreach ($this->steps as $step) {
            $result = $step->execute();
            // If step returns array, it will be forwarded to plan
            // (TODO: shouldn't be array but proper result object)
            if (is_array($result) and !empty($result)) {
                $this->add_result($result);
            }
            $done++;
            $progress->progress($done);
        }
        // Mark as executed if any step has been executed
        if (!empty($this->steps)) {
            $this->executed = true;
        }

        // Finish progress for this task.
        $progress->end_progress();
    }
380168
public function setObject( $object, $throwExceptionOnFailure = true )
    {

        // tasks only work on objects
        if( !is_object($object) ) {
            throw new BadTaskException("A task must be object");
            return false;
        }

        $error = null;

        if( $isCompatible = static::isCompatible( $object, $error ) ) {
            $this->object = $object;
            return true;
        }

        if( $throwExceptionOnFailure ) {
            throw new BadTaskException("{$error}");
        }
        return false;

    }
333015
public function createInstance($taskType, JsonArray $metaData)
    {
        $methodName = $this->methodNameFromType($taskType);
        if ($this->isTypeSupported($taskType)) {
            return call_user_func([$this, $methodName], $metaData);
        }

        throw new \InvalidArgumentException('Do not know how to create task ' . $taskType);
    }
196196
protected function execute(callable $task)
	{
		if ($this->beingDestroyed) {
			throw new \RuntimeException(self::ERROR_BEING_DESTROY);
		}
		
		$this->taskQueue->enqueue($task);
		
		if ($this->idleQueue->isEmpty() && ($this->size + $this->beingCreatedSize) < $this->maxSize) {
			$this->newResource();
		}
		
		$this->taskDequeue();
	}
1003322
public function addTasks($tasks) : self
	{
		$tasksId = $this->createIdFromObject($tasks);
		if (in_array($tasksId, $this->registeredTaskObjects)) {
			throw new InvalidArgumentException("Tasks with ID '" . $tasksId . "' have been already added.");
		}

		$reflection = new ClassType($tasks);
		$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
		foreach ($methods as $method) {
			if (!Strings::startsWith($method->getName(), '__') && $method->hasAnnotation(Parameters::TASK)) {
				$task = new Task($tasks, $method, $this->timestampStorage);
				if (array_key_exists($task->getName(), $this->tasks)) {
					throw new DuplicateTaskNameException('Cannot use more tasks with the same name "' . $task->getName() . '".');
				}
				$this->tasks[$task->getName()] = $task;
			}
		}
		$this->registeredTaskObjects[] = $tasksId;

		return $this;
	}
147727
public function update(Task $task): Task
    {
        $id = $task->getId();

        $task->setId(null);

        $response = $this->client->put($this->prepareUrlForKey('update-task', ['id' => $id]), [], $task->jsonSerialize());
        $responseData = $response->getDecodedBody();

        return new Task($responseData);
    }
337199
public static function build($basicData)
    {
        $className = $basicData[TaskInterface::JSON_TASK_CLASS_NAME_KEY];

        if (class_exists($className) && is_subclass_of($className, TaskInterface::class)) {
            $metaData = $basicData[TaskInterface::JSON_METADATA_KEY];

            /** @var TaskInterface $task */
            $task = new $className($metaData[TaskInterface::JSON_METADATA_ID_KEY], $metaData[TaskInterface::JSON_METADATA_OWNER_KEY]);
            $task->setMetadata($metaData);
            $task->setParameter($basicData[TaskInterface::JSON_PARAMETERS_KEY]);

            if (isset($metaData[TaskInterface::JSON_METADATA_CREATED_AT_KEY])) {
                $task->setCreatedAt(new \DateTime($metaData[TaskInterface::JSON_METADATA_CREATED_AT_KEY]));
            }

            return $task;
        }

        throw new InvalidTaskException;
    }
894610
public function findTaskByType($type)
    {
        foreach ($this->tasks as $task) {
            if ($task->getName() === $type) {
                return $task;
            }
        }

        throw new TaskNotFoundException($type);
    }
371635
public function push(TaskInterface $task)
    {
        return (bool) $this->getPersistence()->insert($this->getTableName(), [
            'message' => $this->serializeTask($task),
            'created_at' => $this->getPersistence()->getPlatForm()->getNowExpression()
        ]);
    }
445653
public function startTask($task, array $options = [])
    {
        ob_start() && $this->taskStack[] = $task;

        $this->taskOptions[$task] = $this->mergeDefaultOptions($options);
    }