public static function getBatchStatus($args)
 {
     $batch_status = new batchStatus();
     $batch_status->batch_name = $args[0];
     $stats = $batch_status->getDbStats($batch_status->batch_name, BatchJobType::FLATTEN);
     $batch_status->addToPending("DB:batch_job, type=" . BatchJobType::FLATTEN . " status=" . BatchJob::BATCHJOB_STATUS_PENDING, @$stats["full_stats"][BatchJob::BATCHJOB_STATUS_PENDING]["count"]);
     $batch_status->addToInProc("DB:batch_job, type=" . BatchJobType::FLATTEN . " status=" . BatchJob::BATCHJOB_STATUS_PROCESSING, @$stats["full_stats"][BatchJob::BATCHJOB_STATUS_PROCESSING]["count"]);
     $batch_status->succeedded_in_period = @$stats["full_stats"][BatchJob::BATCHJOB_STATUS_FINISHED]["count"];
     $batch_status->failed_in_period = @$stats["full_stats"][BatchJob::BATCHJOB_STATUS_FAILED]["count"];
     $batch_status->last_log_time = @$stats["log_timestamp"];
     return $batch_status;
 }
 public static function getBatchStatus($args)
 {
     $batch_status = new batchStatus();
     $batch_status->batch_name = $args[0];
     $batch_status->addToPending("Disk:" . $args[1] . "*" . kConversionHelper::INDICATOR_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[1], "*" . kConversionHelper::INDICATOR_SUFFIX));
     $batch_status->addToInProc("Disk:" . $args[1] . "*" . kConversionHelper::INPROC_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[1], "*" . kConversionHelper::INPROC_SUFFIX));
     list($a, $batch_status->last_log_time) = $batch_status->getLogData($batch_status->batch_name);
     return $batch_status;
 }
 protected function register($script_name)
 {
     $args = func_get_args();
     array_shift($args);
     // ignore the first arg - always the script_name
     $cls = get_class($this);
     $script_name = realpath($script_name);
     self::$batch_script_name = $script_name;
     /* easeier process management */
     $batch_script = substr(self::$batch_script_name, strrpos(str_replace("\\", "/", self::$batch_script_name), "/") + 1);
     if (kConf::get('kaltura_installation_type') == 'CE') {
         /* on CE verify that other batches are not running */
         $stub_status = new batchStatus();
         $indicators = $stub_status->getIndicatorFilesForBatch(str_replace('.php', '', $batch_script));
         foreach ($indicators as $ind) {
             $parts = explode(".", $ind);
             if ($stub_status->getProcessStatusByPid($parts[2])) {
                 die("another batch of type {$batch_script} is already running... exiting.");
             }
         }
     }
     $running_filename = str_replace('.php', '', $batch_script) . '.running.' . getmypid();
     $file_path = self::getBatchwatchPath() . "/" . $running_filename;
     file_put_contents($file_path, date('Y-m-d H:i:s'));
     // sync - OK
     $line = $cls . "," . $script_name . "," . implode(",", $args);
     $file_path = self::getBatchwatchPath() . "/" . self::REGISTERED_BATCHS;
     if (!file_exists($file_path)) {
         file_put_contents($file_path, $line);
         // sync - OK
         return;
     }
     $content = @file_get_contents($file_path);
     if (strpos($content, $line) !== FALSE) {
         return;
     }
     // add to file only of does not already exists
     $content .= self::SEPARATOR . $line;
     file_put_contents($file_path, $content);
     // sync - OK
 }
 public static function getBatchStatus($args)
 {
     //print_r ( $args );
     $mode = $args[3];
     $batch_status = new batchStatus();
     $batch_status->batch_name = $args[0];
     $batch_status->addToPending("Disk:" . $args[1] . "*" . kConversionHelper::INDICATOR_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[1], "*" . kConversionHelper::INDICATOR_SUFFIX));
     // bellow - from the fact this is infact a kConversionClientBase
     $batch_status->addToInProc("Disk:" . $args[1] . "*" . kConversionHelper::INPROC_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[1], "*" . kConversionHelper::INPROC_SUFFIX));
     $batch_status->addToInProc("Disk:" . $args[2] . "*" . kConversionHelper::INDICATOR_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[2], "*" . kConversionHelper::INDICATOR_SUFFIX));
     $batch_status->addToInProc("Disk:" . $args[2] . "*" . kConversionHelper::INPROC_SUFFIX, $batch_status->getDiskStatsCount($args[0], $args[2], "*" . kConversionHelper::INPROC_SUFFIX));
     list($a, $batch_status->last_log_time) = $batch_status->getLogData($args[0]);
     return $batch_status;
 }
Пример #5
0
 private function createBatchwatchCmd($cmd)
 {
     // use this with no prefix
     $batch_name = self::getBatchNameFromCommandLine($this->batch_name);
     $path = myContentStorage::getFSContentRootPath() . "/batchwatch/{$batch_name}";
     self::executeRunBatch($cmd, $batch_name);
     if ($cmd == "stop") {
         $path = batchStatus::batchEnd($batch_name);
     }
     return $path;
 }
Пример #6
0
     // skip if the special file holding the registered batchs
     if ($batch_name[0] == "_") {
         continue;
     }
     //myBatchBase::IGNORE_PREFIX  ) continue;
     if (in_array($batch_name, $batchwatch_job_list)) {
         $command = file_get_contents($file);
         // TODO - change to fit the way we start / stop / restart
         //				$cmd_line = "service $batch_name $command";
         $cmd_line = "{$PHP_CMD} runBatch.php {$command} {$batch_name} ";
         TRACE("{$cmd_line}");
         $output = array();
         exec($cmd_line, $output, $return_var);
         TRACE("Result: [{$return_var}]\n" . print_r($output, true));
         if ($command == "stop") {
             $path = batchStatus::batchEnd($batch_name);
         }
     } else {
         TRACE("VERY BAD!!: tying to manipulate invalid batch [{$batch_name}]. Ignoring...");
     }
     // remove the file
     unlink($file);
 }
 if ($count > $write_to_the_log_seconds) {
     $count = 0;
 }
 if ($count == 0) {
     TRACE("Sleeping for [{$sleep_time}] second. Will write to the log in ({$write_to_the_log_seconds}]");
 }
 sleep($sleep_time);
 $count++;