Esempio n. 1
0
 /**
  * Static method to create new instance and get information about last execution. Used in console daemon action.
  * @param CronTask $task configured task instance
  * @param CronService $service application service component
  * @return CronProcess
  */
 public static function createByTask(CronTask $task, CronService $service)
 {
     $process = new self($service, $task->getId());
     $process->readInfoFile();
     $process->unique = $task->isUnique();
     $process->name = $task->getName();
     $process->command = $task->getCommand();
     $process->action = $task->getCommandAction();
     $params = array();
     foreach ($task->getParams() as $param => $value) {
         $params[] = "--{$param}={$value}";
     }
     $process->params = $params;
     $app = Yii::app()->getBasePath() . DIRECTORY_SEPARATOR . 'yiic';
     $output = $task->getOutputFile() ? "> {$task->getOutputFile()}" : '>> /dev/null';
     $process->_wrapperCommand = "{$app} cron run --id={$task->getId()} {$output} 2>&1 & echo \$!";
     return $process;
 }