Load the cron jobs to run and execute them.
@return int Number of runned tasks
345993
public function output($args = null) {
        $i = 0;
        foreach ($this->jobs as $job)
            if($job['function']($job['msg']) === TRUE)
                $i++;

        $this->jobs = [];
        return $i;
    }
1074655
public function perform()
    {
        Stats::decr('queued', 1);
        Stats::decr('queued', 1, Queue::redisKey($this->queue, 'stats'));

        if (Event::fire(Event::JOB_PERFORM, $this) === false) {
            $this->cancel();
            return false;
        }

        $this->run();

        $retval = true;

        try {
            $instance = $this->getInstance();

            ob_start();

            if (method_exists($instance, 'setUp')) {
                $instance->setUp();
            }

            call_user_func_array(array($instance, $this->method), array($this->data, $this));

            if (method_exists($instance, 'tearDown')) {
                $instance->tearDown();
            }

            $this->complete();
        } catch (Exception\Cancel $e) {
            // setUp said don't perform this job
            $this->cancel();
            $retval = false;
        } catch (\Exception $e) {
            $this->fail($e);
            $retval = false;
        }

        $output = ob_get_contents();

        while (ob_get_length()) {
            ob_end_clean();
        }

        $this->redis->hset(self::redisKey($this), 'output', $output);

        Event::fire(Event::JOB_DONE, $this);

        return $retval;
    }
252599
protected function loadCronModule(){
        //Consigo las variables globales para linea de comandos
        global $argv, $argc;
        //Analizo si se pasa por lo menos un parametros (nombre cron), el primer parametros es el nombre del archivo y el segundo en nombre de la clase
        //pregunta por >= 2
        if($argc >= 2){
            $this->cronCore= new Cron\CronCore($this, $argv);            
        }else{
            Error::general_error('Cron Controller', 'There isent define any cron controller name');
        }    
    }
39579
public function getFinishedJobs()
    {
        while (count($this->jobs) !== 0) {
            foreach ($this->jobs as $index => $job) {
                if ($job->isFinished()) {
                    unset($this->jobs[$index]);
                    yield $index => $job;
                }
            }
        }
    }
1296915
public function run()
    {

        // Check if we have the schedules, else,
        // insert them
        foreach ($this->schedule as $job) {

            if (! DB::table('schedules')->where('command', $job['command'])->first())
                DB::table('schedules')->insert($job);
        }
    }
1347841
public function runworker() {
		try {
			$pid = $this->_initPid();
		} catch (PersistenceFailedException $exception) {
			$this->err($exception->getMessage());
			$limit = (int)Configure::read('Queue.maxworkers');
			if ($limit) {
				$this->out('Cannot start worker: Too many workers already/still running on this server (' . $limit . '/' . $limit . ')');
			}
			return static::CODE_ERROR;
		}

		// Enable Garbage Collector (PHP >= 5.3)
		if (function_exists('gc_enable')) {
			gc_enable();
		}
		if (function_exists('pcntl_signal')) {
			pcntl_signal(SIGTERM, [&$this, '_exit']);
			pcntl_signal(SIGINT, [&$this, '_abort']);
			pcntl_signal(SIGTSTP, [&$this, '_abort']);
			pcntl_signal(SIGQUIT, [&$this, '_abort']);
		}
		$this->_exit = false;

		$startTime = time();
		$groups = $this->_stringToArray($this->param('group'));
		$types = $this->_stringToArray($this->param('type'));

		while (!$this->_exit) {
			$this->_setPhpTimeout();

			try {
				$this->_updatePid($pid);
			} catch (RecordNotFoundException $exception) {
				// Manually killed
				$this->_exit = true;
				continue;
			} catch (ProcessEndingException $exception) {
				// Soft killed, e.g. during deploy update
				$this->_exit = true;
				continue;
			}

			if ($this->param('verbose')) {
				$this->_log('runworker', $pid, false);
			}
			$this->out('[' . date('Y-m-d H:i:s') . '] Looking for Job ...');

			$queuedJob = $this->QueuedJobs->requestJob($this->_getTaskConf(), $groups, $types);

			if ($queuedJob) {
				$this->runJob($queuedJob, $pid);
			} elseif (Configure::read('Queue.exitwhennothingtodo')) {
				$this->out('nothing to do, exiting.');
				$this->_exit = true;
			} else {
				$this->out('nothing to do, sleeping.');
				sleep(Config::sleeptime());
			}

			// check if we are over the maximum runtime and end processing if so.
			if (Configure::readOrFail('Queue.workermaxruntime') && (time() - $startTime) >= Configure::readOrFail('Queue.workermaxruntime')) {
				$this->_exit = true;
				$this->out('Reached runtime of ' . (time() - $startTime) . ' Seconds (Max ' . Configure::readOrFail('Queue.workermaxruntime') . '), terminating.');
			}
			if ($this->_exit || mt_rand(0, 100) > (100 - (int)Config::gcprob())) {
				$this->out('Performing Old job cleanup.');
				$this->QueuedJobs->cleanOldJobs();
				$this->QueueProcesses->cleanEndedProcesses();
			}
			$this->hr();
		}

		$this->_deletePid($pid);

		if ($this->param('verbose')) {
			$this->_log('endworker', $pid);
		}
	}
