@coroutine

@param \Icicle\Concurrent\Worker\Task $task

@return \Generator

@resolve mixed
428274
private function send(Task $task): \Generator
    {
        yield from $this->context->send($task);
        return yield from $this->context->receive();
    }
1001582
public function executeTask($task, $input = null)
    {
        return $this->execute(
            $this->getController($task, $input),
            $this->app->request,
            new \Windwalker\Http\Response\Response()
        );
    }
605219
public function registerTask($task, $method)
	{
		if (in_array(strtolower($method), $this->_taskMap))
		{
			$this->_taskMap[strtolower($task)] = $method;
		}

		return $this;
	}
661008
public function attach(Task $task, $task_name = null)
    {
        if (is_null($task_name)) {
            $task_name = count($this->tasks);
        }
        $this->tasks[$task_name] = $task;
        curl_multi_add_handle($this->curl, $task->createCurl());
        $deferred = new Deferred();
        $this->deferred[$task_name] = $deferred;

        return $deferred->promise();
    }
485870
public function updateTask(AbstractTask $task) {        
        try{
            Database::prepare(
                'UPDATE `##maj_admintasks`'.
                ' SET majat_status = :status,'.
                ' majat_last_run = :last_run,'.
                ' majat_last_result = :last_result,'.
                ' majat_frequency = :frequency,'.
                ' majat_nb_occur = :nb_occurrences,'.
                ' majat_running = :is_running'.
                ' WHERE majat_name = :name'
                )->execute(array(
                    'name' => $task->getName(),
                    'status' => $task->isEnabled() ? 'enabled' : 'disabled',
                    'last_run' => $task->getLastUpdated()->format('Y-m-d H:i:s'),
                    'last_result' =>  $task->isLastRunSuccess() ? 1 : 0,
                    'frequency' => $task->getFrequency(),
                    'nb_occurrences' => $task->getRemainingOccurrences(),
                    'is_running' => $task->isRunning() ? 1 : 0
                ));
            return true;
        }
        catch (\Exception $ex) {
            Log::addErrorLog(sprintf('Error while updating the Admin Task %s. Exception: %s', $task->getName(), $ex->getMessage()));
            return false;
        }        
    }
44585
public function canWork($task)
    {
        foreach ($this as $worker) {
            if ($worker->canWork($task)) {
                return true;
            }
        }
        return false;
    }
1157559
public function updateTask(Task $task): Task
    {
        @trigger_error(sprintf('The %s() method is deprecated since version 0.8. Use update() instead.', __METHOD__), E_USER_DEPRECATED);

        return $this->update($task);
    }
895881
private function createWorkload(TaskInterface $task)
    {
        // TODO get from additional form of handler
        $workload = [];

        $optionsResolver = new OptionsResolver();
        $optionsResolver->setDefaults(
            [
                'class' => $task->getEntityClass(),
                'id' => $task->getEntityId(),
                'locale' => $task->getLocale(),
            ]
        );

        $handler = $this->taskHandlerFactory->create($task->getHandlerClass());
        if (!$handler instanceof AutomationTaskHandlerInterface) {
            throw new TaskHandlerNotSupportedException($handler, $task);
        }

        $optionsResolver = $handler->configureOptionsResolver($optionsResolver);

        return $optionsResolver->resolve($workload);
    }
487335
public function update(Task $task)
    {
        $this->om->persist($task);
        $this->om->flush();

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

        return $task;
    }
842439
public function stop(Task $task)
    {
        $task->setStatus(Task::STATUS_STOPPED);

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

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

        return $task;
    }
