Creates a new task for the given user.

@param string $name
@param string $event
@param bool   $running
@param bool   $success
@param string $message

@return array Response
359969
public function createNew(
        string $name,
        string $event,
        bool $running,
        bool $success,
        string $message
    ) : array {

        return $this->sendPost(
            sprintf('/profiles/%s/processes/%s/tasks', $this->userName, $this->processId),
            [],
            [
                'name'    => $name,
                'event'   => $event,
                'running' => $running,
                'success' => $success,
                'message' => $message
            ]
        );
    }
1083135
public static function runHook($name, array $params = [ ])
    {
        static::ensureHookPoint($name);

        foreach (static::$hooks[ $name ] as $handler) {
            if ($handler instanceof \Closure) {

                call_user_func_array($handler, $params);
            } elseif (class_exists($handler)) {
                $instance = app()->make($handler);

                call_user_func_array([ $instance, 'handle' ], $params);
            }
        }
    }
855355
public function create($name, $jobId, $settings, $period)
    {
        $task = new Task();
        $task->setName($name)
            ->setJobId($jobId)
            ->setSettings($settings)
            ->setPeriod($period);

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

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

        return $task;
    }
1075593
public static function startTimer($name, $message = null) {
		if (!Reveal::is('DebugKit.running')) {
			return;
		}

		App::uses('DebugTimer', 'DebugKit.Lib');
		DebugTimer::start($name, $message);
	}
1348037
public function trigger($name, Event $event = null)
    {
        if (! isset($event)) {
            $event = new Event($this->subject);
        }
        if (isset($this->parent)) {
            if (! $this->parent->trigger($this->subjectClass . '.' . $name, $event)) {
                return false;
            }
        }
        if (isset($this->events[$name])) {
            $event->name = $name;
            foreach ($this->events[$name] as $function) {
                $continue = call_user_func($function, $event);
                if ($event->stopped or $continue === false) {
                    return false;
                }
            }
        } elseif (strpos($name, '.') === false) {
            throw new InvalidEventException(
                'Event subject "' . $this->subjectClass
                . '" does not have event "' . $name . '"'
            );
        }
        return true;
    }
1322565
public static void invokeTask (String name, Task task, TaskObserver observer)
    {
        // create a task runner and stick it in our task table
        TaskRunner runner = new TaskRunner(name, task, observer);
        _tasks.put(name, runner);
        // then start the runner up
        runner.start();
    }
1275188
public function build($name, $target, Array $files, Array $args = array())
    {
        if (empty($this->tasks[$name])) {
            throw new \RuntimeException("Don't konw how to build {$name}");
        }

        $watching = array_merge([$target], $files);
        if (!$this->needBuilding($target, $watching)) {
            return $target;
        }

        $this->stack[] = $target;
        $this->tasks[$name]->exec($target, $files, $args, $this);
        array_pop($this->stack);

        $this->watchFiles($target, $watching);

        $this->isDry = true;
        return $target;
    }
1337349
private function beforeTask(
        string $logid,
        int $spanid,
        string $name,
        string $method,
        string $type,
        string $taskClass
    ) {
        $event = new BeforeTaskEvent(TaskEvent::BEFORE_TASK, $logid, $spanid, $name, $method, $type, $taskClass);
        App::trigger($event);
    }
669279
public function createHook(string $name, string $config, array $events = ['push'], bool $active = true): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/hooks',
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo()), Request::METHOD_POST, [
                'name'   => $name,
                'config' => $config,
                'events' => $events,
                'active' => $active
            ]);
    }
83680
private function writeMigration($name, $eventObjectTable, $actionTiming, $event)
    {
        $file = pathinfo($this->creator->write(
            $name,
            $eventObjectTable,
            $actionTiming,
            $event,
            $this->getMigrationPath()
        ), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> {$file}");
    }
1071798
public function task($name, $task = null, $description = null)
    {
        return $this->add($task, $name, $description)->getTask();
    }
301938
protected function getNotification($name, $status = FALSE)
    {
        //If $status is FALSE show primary notification
        if($status === FALSE)
        {
            //Generate a message
            if($this->commandExists('notify-send'))
            {
                shell_exec('notify-send "'.$this->getAppName().' Tasks"  "Running '.$name.'..." -i dialog-information');
            }
            //Show required message
            echo "\n";
            echo "\t", $this->colorize('Running '.$name.'...', 'info');
            echo "\n";
        }
        else
        {
            //If $status is TRUE show success notification
            //Generate a message
            if($this->commandExists('notify-send'))
            {
                shell_exec('notify-send "'.$this->getAppName().' Tasks" "'.$name.' Task Completed!" -i dialog-ok');
            }
            //Show required message
            echo "\n";
            echo "\t", $this->colorize($name.' Task Completed!', 'success');
            echo "\n";
        }
    }
510795
function run(task_name, options, driver_name) {
  var task = this.tasks[task_name];
  if (!task) {
    log.error(new Error('Task "' + task_name + '" is not registered.'));
    return;
  }
  var driver = this.drivers[driver_name];
  if (!driver) {
    log.error(new Error('Driver "' + driver_name + '" is not registered.'));
    return;
  }

  return task.run(driver, options);
}
213110
public function createTask($name) {
    $this->init();
    $class = Code::expandNamespace(\Webforge\Common\String::expand($name, 'Task'), 'Psc\System\Deploy');
    
    $gClass = GClass::factory($class);
    $params = array();
    if ($gClass->hasMethod('__construct')) {
      $constructor = $gClass->getMethod('__construct');
      foreach ($constructor->getParameters() as $parameter) {
        $params[] = $this->resolveTaskDependency($parameter, $gClass);
      }
    }
    
    return $gClass->newInstance($params);
  }
418237
public static function task($name, $data = null, \Closure $ready = null)
    {
        $task = self::getTask($name);
        if (!$task) {
            if (is_callable($data)) {
                $ready = $data;
                $data = null;
            }
            $task = Task::create($name, $data, $ready);
            self::$tasks[$name] = $task;
        }

        return $task;
    }
164390
public function log(string $name, string $message, array $data = []): void
    {
        $filename = $this->dir . '/' . $name . '-' . date('Y-m-d') . '.log';
        try {
            $microtime = microtime(true);
            $microtimeParts = explode('.', $microtime);
            $logData = date('H:i:s', $microtime) . ':' . (isset($microtimeParts[1]) ? $microtimeParts[1] : '0') . "\n" . trim($message) . (empty($data) ? '' : "\n" . trim(print_r($data, true))) . "\n\n";
            $fileHandler = fopen($filename, 'ab');
            fwrite($fileHandler, $logData);
            fclose($fileHandler);
        } catch (\Exception $e) {
            throw new \Exception('Cannot write log file (' . $filename . ')');
        }
    }
511820
public function run($run, array $arguments = [])
    {

        $lambda = new Lambda($run);

        return $this->repository->transaction(function($repo) use ($lambda, $arguments) {

            $taskTemplate = $this->newTask($lambda);

            $this->callBeforeListeners('run', [$taskTemplate, $lambda, $arguments]);

            $task = $this->repository->create($taskTemplate);

            $job = $this->createJob($task, $lambda, $arguments);

            // We can just ignore to write state because typically the job
            // is typically started in another process
            $task->setJob($job);

            $this->callAfterListeners('run', [$taskTemplate, $job]);

            return $task;

        });
    }