当前位置: 首页>>代码示例>>PHP>>正文


PHP CronExpression::isValidExpression方法代码示例

本文整理汇总了PHP中Cron\CronExpression::isValidExpression方法的典型用法代码示例。如果您正苦于以下问题:PHP CronExpression::isValidExpression方法的具体用法?PHP CronExpression::isValidExpression怎么用?PHP CronExpression::isValidExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cron\CronExpression的用法示例。


在下文中一共展示了CronExpression::isValidExpression方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (null === $value) {
         return;
     }
     if (!Validator::isValidExpression($value)) {
         $this->context->buildViolation($constraint->message)->setParameter('{{string}}', $value)->addViolation();
     }
 }
开发者ID:aboutcoders,项目名称:scheduler-bundle,代码行数:12,代码来源:CronExpressionValidator.php

示例2: getCacheLifetimeForExpression

 /**
  * @param string $expression Cron expression
  *
  * @return int Cache lifetime in seconds
  */
 protected function getCacheLifetimeForExpression($expression)
 {
     if (!CronExpression::isValidExpression($expression)) {
         return 0;
     }
     $now = new \DateTime();
     $cronExpression = CronExpression::factory($expression);
     $endTime = $cronExpression->getNextRunDate($now);
     return $endTime->getTimestamp() - $now->getTimestamp();
 }
开发者ID:sulu,项目名称:sulu,代码行数:15,代码来源:CacheLifetimeResolver.php

示例3: testValidationWorks

 /**
  * @covers Cron\CronExpression::__construct
  * @covers Cron\CronExpression::factory
  * @covers Cron\CronExpression::isValidExpression
  * @covers Cron\CronExpression::setExpression
  * @covers Cron\CronExpression::setPart
  */
 public function testValidationWorks()
 {
     // Invalid. Only four values
     $this->assertFalse(CronExpression::isValidExpression('* * * 1'));
     // Valid
     $this->assertTrue(CronExpression::isValidExpression('* * * * 1'));
 }
开发者ID:phantsang,项目名称:8csfOIjOaJSlDG2Y3x992O,代码行数:14,代码来源:CronExpressionTest.php

示例4: crontabWorker

 public function crontabWorker()
 {
     $cron_queue = $this->shm->get("worker_cron_queue");
     $cron_ready = $this->shm->get("worker_cron_ready");
     if (empty($cron_queue)) {
         return;
     }
     foreach ($cron_queue as $worker_name => $config) {
         $crontab = \Cron\CronExpression::isValidExpression($config["crontab"]);
         if (!$crontab) {
             $timeNs = intval($config["crontab"]);
         } else {
             $cron = \Cron\CronExpression::factory($config["crontab"]);
             $nextRunTime = $cron->getNextRunDate()->getTimestamp();
             $timeNs = intval($nextRunTime - time());
         }
         if ($timeNs < 1) {
             continue;
         }
         swoole_timer_after(1000 * $timeNs, function () use($worker_name, $config) {
             self::getInstance()->disPatch($config['action'], array('worker_name' => $worker_name));
             $cron_queue = $this->shm->get("worker_cron_queue");
             $cron_ready = $this->shm->get("worker_cron_ready");
             unset($cron_ready[$worker_name]);
             $cron_queue[$worker_name] = $config;
             $this->shm->set("worker_cron_queue", $cron_queue);
             $this->shm->set("worker_cron_ready", $cron_ready);
         });
         unset($cron_queue[$worker_name]);
         $cron_ready[$worker_name] = $config;
     }
     $this->shm->set("worker_cron_queue", $cron_queue);
     $this->shm->set("worker_cron_ready", $cron_ready);
 }
开发者ID:millken,项目名称:ypf,代码行数:34,代码来源:Swoole.php

