Beispiel #1
0
 /**
  * Start's the CRON scanner and executes the jobs configured in the systems
  * etc/appserver/conf.d/cron.xml and in the applications META-INF/cron.xml files.
  *
  * @return void
  * @see \AppserverIo\Appserver\Core\AbstractThread::main()
  */
 public function main()
 {
     // log the configured deployment directory
     $this->getSystemLogger()->info('Now start CRON scanner');
     // load the validated and merged CRON jobs
     /** \AppserverIo\Appserver\Core\Api\Node\CronNodeInterface $cronNode */
     $cronNodes = $this->newService('AppserverIo\\Appserver\\Core\\Api\\ScannerService')->findAll();
     // execute all the registered CRON jobs
     while (true) {
         // execute each of the jobs found in the configuration file
         /** @var \AppserverIo\Appserver\Core\Api\Node\CronNodeInterface $cronNode */
         foreach ($cronNodes as $cronNode) {
             // execute each of the jobs found in the configuration file
             /** @var \AppserverIo\Appserver\Core\Api\Node\JobNodeInterface $jobNode */
             foreach ($cronNode->getJobs() as $jobNode) {
                 // load the scheduled expression from the job definition
                 $schedule = $jobNode->getSchedule()->getNodeValue()->__toString();
                 // query whether the job has to be scheduled or not
                 if (CronExpression::factory($schedule)->isDue()) {
                     $this->getCronJob($jobNode);
                 }
             }
         }
         // sleep for the configured interval
         sleep($this->getInterval());
     }
 }