@abstract   Task execution router. Receive task detail and execute requiered task operations.

@param ArrayObject $task Full Task Request Array

@return ArrayObject Task results, or False if KO
779004
public static function action($task)
    {
        //====================================================================//
        // Stack Trace
        Splash::log()->trace();

        //====================================================================//
        // Initial Response
        $response = self::getEmptyResponse($task);

        //====================================================================//
        // Safety Check - Minimal Parameters
        //====================================================================//
        $inputs = self::validateInputs($task);
        if (!$inputs) {
            return $response;
        }

        //====================================================================//
        // Execute Action
        switch ($task->name) {
            //====================================================================//
            //  READING A FILE INFORMATIONS
            case SPL_F_ISFILE:
                $response->data = Splash::file()->isFile($inputs['path'], $inputs['md5']);

                break;
            //====================================================================//
            //  READING A FILE CONTENTS
            case SPL_F_GETFILE:
                $response->data = Splash::file()->readFile($inputs['path'], $inputs['md5']);

                break;
            default:
                Splash::log()->err('File - Requested task not found => '.$task->name);

                break;
        }

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

        return $response;
    }
1211537
public function executeJob(Job $job)
    {
        // Set proper server
        $connectionKey = $job->connectionKey;
        $this->connections->setCurrentConnection($connectionKey);

        foreach ($job->queue as $key => $task) {
            if ($task->usesStages()) {
                $stage = $task->usesStages() ? $connectionKey->stage : null;
                $this->connections->setStage($stage);
            }

            // Check if the current server can run the task
            if (!$this->connections->getCurrentConnection()->isCompatibleWith($task)) {
                continue;
            }

            // Here we fire the task, save its
            // output and return its status
            $state = $task->fire();
            $this->toOutput($state);

            // If the task didn't finish, display what the error was
            if ($task->wasHalted() || $state === false) {
                $this->explainer->error('The tasks queue was canceled by task "'.$task->getName().'"');

                return false;
            }
        }

        return true;
    }
509673
public function dispatch(\Closure $task, $middlewares = null)
    {
        is_array($middlewares) || $middlewares = $this->getMiddlewares();

        $beforeReturnValue = $this->before($middlewares);

        if ($beforeReturnValue === false || $beforeReturnValue !== true) {
            return $beforeReturnValue;
        }

        $this->setPayload($task());

        $afterReturnValue = $this->after(array_reverse($middlewares));

        if ($afterReturnValue === false || $afterReturnValue !== true) {
            return $afterReturnValue;
        }

        return $this->getPayload();
    }
281871
public function getTasksListeners($task, $event, $flatten = false)
    {
        // Get events
        $task = $this->builder->buildTaskFromClass($task);
        $handle = $this->getEventHandle($task, $event);
        $events = $this->events->getListeners($handle);

        // Flatten the queue if requested
        foreach ($events as $key => $listener) {
            if ($flatten && $listener instanceof ClosureTask && $stringTask = $listener->getStringTask()) {
                $events[$key] = $stringTask;
            } elseif ($flatten && $listener instanceof AbstractTask) {
                $events[$key] = $listener->getSlug();
            }
        }

        return $events;
    }
408908
public function task($task, Closure $callback = null)
    {
        foreach ($this->connections as $connection) {
            $connection->task($task, $callback);
        }
    }
1000888
public static function createProcess($task): Runnable
    {
        if (! self::$isInitialised) {
            self::init();
        }

        if (! Pool::isSupported()) {
            return SynchronousProcess::create($task, self::getId());
        }

        $process = new Process(implode(' ', [
            'exec php',
            self::$childProcessScript,
            self::$autoloader,
            self::encodeTask($task),
        ]));

        return ParallelProcess::create($process, self::getId());
    }
428274
private function send(Task $task): \Generator
    {
        yield from $this->context->send($task);
        return yield from $this->context->receive();
    }
1064234
public function start(Task $task)
    {
        $task->setStatus(Task::STATUS_STARTED);

        $this->om->persist($task);
        $this->om->flush();

        $this->notify(NotifierInterface::MESSAGE_UPDATE);

        return $task;
    }
