Define a set of commands as a task.

@param string       $task
@param string|array $commands

@return void
559329
public function define($task, $commands)
    {
        foreach ($this->connections as $connection) {
            $connection->define($task, $commands);
        }
    }
723578
private static function areCommands(array $commands): bool
    {
        $areCommands = true;

        foreach ($commands as $command) {
            $areCommands = $areCommands && ($command instanceof BaseCommand);
        }

        return $areCommands;
    }
1326240
public function addConsoleCommands()
    {
        $this->getConsole()->addUserArgumentsAndOptions();

        foreach ($this->tasks as $name => $task) {
            if ($task->isPrivate()) {
                continue;
            }

            $this->getConsole()->add(new TaskCommand($name, $task->getDescription(), $this));
        }
    }
153382
protected function registerCommands(array $commands)
    {
        foreach (array_keys($commands) as $command) {
            call_user_func_array([$this, "register{$command}Command"], []);
        }

        $this->commands(array_values($commands));
    }
1150360
public function withCommands(array $commands)
    {
        $validCommands = [];
        foreach ($commands as $command) {
            if (is_string($command) && $command != Command::class) {
                $validCommands[] = new $command();
            }
        }

        $this->addCommands($validCommands);

        return $this;
    }
509609
private synchronized void runTask(Task task) {
        if (taskThread == null) {
            taskThread = new TaskThread();
        }
        taskThread.runTask(task);
    }
44915
public void setTasks(java.util.Collection<TaskListEntry> tasks) {
        if (tasks == null) {
            this.tasks = null;
            return;
        }

        this.tasks = new java.util.ArrayList<TaskListEntry>(tasks);
    }
1078669
public function registerCommands(array $commands)
    {
        foreach ($commands as $command) {
            $instance = $this->app->make($command);

            $instance->boot($this->app);

            $this->addCommand($instance->signature, [$instance, 'register'], [
                'shortdesc' => $instance->description,
            ]);
        }
    }
834720
public function buildCommand($task, $slug = null)
    {
        // Build the task instance
        try {
            $instance = $this->modulable->buildTask($task);
        } catch (TaskCompositionException $exception) {
            $instance = null;
        }

        // Get the command name
        $name = $instance ? $instance->getName() : null;
        $command = $this->modulable->findQualifiedName($name, 'commands');

        // If no command found, use BaseTaskCommand or task name
        if ($command === BaseTaskCommand::class) {
            $name = is_string($task) ? $task : $name;
            $command = $this->modulable->findQualifiedName($name, 'commands');
        }

        /** @var AbstractCommand $command */
        $command = new $command($instance, $slug);
        $command->setContainer($this->container);

        return $command;
    }
1020534
public function addTaskListeners($task, $event, $listeners, $priority = 0)
    {
        // Recursive call
        if (is_array($task)) {
            foreach ($task as $t) {
                $this->addTaskListeners($t, $event, $listeners, $priority);
            }

            return;
        }

        // Cancel if no listeners
        if (!$listeners) {
            return;
        }

        // Prevent events on anonymous tasks
        $task = $this->builder->buildTask($task);
        if ($task->getSlug() === 'closure') {
            return;
        }

        // Get event name and register listeners
        $event = $this->getEventHandle($task, $event);
        $event = $this->listenTo($event, $listeners, $priority);

        return $event;
    }
101059
public function add(Task $task) : void
    {
        $this->index++;
        Util::put($this -> storage().$this->index.'.queue', serialize($task));
        $this -> updateIterator();
        Util::put($this -> storage().'_index', $this -> index);
    }
849327
public void execute(Task task) {
    LOG.info(String.format("Executing task %s", task.getTaskId()));
    this.taskExecutor.execute(new TrackingTask(task));
  }
308447
public function task($task, Closure $callback = null)
    {
        if (isset($this->tasks[$task])) {
            $this->run($this->tasks[$task], $callback);
        }
    }
703867
public function run(Task $task)
    {
        // get configured filters for this task
        $filters = $task
            ->getConfiguration()
            ->getParameter('filters');

        // get sources files
        $sources = $this->fetchSources($task);
        $destinations = $this->fetchDestinations($task);

        foreach ($filters as $filterName) {
            // get current configured filter
            $filter = $this->getFilter($filterName);

            // filter the files supported by this filter
            $filteredSources = $this->filterSources($sources, $filter);

            // apply the filter
            $updatedSources = $filter->run($filteredSources, $destinations);

            // update new sources if exists
            if ($updatedSources === null) {
                $updatedSources = [];
            }
            $sources = $this->updateSources($sources, $filteredSources, $updatedSources);
        }

        if (!$this->isDebug) {
            foreach ($filters as $filterName) {
                // get current configured filter
                $filter = $this->getFilter($filterName);

                // clean the files generated by the filter
                $filter->clean();
            }
        }
    }
1243816
public function dispatch($command): void
    {
        $this->commandStack[] = $command;

        if ($this->executing) {
            return;
        }

        $this->transactionManager->begin();
        try {
            while ($command = array_shift($this->commandStack)) {
                $this->invokeHandler($command);
            }
            $this->eventPublisher->publishEvents();
            $this->transactionManager->commit();
        } catch (Exception $e) {
            $this->transactionManager->rollback();
            throw $e;
        }
    }
532582
public function resolveCommands($commands)
    {
        $commands = is_array($commands) ? $commands : func_get_args();

        foreach ($commands as $command)  {
            $this->resolve($command);
        }
    }
698040
public static function registerTasks(array $tasks)
    {
        // Register Tasks
        foreach ($tasks as $key => $task) {
            $roles = array_key_exists('roles', $task) ? $task['roles'] : null;
            self::registerTask($key, $task['desc'], $task['callback'], $roles);
        }
    }