@abstract     Build an Empty Task Response

@param  ArrayObject     $task       Task To Execute

@return ArrayObject   Task Result ArrayObject
552207
private static function getEmptyResponse($task)
    {
        //====================================================================//
        // Initial Tasks results ArrayObject
        $response = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);

        //====================================================================//
        // Set Default Result to False
        $response->result = false;
        $response->data = null;

        //====================================================================//
        // Insert Task Description Informations
        $response->name = $task->name;
        $response->desc = $task->desc;

        return $response;
    }
205012
public function getTask(liveTask $task, $throwException = false)
    {
        $data = $this->query($throwException);

        return $this->formatTask($task, $data);
    }
401664
public static function async(array $tasks): array
    {
        $server = App::$server->getServer();

        $result = [];
        foreach ($tasks as $task) {
            if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) {
                App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]'));
                continue;
            }

            if ($task['type'] !== static::TYPE_ASYNC) {
                App::error(sprintf('Task %s is not a asynchronous task.', $task['name']));
                continue;
            }

            $data = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']);
            $result[] = $server->task($data);
        }

        return $result;
    }
1071798
public function task($name, $task = null, $description = null)
    {
        return $this->add($task, $name, $description)->getTask();
    }
1250625
public function create($task)
    {
        $attributes = $task instanceof OrmTask ? $task->toArray() : $task;
        $attributes['id'] = static::nextId();
        $task = new OrmTask($attributes, true);
        $this->tasks[$attributes['id']] = $task;
        return $task;
    }
1349868
protected function add($task) {
		if (is_string($task)) {
			$task = new $task();
		}

		$class = get_class($task);
		if (!$task instanceof TaskInterface) {
			throw new InvalidArgumentException(
				"Cannot use '$class' as task, it is not implementing " . TaskInterface::class . '.'
			);
		}

		$this->tasks[$class] = $task;

		return $this;
	}
824858
public static function co(array $tasks): array
    {
        $taskCos = [];
        foreach ($tasks as $task) {
            if (! isset($task['type']) || ! isset($task['name']) || ! isset($task['method']) || ! isset($task['params'])) {
                App::error(sprintf('Task %s format error.', $task['name'] ?? '[UNKNOWN]'));
                continue;
            }

            $type = $task['type'];
            if ($type !== static::TYPE_CO) {
                App::error(sprintf('Task %s is not a coroutine task.', $task['name']));
                continue;
            }

            $taskCos[] = TaskHelper::pack($task['name'], $task['method'], $task['params'], $task['type']);
        }

        $result = [];
        if (! empty($taskCos)) {
            $result = App::$server->getServer()->taskCo($tasks);
        }

        return $result;
    }
786592
public function run($tasks)
    {
        $tasks = is_array($tasks) ? $tasks : [$tasks];
        $queue = $this->builder->buildTasks($tasks);
        $pipeline = $this->buildPipeline($queue);

        // Wrap job in closure pipeline
        foreach ($pipeline as $key => $job) {
            $pipeline[$key] = function () use ($job) {
                return $this->executeJob($job);
            };
        }

        // Run the tasks and store the results
        if ($this->getOption('parallel')) {
            $pipeline = $this->runAsynchronously($pipeline);
        } else {
            $pipeline = $this->runSynchronously($pipeline);
        }

        return $pipeline;
    }
908869
public function stdout(array $task, $full = true) {
		return $this->_text($task['stdout'], $full ? 0 : Configure::read('Task.truncateOutput'));
	}
851244
public function runCommand($task = '')
    {
        if (!$task && $tasks = $this->arguments->getValues()) {
            $task = $tasks[0];
        }

        if (!$task) {
            return $this->arguments->getOption('task|t');
        }

        $this->tasksManager->run($task);

        return 0;
    }
310254
protected function passToRemoteProcessor(Task $task)
    {
        return $this->getRemoteProcessor($task)->run($task, function ($type, $host, $line) {
            if (starts_with($line, 'Warning: Permanently added ')) {
                return;
            }

            $this->displayOutput($type, $host, $line);
        });
    }
1128988
public static function record_from_adhoc_task($task) {
        $record = new \stdClass();
        $record->classname = self::get_canonical_class_name($task);
        $record->id = $task->get_id();
        $record->component = $task->get_component();
        $record->blocking = $task->is_blocking();
        $record->nextruntime = $task->get_next_run_time();
        $record->faildelay = $task->get_fail_delay();
        $record->customdata = $task->get_custom_data_as_string();
        $record->userid = $task->get_userid();

        return $record;
    }
1275107
public function setTask(Task $task = null)
    {
        $this->task = $task;
        if (null !== $task) {
            $task->addTransition($this);
        }

        return $this;
    }