1078297
protected function runTaskOverSSH(Task $task)
    {
        // If the pretending option has been set, we'll simply dump the script out to the command
        // line so the developer can inspect it which is useful for just inspecting the script
        // before it is actually run against these servers. Allows checking for errors, etc.
        if ($this->pretending()) {
            echo $task->script.PHP_EOL;

            return 1;
        } else {
            return $this->passToRemoteProcessor($task);
        }
    }
77500
public static function main($task)
    {
        $methodName = "main";
        $dispatchable = null;
        try {
            if ($task instanceof Dispatchable) {
                $dispatchable = $task;
            } elseif ($task instanceof UnknownElement) {
                $ue = $task;
                $realThing = $ue->getRealThing();
                if ($realThing != null && $realThing instanceof Dispatchable && $realThing instanceof Task) {
                    $dispatchable = $realThing;
                }
            }
            if ($dispatchable != null) {
                $mName = null;

                $name = trim($dispatchable->getActionParameterName());
                if (empty($name)) {
                    throw new BuildException(
                        "Action Parameter Name must not be empty for Dispatchable Task."
                    );
                }
                $mName = "get" . ucfirst($name);
                try {
                    $c = new ReflectionClass($dispatchable);
                    $actionM = $c->getMethod($mName);
                    $o = $actionM->invoke($dispatchable);
                    $methodName = trim((string) $o);
                    if (empty($methodName)) {
                        throw new ReflectionException();
                    }
                } catch (ReflectionException $re) {
                    throw new BuildException(
                        "Dispatchable Task attribute '" . $name . "' not set or value is empty."
                    );
                }
                $executeM = $c->getMethod($methodName);
                $executeM->invoke($dispatchable);

                if ($task instanceof UnknownElement) {
                    $task->setRealThing(null);
                }
            } else {
                try {
                    $refl = new ReflectionClass($task);
                    $executeM = $refl->getMethod($methodName);
                } catch (ReflectionException $re) {
                    throw new BuildException("No public " . $methodName . "() in " . get_class($task));
                }
                $executeM->invoke($task);
                if ($task instanceof UnknownElement) {
                    $task->setRealThing(null);
                }
            }
        } catch (ReflectionException $e) {
            throw new BuildException($e);
        }
    }
237422
public static function runTask($task)
    {
        $run = $task->createTaskRun();
        $run->setTaskId($task->getTaskId());
        $run->setTs(date('Y-m-d H:i:s'));
        $run->setStatus(TaskRunInterface::RUN_STATUS_STARTED);
        $run->saveTaskRun();
        $run_final_status = TaskRunInterface::RUN_STATUS_COMPLETED;

        ob_start();
        $time_begin = microtime(true);

        $result = self::parseAndRunCommand($task->getCommand());
        if (!$result) {
            $run_final_status = TaskRunInterface::RUN_STATUS_ERROR;
        }

        $output = ob_get_clean();
        $run->setOutput($output);

        $time_end = microtime(true);
        $time = round(($time_end - $time_begin), 2);
        $run->setExecutionTime($time);

        $run->setStatus($run_final_status);
        $run->saveTaskRun();
        return $output;
    }
454039
public function executeTask($tasks)
    {
        return $this->explainer->displayBelow(function () use ($tasks) {
            return $this->builder->buildTask($tasks)->fire();
        });
    }
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;
    }
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;
    }
758869
protected function runSilentCommand(TaskInterface $task)
    {
        return $task->printOutput(false)
            // This is weird as you would expect this to give you more
            // information, but it suppresses the exit code from display.
            ->setVerbosityThreshold(VerbosityThresholdInterface::VERBOSITY_DEBUG)
            ->run();
    }
984219
public function buildTaskFromClass($task)
    {
        if (is_object($task) && $task instanceof AbstractTask) {
            return $task;
        }

        // Cancel if class doesn't exist
        if (!$class = $this->taskClassExists($task)) {
            throw new TaskCompositionException($task);
        }

        // Build class
        $class = new $class();
        if ($class instanceof ContainerAwareInterface) {
            $class->setContainer($this->container);
        }

        return $class;
    }
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;
    }