本文整理匯總了PHP中Cron\CronExpression::setExpression方法的典型用法代碼示例。如果您正苦於以下問題:PHP CronExpression::setExpression方法的具體用法?PHP CronExpression::setExpression怎麽用?PHP CronExpression::setExpression使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Cron\CronExpression
的用法示例。
在下文中一共展示了CronExpression::setExpression方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->logPath = $input->getOption('log');
$cronInfoUrl = sprintf('http://%s:%d/info/cron/', $input->getOption('host'), $input->getOption('port'));
$response = json_decode($this->curlRequest->getCurlResult($cronInfoUrl, [CURLOPT_TIMEOUT_MS => 100000])['body'], true);
if (!is_array($response)) {
$this->log('Core connection failed, exiting');
throw new \RuntimeException('Error connecting to core server');
}
foreach ($response as $cronItem) {
$this->cronExpression->setExpression(Ar::get($cronItem, 'time'));
if ($this->cronExpression->isDue()) {
$this->log('Executing: ' . Ar::get($cronItem, 'type'));
switch (Ar::get($cronItem, 'type')) {
case 'playbook':
$url = sprintf('http://%s:%d/playbook/run/', $input->getOption('host'), $input->getOption('port'));
$playbookFile = Ar::get($cronItem, 'playbook');
$playbook = $this->fileLoader->load($playbookFile);
$this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['playbook' => urlencode($playbook), 'filename' => $playbookFile], CURLOPT_TIMEOUT_MS => 100000]);
$this->log('Executed playbook: ' . $playbookFile);
break;
case 'command':
$url = sprintf('http://%s:%d/command/run/', $input->getOption('host'), $input->getOption('port'));
$command = Ar::get($cronItem, 'command');
if (null === $command) {
break;
}
$this->curlRequest->getCurlResult($url, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => ['command' => urlencode($command)], CURLOPT_TIMEOUT_MS => 100000]);
$this->log('Executed command: ' . $command);
break;
case 'curl':
break;
}
}
}
}