示例5: createUpdateJob

 /**
  * Função createUpdateJob
  *
  * Creates a new job in the database, if the parameter \$jobID is filled, the Job's content will be updated.
  *
  * @author Henrique Ramos <hramos@live.de>
  * @version 0.2.0
  * @since 0.1.0
  *
  * @param array[] $params F3 parameters array.
  *
  * @throws Exception If _POST parameters job_name, job_cron, job_type, job_path aren't filled or are invalid
  * @throws Exception If can't add the Job in the database
  *
  * @return array[]
  */
 public function createUpdateJob($params)
 {
     global $connectDB, $logger;
     try {
         $jobID = (!empty($params['jobID']) and is_numeric($params['jobID'])) ? $params['jobID'] : NULL;
         $job_author = 1;
         //Melhorar isso
         if (empty($_POST['job_name'])) {
             throw new \Exception(__("You need a valid name for this job."));
         }
         if (empty($_POST['job_cron'])) {
             throw new \Exception(__("We need the Cron filled."));
         }
         if (!\Cron\CronExpression::isValidExpression($_POST['job_cron'])) {
             throw new \Exception(__("We need a valid Cron syntax."));
         }
         if (empty($_POST['job_type']) or !in_array($_POST['job_type'], array('internal', 'external'))) {
             throw new \Exception(__("We need the job type filled.  Choose between \"internal\" and \"external\"."));
         }
         if (empty($_POST['job_path'])) {
             throw new \Exception(__("We need the job path filled."));
         }
         if (empty($_POST['job_status']) or !in_array($_POST['job_status'], array('active', 'disable'))) {
             throw new \Exception(__("We need the job type filled.  Choose between \"active\" and \"disable\"."));
         }
         $alertArray = $_POST['alerts'];
         if (!empty($alertArray) and !is_array($alertArray)) {
             throw new \Exception(__("Fill the \"alerts\" parameter correctly."));
         }
         $job_comment = !empty($_POST['job_comment']) ? $_POST['job_comment'] : NULL;
         $job_status = $_POST['job_status'] == 'active' ? 1 : 0;
         $job_cron = $_POST['job_cron'];
         $job_group = 1;
         //Groups::checkIfGroupExists($_POST['job_group'])?$_POST['job_group']:NULL;
         $timestamp = time();
         $connectDB->beginTransaction();
         $insertJobDatabase = $connectDB->prepare("INSERT INTO `jobs`(`job_id`, `job_name`, `job_date`, `job_cron`, `job_path`, `job_type`, `job_author`, `job_status`, `job_comment`, `job_group`, `is_running`) VALUES (:job_id,:job_name, FROM_UNIXTIME(:job_date),:job_cron,:job_path,:job_type,:job_author,:job_status,:job_comment,:job_group,0) ON DUPLICATE KEY UPDATE `job_name`=:job_name, `job_cron`=:job_cron, `job_path`=:job_path, `job_type`=:job_type, `job_status`=:job_status, `job_comment`=:job_comment, `job_group`=:job_group");
         $insertJobDatabase->bindValue(":job_id", $jobID, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_name", $_POST['job_name'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_date", $timestamp, \PDO::PARAM_INT);
         $insertJobDatabase->bindValue(":job_cron", $job_cron, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_path", $_POST['job_path'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_type", $_POST['job_type'], \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_author", $job_author, \PDO::PARAM_INT);
         $insertJobDatabase->bindValue(":job_status", $job_status, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_comment", $job_comment, \PDO::PARAM_STR);
         $insertJobDatabase->bindValue(":job_group", $job_group, \PDO::PARAM_STR);
         if (!$insertJobDatabase->execute()) {
             $logger->addError(sprintf(__("MySQL Error %s"), var_Export($insertJobDatabase->errorInfo(), true)));
             throw new \Exception(sprintf(__("Problems with database insertion. Try again later. MySQL Error %s"), $insertJobDatabase->errorCode()));
         }
         $JobIDInfo = $connectDB->lastInsertId();
         foreach ($alertArray as $alertIndividual) {
             $alert = new Alert();
             $alert->addUpdateAlert($JobIDInfo, $alertIndividual);
         }
         $logger->addError(sprintf(__("About Job: {id: \"%s\" name: \"%s\", timestamp: \"%s\", path: \"%s\"}"), $JobIDInfo, $_POST['job_name'], $timestamp, $_POST['job_path']));
         //Inserir no crontab
         switch ($_POST['job_type']) {
             case 'external':
                 $logger->addInfo(sprintf(__("External Job %s"), ExternalCrawlerPath));
                 $pathToCallingJob = ExternalCrawlerPath;
                 break;
             case 'internal':
             default:
                 $logger->addInfo(sprintf(__("Internal Job %s"), InternalCrawlerPath));
                 $pathToCallingJob = InternalCrawlerPath;
                 break;
         }
         $logger->addInfo(sprintf(__("Job Info %s"), var_export($JobInfo, true)));
         $logger->addInfo(sprintf(__("CRON Expression %s"), $job_cron));
         $logger->addInfo(sprintf(__("CRON Log %s"), Zeus_Monitor_Log_Path));
         $logger->addInfo(sprintf(__("Path to call job %s"), $pathToCallingJob));
         $cronParser = \Cron\CronExpression::factory($job_cron);
         $cronMinute = !empty($cronParser->getExpression(1)) ? $cronParser->getExpression(1) : "*";
         $cronHour = !empty($cronParser->getExpression(2)) ? $cronParser->getExpression(2) : "*";
         $cronDayMonth = !empty($cronParser->getExpression(3)) ? $cronParser->getExpression(3) : "*";
         $cronMonth = !empty($cronParser->getExpression(4)) ? $cronParser->getExpression(4) : "*";
         $cronDayWeek = !empty($cronParser->getExpression(5)) ? $cronParser->getExpression(5) : "*";
         $addToCron = new \MyBuilder\Cronos\Formatter\Cron();
         $addToCron->comment(sprintf("Job %s", addslashes(htmlspecialchars($_POST['job_name']))))->job("php {$pathToCallingJob} {$JobIDInfo}")->setMinute($cronMinute)->setHour($cronHour)->setDayOfMonth($cronDayMonth)->setMonth($cronMonth)->setDayOfWeek($cronDayWeek)->setStandardOutFile('log')->appendStandardErrorToFile(Zeus_Monitor_Log_Path)->end();
         $connectDB->commit();
         if (is_null($jobID)) {
             return json_encode(array('success' => sprintf(__("Job inserted with success.<br />Please, insert this code inside your cron:<br /><code>%s</code>"), nl2br($addToCron->format()))));
//.........这里部分代码省略.........
开发者ID:henriqueramos,项目名称:zeus,代码行数:101,代码来源:Job.php

示例6: validateExpression

 /**
  * @param string $expression
  * @throws CronomJobException
  */
 private function validateExpression($expression)
 {
     if (!CronExpression::isValidExpression($expression)) {
         $this->throwException('Invalid expression');
     }
 }
开发者ID:yanivgal,项目名称:cronom,代码行数:10,代码来源:CronomJob.php

示例7: schedule

 /**
  * Puts a command into recursive schduled task, this will be enqueued by
  * cron spawned workers for the next single process.
  *
  * @param {string} $name Unique identifier for this schdule task.
  * @param {string} $expr Cron expression for the schdule.
  * @param {string} $command The command to run.
  * @param {?array} $options This is identical to the option array in enqueue()
  *                          but also includes properties starts with dollar sign.
  */
 public static function schedule($name, $expr, $command, $options = array())
 {
     $schedules = Node::get(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS_SCHEDULE, 'name' => $name));
     if ($schedules) {
         throw new ProcessException('Schedule with the same name already exists.', self::ERR_ENQUE);
     }
     if (!CronExpression::isValidExpression($expr)) {
         throw new ProcessException('Expression is not in valid cron format.', self::ERR_CEXPR);
     }
     return Node::set(array(Node::FIELD_COLLECTION => FRAMEWORK_COLLECTION_PROCESS_SCHEDULE, 'name' => $name, 'schedule' => $expr, 'command' => $command) + $options);
 }
开发者ID:Victopia,项目名称:prefw,代码行数:21,代码来源:Process.php


注:本文中的Cron\CronExpression::isValidExpression方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。