Scalr\System\Zmq\Cron\Launcher::launch PHP Method

launch() public method

Launches tasks are due to run
public launch ( ) : integer
return integer Returns the number of the launched tasks
    public function launch()
    {
        $curTime = new DateTime('now');
        if ($curTime->format('i') % 5 == 1) {
            $services = [];
            foreach (ScalrService::find() as $scalrService) {
                $services[$scalrService->name] = $scalrService;
            }
            foreach ($this->getAllTasks() as $task) {
                $config = $task->config();
                if (!array_key_exists($task->getName(), $services)) {
                    $task->getScalrService()->update(['state' => $config->enabled ? ScalrService::STATE_SCHEDULED : ScalrService::STATE_DISABLED]);
                } elseif (!$config->enabled && $services['state'] != ScalrService::STATE_DISABLED) {
                    $task->getScalrService()->update(['state' => ScalrService::STATE_DISABLED]);
                }
            }
        }
        $count = 0;
        //Gets all scheduled task at this second
        foreach ($this->getScheduled() as $task) {
            /* @var $task \Scalr\System\Zmq\Cron\TaskInterface */
            $this->log("DEBUG", "Launching %s", $task->getName());
            $task->launch();
            $count++;
        }
        return $count;
    }