576377
public static function action($task)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace();
        Splash::log()->deb("Widgets => ".$task->name);
        //====================================================================//
        // Initial Response
        $response = self::getEmptyResponse($task);

        //====================================================================//
        // Execute Requested Task
        //====================================================================//
        switch ($task->name) {
            //====================================================================//
            //  READING OF SERVER WIDGETS LIST
            case SPL_F_WIDGET_LIST:
                $response->data = Splash::widgets();

                break;
            //====================================================================//
            //  READING A WIDGET DEFINITION
            case SPL_F_WIDGET_DEFINITION:
                $response->data = Splash::widget($task->params->type)->description();

                break;
            //====================================================================//
            //  READING A WIDGET CONTENTS
            case SPL_F_WIDGET_GET:
                $response->data = Splash::widget($task->params->type)->get($task->params->params);

                break;
            default:
                Splash::log()->err(
                    "Info Router - Requested task was not found => ".$task->name." (".$task->desc.")"
                );

                break;
        }

        //====================================================================//
        // Task results post treatment
        if (false != $response->data) {
            $response->result = true;
        }

        return $response;
    }
1057266
protected function renderProgressBar(array $task): void
    {
        // Use a progress bar to indicate how far a long the re-indexing has come
        $progressBar = null;

        do {
            $response = ['completed' => false];

            // Ignore ServerErrorResponseException, re-indexing can make these requests time out
            try {
                $response = $this->elasticsearchService->tasks()->get([
                    'task_id' => $task['task'],
                ]);

                $total = $response['task']['status']['total'];

                // Initialize the progress bar once Elasticsearch knows the total amount of items
                if ($progressBar === null && $total > 0) {
                    $progressBar = new ProgressBar(new ConsoleOutput(), $total);
                } elseif ($progressBar !== null) {
                    $progressBar->setProgress($response['task']['status']['created']);
                }
            } catch (ServerErrorResponseException $e) {
            }

            sleep(1);
        } while ((bool)$response['completed'] === false);

        // For very short migrations we may never get a progress bar, because the task finishes too quickly
        if ($progressBar !== null) {
            $progressBar->finish();
        }

        echo PHP_EOL;
    }
949391
public function getTask( $object, $operation, $exceptionOnFailure = true )
    {

        /* debugging
        printf(
            "\n-- new task %s%s %s\n",
            get_class( $object ),
            $object instanceof \Bond\Entity\Container ? get_unqualified_class( $object->classGet() ) : null,
            count( $object )
        );
         */

        if( !in_array( $operation, array( Task::PERSIST, Task::DELETE ), true ) ) {
            throw new BadOperationException( "Unknown task operation `{$operation}`; you probably want `RecordManager::PERSIST` or `RecordManager::DELETE`" );
        }

        // tasks only work on objects
        if( !is_object($object) ) {
            throw new BadTaskException("Tasks can only operate on objects");
        }

        // detect object
        foreach( $this->taskHandlers as $type ){

            if( call_user_func( [$type, 'isCompatible'], $object ) ) {
                $taskType = $type;
                break;
            }

        }

        // Can't handle this? What now?
        if( !isset( $taskType ) ) {

            // exceptionOnFailure
            if( $exceptionOnFailure ) {
                $class = get_class( $object );
                throw new BadTaskException( "Unable to find a Task compatible which works for object `{$class}` and operation `{$operation}`" );
            }

            // No exception
            return null;

        }

        // Normality variants?
        if(
            strpos( $taskType, 'Normality' ) !== false or
            strpos( $taskType, 'PgLargeObject' ) !== false
        ) {
            $taskType .= ( $operation === Task::DELETE ) ? '\\Delete' : '\\Persist';
        }

        // Instantiate
        $reflClass = new \ReflectionClass($taskType);
        $task = $reflClass->newInstance($this);
        // Set object property. No need to go via the setter because we have already determined this is compatible
        $reflProperty = $reflClass->getProperty('object');
        $reflProperty->setAccessible(true);
        $reflProperty->setValue( $task, $object );

        return $task;

    }
400071
protected static function get_queued_adhoc_task_record($task) {
        global $DB;

        $record = self::record_from_adhoc_task($task);
        $params = [$record->classname, $record->component, $record->customdata];
        $sql = 'classname = ? AND component = ? AND ' .
            $DB->sql_compare_text('customdata', \core_text::strlen($record->customdata) + 1) . ' = ?';

        if ($record->userid) {
            $params[] = $record->userid;
            $sql .= " AND userid = ? ";
        }
        return $DB->get_record_select('task_adhoc', $sql, $params);
    }