Esempio n. 1
0
 public function run($jobs = null)
 {
     KalturaLog::info("Schedule helper batch is running");
     try {
         $systemReady = self::$kClient->system->ping();
         if (!$systemReady) {
             KalturaLog::err("System is not yet ready - ping failed");
             return;
         }
     } catch (KalturaClientException $e) {
         KalturaLog::err("System is not yet ready - ping failed");
         return;
     }
     $scheduler = new KalturaScheduler();
     $scheduler->configuredId = $this->getSchedulerId();
     $scheduler->name = $this->getSchedulerName();
     $scheduler->host = KSchedulerConfig::getHostname();
     // get command results from the scheduler
     $commandResults = KScheduleHelperManager::loadResultsCommandsFile();
     KalturaLog::info(count($commandResults) . " command results returned from the scheduler");
     if (count($commandResults)) {
         $this->sendCommandResults($commandResults);
     }
     // get config from the schduler
     $configItems = KScheduleHelperManager::loadConfigItems();
     if (count($configItems)) {
         KalturaLog::info(count($configItems) . " config records sent from the scheduler");
         $this->sendConfigItems($scheduler, $configItems);
     }
     $filters = KScheduleHelperManager::loadFilters();
     KalturaLog::info(count($filters) . " filter records found for the scheduler");
     // get status from the schduler
     $statuses = KScheduleHelperManager::loadStatuses();
     KalturaLog::info(count($statuses) . " status records sent from the scheduler");
     // send status to the server
     $statusResponse = self::$kClient->batchcontrol->reportStatus($scheduler, (array) $statuses, (array) $filters);
     KalturaLog::info(count($statusResponse->queuesStatus) . " queue status records returned from the server");
     KalturaLog::info(count($statusResponse->controlPanelCommands) . " control commands returned from the server");
     KalturaLog::info(count($statusResponse->schedulerConfigs) . " config items returned from the server");
     // send commands to the scheduler
     $commands = array_merge($statusResponse->queuesStatus, $statusResponse->schedulerConfigs, $statusResponse->controlPanelCommands);
     KalturaLog::info(count($commands) . " commands sent to scheduler");
     $this->saveSchedulerCommands($commands);
 }
 private function loadCommands()
 {
     $commands = KScheduleHelperManager::loadCommands();
     if (!$commands || !is_array($commands) || !count($commands)) {
         return;
     }
     //		KalturaLog::info(count($commands) . " commands found");
     $command_results = array();
     foreach ($commands as $command) {
         if ($command instanceof KalturaBatchQueuesStatus) {
             $this->handleQueueStatus($command->workerId, $command->size);
         } elseif ($command instanceof KalturaControlPanelCommand) {
             $command_results[] = $this->handleCommand($command);
         } else {
             KalturaLog::err("command of type " . get_class($command) . " could not be handled");
             $command_results[] = KalturaControlPanelCommandStatus::FAILED;
         }
     }
     $cnt = count($command_results);
     if ($cnt) {
         KalturaLog::info("Sending {$cnt} command results to the server");
         KScheduleHelperManager::saveCommandsResults($command_results);
     }
 }
Esempio n. 3
0
 /**
  * @param array $commands
  */
 public function saveSchedulerCommands(array $commands)
 {
     $type = self::$taskConfig->type;
     $file = "{$type}.cmd";
     KScheduleHelperManager::saveCommand($file, $commands);
 }
 /**
  * @param int $jobType
  */
 protected function saveQueueFilter($jobType)
 {
     $filter = $this->getQueueFilter($jobType);
     $type = KBatchBase::$taskConfig->name;
     $file = "{$type}.flt";
     KalturaLog::debug("Saving filter to {$file}: " . print_r($filter, true));
     KScheduleHelperManager::saveFilter($file, $filter);
 }