1020262
private function execute(): \Generator
    {
        $job = yield $this->channel->receive();

        while ($job instanceof Internal\Job) {
            try {
                $result = yield call([$job->getTask(), "run"], $this->environment);
                $result = new Internal\TaskSuccess($job->getId(), $result);
            } catch (\Throwable $exception) {
                $result = new Internal\TaskFailure($job->getId(), $exception);
            }

            $job = null; // Free memory from last job.

            try {
                yield $this->channel->send($result);
            } catch (SerializationException $exception) {
                // Could not serialize task result.
                yield $this->channel->send(new Internal\TaskFailure($result->getId(), $exception));
            }

            $result = null; // Free memory from last result.

            $job = yield $this->channel->receive();
        }

        return $job;
    }
683138
protected function scheduleTask(TaskInterface $task)
    {
        if (null !== ($execution = $this->taskExecutionRepository->findPending($task))) {
            return;
        }

        if ($task->getInterval() === null && 0 < count($this->taskExecutionRepository->findByTask($task))) {
            return;
        }

        $scheduleTime = $task->getInterval() ? $task->getInterval()->getNextRunDate() : $task->getFirstExecution();
        $execution = $this->taskExecutionRepository->create($task, $scheduleTime);
        $execution->setStatus(TaskStatus::PLANNED);

        $this->eventDispatcher->dispatch(
            Events::TASK_EXECUTION_CREATE,
            new TaskExecutionEvent($task, $execution)
        );

        $this->taskExecutionRepository->save($execution);
    }
22169
public static function scheduled_task_complete(scheduled_task $task) {
        global $DB;

        // Finalise the log output.
        logmanager::finalise_log();

        $classname = self::get_canonical_class_name($task);
        $record = $DB->get_record('task_scheduled', array('classname' => $classname));
        if ($record) {
            $record->lastruntime = time();
            $record->faildelay = 0;
            $record->nextruntime = $task->get_next_scheduled_time();

            $DB->update_record('task_scheduled', $record);
        }

        // Reschedule and then release the locks.
        if ($task->is_blocking()) {
            $task->get_cron_lock()->release();
        }
        $task->get_lock()->release();
    }
121811
public function start(int $count): Promise
    {
        if ($this->running || $this->deferred) {
            throw new \Error("The cluster is already running or has already run");
        }

        if ($count <= 0) {
            throw new \Error("The number of workers must be greater than zero");
        }

        $this->deferred = new Deferred;
        $this->running = true;

        return call(function () use ($count) {
            try {
                $promises = [];
                for ($i = 0; $i < $count; ++$i) {
                    $promises[] = $this->startWorker();
                }
                yield Promise\all($promises);
            } catch (\Throwable $exception) {
                $this->stop();
                throw $exception;
            }
        });
    }
1324861
private function spawn(Task $task)
    {
        $config      = $this->getTensideConfig();
        $home        = $this->getTensideHome();
        $commandline = PhpProcessSpawner::create($config, $home)->spawn(
            [
                $this->get('tenside.cli_script')->cliExecutable(),
                'tenside:runtask',
                $task->getId(),
                '-v',
                '--no-interaction'
            ]
        );

        $this->get('logger')->debug('SPAWN CLI: ' . $commandline->getCommandLine());
        $commandline->setTimeout(0);
        $commandline->start();
        if (!$commandline->isRunning()) {
            // We might end up here when the process has been forked.
            // If exit code is neither 0 nor null, we have a problem here.
            if ($exitCode = $commandline->getExitCode()) {
                /** @var LoggerInterface $logger */
                $logger = $this->get('logger');
                $logger->error('Failed to execute "' . $commandline->getCommandLine() . '"');
                $logger->error('Exit code: ' . $commandline->getExitCode());
                $logger->error('Output: ' . $commandline->getOutput());
                $logger->error('Error output: ' . $commandline->getErrorOutput());
                throw new \RuntimeException(
                    sprintf(
                        'Spawning process task %s resulted in exit code %s',
                        $task->getId(),
                        $exitCode
                    )
                );
            }
        }

        $commandline->wait();
    }
408908
public function task($task, Closure $callback = null)
    {
        foreach ($this->connections as $connection) {
            $connection->task($task, $callback);
        }
    }
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);
        });
    }