/**
  * Parse a Microcron (seconds digit + CRON ) expression
  *
  * @param string                                              $expression         Microcron expression (e.g. '8 * * * * *')
  * @param \AppserverIo\Psr\EnterpriseBeans\ScheduleExpression $scheduleExpression The schedule expression with the data to create the instance with
  * @param \AppserverIo\Microcron\FieldFactory                 $fieldFactory       Factory to create cron fields
  */
 public function __construct($expression, ScheduleExpression $scheduleExpression, FieldFactory $fieldFactory = null)
 {
     // call parent constructor
     parent::__construct($expression, $fieldFactory);
     // set the schedule expression instance
     $this->scheduleExpression = $scheduleExpression;
 }
 /**
  * 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());
     }
 }