Esempio n. 5
0
 /**
  * @param array $commands
  */
 public function saveSchedulerCommands(array $commands)
 {
     $dir = $this->taskConfig->getCommandsDir();
     $type = $this->taskConfig->type;
     $res = self::createDir($dir);
     if (!$res) {
         return;
     }
     $path = "{$dir}/{$type}.cmd";
     KScheduleHelperManager::saveCommands($path, $commands);
 }
 public function run($jobs = null)
 {
     KalturaLog::info("Schedule helper batch is running");
     try {
         $systemReady = $this->kClient->system->ping();
         if (!$systemReady) {
             KalturaLog::err("System is not yet ready - ping failed");
             return;
         }
     } catch (KalturaClientException $e) {
         KalturaLog::err("System is not yet ready - ping failed");
         return;
     }
     $scheduler = new KalturaScheduler();
     $scheduler->configuredId = $this->getSchedulerId();
     $scheduler->name = $this->getSchedulerName();
     $scheduler->host = $this->getConfigHostName();
     // if the hostName is not set in the config - search the differnt env params
     if (!$scheduler->host) {
         if (isset($_SERVER['COMPUTERNAME'])) {
             $scheduler->host = $_SERVER['COMPUTERNAME'];
         } elseif (isset($_SERVER['HOSTNAME'])) {
             $scheduler->host = $_SERVER['HOSTNAME'];
         } elseif (function_exists('gethostname')) {
             $scheduler->host = gethostname();
         } else {
             $scheduler->host = 'unknown';
         }
     }
     // get command results from the scheduler
     $commandResults = KScheduleHelperManager::loadCommandsFile($this->taskConfig->params->commandResultsFilePath);
     KalturaLog::info(count($commandResults) . " command results returned from the scheduler");
     if (count($commandResults)) {
         $this->sendCommandResults($commandResults);
     }
     if ($this->taskConfig->params->configItemsFilePath) {
         // get config from the schduler
         $configItems = KScheduleHelperManager::loadConfigItems($this->taskConfig->params->configItemsFilePath);
         if (count($configItems)) {
             KalturaLog::info(count($configItems) . " config records sent from the scheduler");
             $this->sendConfigItems($scheduler, $configItems);
         }
     }
     $filters = KScheduleHelperManager::loadFilters($this->taskConfig->getQueueFiltersDir());
     KalturaLog::info(count($filters) . " filter records found for the scheduler");
     $statuses = array();
     if ($this->taskConfig->params->statusFilePath) {
         // get status from the schduler
         $statuses = KScheduleHelperManager::loadStatuses($this->taskConfig->params->statusFilePath);
         KalturaLog::info(count($statuses) . " status records sent from the scheduler");
     }
     // send status to the server
     $statusResponse = $this->kClient->batchcontrol->reportStatus($scheduler, (array) $statuses, (array) $filters);
     KalturaLog::info(count($statusResponse->queuesStatus) . " queue status records returned from the server");
     KalturaLog::info(count($statusResponse->controlPanelCommands) . " control commands returned from the server");
     KalturaLog::info(count($statusResponse->schedulerConfigs) . " config items returned from the server");
     // send commands to the scheduler
     $commands = array_merge($statusResponse->queuesStatus, $statusResponse->schedulerConfigs, $statusResponse->controlPanelCommands);
     KalturaLog::info(count($commands) . " commands sent to scheduler");
     $this->saveSchedulerCommands($commands);
 }
 /**
  * @param int $jobType
  */
 protected function saveQueueFilter($jobType)
 {
     $filter = $this->getQueueFilter($jobType);
     $dir = $this->taskConfig->getQueueFiltersDir();
     $type = $this->taskConfig->name;
     $res = self::createDir($dir);
     if (!$res) {
         return;
     }
     $path = "{$dir}/{$type}.flt";
     KalturaLog::debug("Saving filter to {$path}: " . print_r($filter, true));
     KScheduleHelperManager::saveFilter($path, $filter);
 }
 /**
  * @param int $jobType
  */
 protected function saveQueueFilter($jobType)
 {
     $filter = $this->getQueueFilter($jobType);
     $type = KBatchBase::$taskConfig->name;
     $file = "{$type}.flt";
     KScheduleHelperManager::saveFilter($file, $filter);
 }
Esempio n. 9
0
 public function _cleanup()
 {
     if ($this->pipes) {
         foreach ($this->pipes as $index => $ref) {
             if (is_resource($ref)) {
                 fclose($ref);
             }
         }
         unset($this->pipes);
         $this->pipes = null;
     }
     if ($this->isMockedProcess) {
         $this->killProcess();
         KScheduleHelperManager::unlinkRunningBatch($this->taskConfig->name, $this->taskConfig->getTaskIndex());
         return;
     }
     if ($this->handle && is_resource($this->handle)) {
         $status = proc_get_status($this->handle);
         if (!$status['running']) {
             return;
         }
         $this->killProcess();
         proc_terminate($this->handle);
         proc_close($this->handle);
         $this->handle = null;
     }
 }