public function run() { KalturaLog::debug("run()"); $startTime = time(); while ($this->keepRunning) { $this->loadConfig(); $this->loadCommands(); $fullCycle = false; if ($this->nextStatusTime < time()) { $fullCycle = true; $this->nextStatusTime = time() + $this->statusInterval; KalturaLog::debug("Next Status Time: " . date('H:i:s', $this->nextStatusTime)); } $statuses = array(); $taskConfigs = $this->schedulerConfig->getTaskConfigList(); foreach ($taskConfigs as $taskConfig) { if (!$taskConfig->type) { continue; } $runningTasksCount = $this->numberOfRunningTasks($taskConfig->name); $statuses[] = $this->createStatus($taskConfig, KalturaSchedulerStatusType::RUNNING_BATCHES_COUNT, $runningTasksCount); $shouldRun = true; if (!$taskConfig->enable) { $shouldRun = false; } if (!$taskConfig->autoStart && !isset($this->startedRemotely[$taskConfig->name])) { $shouldRun = false; } if (isset($this->stoppedRemotely[$taskConfig->name])) { $shouldRun = false; } if ($fullCycle) { $statuses[] = $this->createStatus($taskConfig, KalturaSchedulerStatusType::RUNNING_BATCHES_IS_RUNNING, $shouldRun ? 1 : 0); } if ($shouldRun && $this->shouldExecute($taskConfig)) { $this->spawn($taskConfig); } } if ($fullCycle) { $statuses[] = $this->createSchedulerStatus(KalturaSchedulerStatusType::RUNNING_BATCHES_IS_RUNNING, 1); KScheduleHelperManager::saveStatuses($this->schedulerConfig->getStatusFilePath(), $statuses); } $runningBatches = KScheduleHelperManager::loadRunningBatches($this->schedulerConfig->getCommandsDir()); foreach ($this->runningTasks as $taskName => &$tasks) { if (!count($tasks)) { continue; } foreach ($tasks as $index => &$proc) { if ($proc->isRunning()) { if (isset($runningBatches[$proc->getName()][$proc->getIndex()])) { unset($runningBatches[$proc->getName()][$proc->getIndex()]); } continue; } $proc->_cleanup(); unset($tasks[$index]); } self::onRunningInstancesEvent($taskConfig, count($this->runningTasks[$taskName])); } foreach ($runningBatches as $workerName => $indexes) { if (!is_array($indexes)) { continue; } $keys = array_keys($indexes); $index = intval(reset($keys)); $this->nextRunIndex[$workerName] = $index; } sleep(1); } KalturaLog::info("-- Done --"); KalturaLog::debug("ended after [" . (time() - $startTime) . "] seconds"); die; }