Esempio n. 1
0
 /**
  * Daemon action to run every minute (need to be manually added to the server's cron schedule)
  * and check if any of the specified tasks by user can be executed.
  * For each task get CronProcess instance with information of it's current state. Check run conditions (time and
  * date, uniqueness) and run wrapper command if all conditions are met.
  */
 public function actionDaemon()
 {
     $this->_service->loadTasks();
     /** @var CronTask $task */
     foreach ($this->_service->getActiveTasks() as $task) {
         if (!$task->canRun()) {
             continue;
         }
         if ($task->getProcessInfo()->isRunning() && $task->isUnique()) {
             CronService::log("Cannot run task '{$task->getName()}': it is still running and does not allow overlapping (is unique)", CLogger::LEVEL_WARNING);
         } else {
             $task->getProcessInfo()->runWrapper();
         }
     }
 }
Esempio n. 2
0
 /**
  * Check if task process really active and running
  */
 private function checkProcessAvailability()
 {
     if ($this->pid !== null && $this->status === self::STATUS_RUNNING) {
         exec("ps -p {$this->pid} -o pid", $output);
         if (count($output) != 2) {
             $this->pid = null;
             $this->status = self::STATUS_FAILED;
             CronService::log("Task '{$this->name}' unexpectedly finished. Check logs and console command", CLogger::LEVEL_ERROR);
         }
     }
 }