1359133
public function run() {
		
		//Check if the function exec is enabled
		if(false === function_exists('exec')) {
		    return trigger_error('Function "exec" is not enabled', E_USER_ERROR);
		}

		//Check if schedules folder is readable
		if(false === is_readable(Path :: get('schedule'))) {
			return trigger_error(printf('Could not read schedule folder "%s"', Path :: get('schedule')));
		}

		//Check if schedule cache folder is writable
		if(false === is_writable(Path :: get('log-schedule'))) {
			return trigger_error(printf('Could not write schedule cache folder "%s"', Path :: get('log-schedules')));
		}

		//Get all schedules from schedules folder
		$schedules = glob(Path :: get('schedule') . Application :: get(['prefix', 'schedule']) . '*.php');

		//For all the schedules classes; run the script
		foreach($schedules as $schedule) {

			//Remove path
			$schedule = preg_replace('#^'. Path :: get('schedule')  .'#', '', $schedule);
			
			//Remove prefix
			$schedule = preg_replace('#^'. Application :: get(['prefix', 'schedule'])  .'#', '', $schedule);

			//Remove extension
			$schedule = preg_replace('#.php$#', '', $schedule);

			//Execute schedule
			$this -> exec(sprintf('%s %s %s', $this -> path, getcwd() . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_FILENAME'], $schedule), true);
		}
	}
1081164
public function load()
    {
        $this->out('<info>' . __d('cake_resque', 'Loading predefined workers') . '</info>');

        $debug = isset($this->params['debug']) ? $this->params['debug'] : false;
        $queues = Configure::read('CakeResque.Queues');

        if ($queues === null) {
            $this->out('   ' . __d('cake_resque', 'You have no configured workers to load.'));
        } else {
            foreach ($queues as $workerArgs) {
                $workerArgs['debug'] = $debug;
                $this->start($workerArgs);
            }
        }

        if (Configure::read('CakeResque.Scheduler.enabled') === true) {
            $this->startscheduler(['debug' => $debug]);
        }

        $this->out('');
    }
63497
public function listCron()
    {
        $this->returnCode = 'no';
        $listDns = $this->send('v-list-cron-jobs', $this->userName, 'json');
        $data = json_decode($listDns, true);

        return $data;
    }
578353
protected function findNextJob(): ?Job
    {
        $next_at_timestamp = $this->getNextAtTimestamp();
        $cron_id = $this->getNextCronId();

        if (is_null($cron_id)) {
            return $this->getNextAtJob();
        }

        $next_cron_timestamp = $this->getCronTimestamp($cron_id);

        if ($next_at_timestamp <= $next_cron_timestamp) {
            return $this->getNextAtJob();
        }

        return $this->getNextCronJob();
    }
445241
public function run()
    {
        $prefix = $this->notifyPrefix;
        
        $this->addNotification($prefix.'_start_run_tasks');
        
        foreach ($this->runSteps as $actionName => $stepInfos) {
            $context = null;
            if ($stepInfos->context !== null) {
                $context = $stepInfos->context;
            }
            
            if ($stepInfos->callback === null) {
                $this->addNotification($prefix.'_exec_'.$actionName, $context);
                continue;
            }
            
            $this->addNotification($prefix.'_run_'.$actionName, $context);

            if (is_callable($stepInfos->callback)) {
                $callback = $stepInfos->callback;
                $callback();
            }

            $this->addNotification($prefix.'_done_'.$actionName, $context);
        }
        
        $this->addNotification($prefix.'_end_run_tasks');
    }
1083530
public function executeCronManagement(){
        $dateTime= new \DateTime();
        $actualFrequency= array(
            'i' => $dateTime->format('i'),
            'H' => $dateTime->format('H'),
            'd' => $dateTime->format('d'),
            'm' => $dateTime->format('m'),
            'w' => $dateTime->format('w')
        );
        $file= $this->app->context->getConfigFolderDomain() . 'cronJobs';
        $definedCrons= $this->app->context->readConfigurationFile($file)['crons'];
        $cronsToExeture= array();
        foreach ($definedCrons as $cronEsp) {
            $frecuenciaActiva= $this->activeFrequency($cronEsp['frequency'], $actualFrequency);
            if($frecuenciaActiva){
                $cronsToExeture[]= $cronEsp;
            }
        }
        //Ejecuto las tareas en la que su frecuencia sea activa
        foreach ($cronsToExeture as $cronEsp) {
            $propertiesEsp= isset($cronEsp['properties']) ? $cronEsp['properties'] : NULL;
            $this->executeCron($cronEsp['cronController'], $cronEsp['method'], $propertiesEsp);
        }        
    }
849876
public function execute()
    {
        $stmt = $this->connection->prepare($this->getSQL());
        $stmt->execute($this->getParams());

        return $this->counting ? (int) $stmt->fetchColumn() : $stmt->fetchAll();
    }
195618
public function run()
	{
		if( isset( $this->config['task_list'] ) && !empty( $this->config['task_list'] ) ){
			$task_list            = $this->config['task_list'];
			$cronLastExecTimeList = [];
			// 定时执行
			ServerManager::getInstance()->getServer()->tick( $this->config['loop_time'] * 1000, function() use ( &$task_list, &$cronLastExecTimeList ){
				// 分别执行
				foreach( $task_list as $name => $option ){
					try{
						// 是到期需执行 当前时间 > 最后一次时间 + 间隔时间
						$last_time     = isset( $cronLastExecTimeList[$name] ) ? $cronLastExecTimeList[$name] : 0;
						$current_time  = time();
						$interval_time = ceil( $option['interval_time'] );

						if( $current_time > ($last_time + $interval_time) ){
							// 设置最后一次执行时间 不可等任务执行完毕后再设置时间，因为会阻塞导致每秒进行一次
							$cronLastExecTimeList[$name] = $current_time;
							// 检测是否可执行
							if( \ezswoole\Cron::checkTask( $name, $option ) === true ){
								\EasySwoole\Core\Swoole\Task\TaskManager::async( function() use ( $name, $option ){
									\ezswoole\Cron::exec( $name, $option );
									return true;
								} );
							} else{
								// 删除该任务
								unset( $task_list[$name] );
							}
						}
					} catch( \Exception $e ){
						\EasySwoole\EasySwoole\Logger::getInstance()->log($e->getTraceAsString(),'error');
					}
				}
			} );
		}
		return true;
	}
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;
    }
150075
public function getTasks()
    {
        $tasks = [];

        foreach ($this->getKernelEvents() as $event) {
            $tasks[] = [
                'task'          => $this->formatTask($event),
                'expression'    => $event->expression,
                'nextRunDate'   => $event->nextRunDate()->format('Y-m-d H:i:s'),
                'description'   => $event->description,
                'readable'      => CronSchedule::fromCronString($event->expression)->asNaturalLanguage(),
            ];
        }

        return $tasks;
    }
72603
public function process()
    {
        $taskRows = $this->getTasksWithAssignedSite();
        $legacySchedulerTasks = $taskRows->fetchAll();
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable("tx_scheduler_task");

        $status = FlashMessage::OK;
        $title = 'Remove site from scheduler task';
        $failedTaskCount = 0;
        $migratedTaskCount = 0;
        foreach ($legacySchedulerTasks as $legacySchedulerTask) {
            try {
                $uid = $legacySchedulerTask['uid'];
                $task = unserialize($legacySchedulerTask['serialized_task_object']);
                $task->setRootPageId($task->getSite()->getRootPageId());
                $updatedTask = serialize($task);
                $updatedRows = $queryBuilder->update('tx_scheduler_task')
                    ->where($queryBuilder->expr()->eq('uid', $uid))
                    ->set('serialized_task_object', $updatedTask)
                    ->execute();

                $migratedTaskCount += $updatedRows;
            } catch (\Exception $e) {
                $failedTaskCount++;
                $status = FlashMessage::ERROR;
            }
        }

        $message = 'Migrated ' . (int)$migratedTaskCount . ' scheduler tasks! Update of ' . (int)$failedTaskCount . ' failed!';
        return [$status, $title, $message];
    }