protected static function exitIfDone()
 {
     if (!self::shouldProceed()) {
         if (self::$s_pending_tasks == 0) {
             KalturaLog::debug("Gracefully exiting...");
             die;
         } else {
             if (self::$s_force_die_time == null) {
                 // set the force_die_time
                 self::$s_force_die_time = time() + self::SECONDS_TO_FORCE_DIE;
                 KalturaLog::debug("Should exis but still exists [" . self::$s_pending_tasks . "] pending tasts ... Will FORCE DIE in [" . self::SECONDS_TO_FORCE_DIE . "] seconds");
             } elseif (time() > self::$s_force_die_time) {
                 KalturaLog::debug("FORCE DIE !!. There are still [" . self::$s_pending_tasks . "] pending tasts but their time has come !");
                 die;
             } else {
                 KalturaLog::debug("Should exit but still exists [" . self::$s_pending_tasks . "] pending tasts ... Will FORCE DIE in [" . (time() - self::$s_force_die_time) . "] seconds");
             }
         }
     }
     /* easeier process management */
     $batch_script = substr(self::$batch_script_name, strrpos(str_replace("\\", "/", self::$batch_script_name), "/") + 1);
     $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
 }
 public function getStatus()
 {
     /* status check according to running.pid filename and platform relevant command */
     $batch_name = self::getBatchNameFromCommandLine($this->batch_name);
     $running = 0;
     $batch_indicators = self::getIndicatorFilesForBatch($batch_name);
     foreach ($batch_indicators as $ind) {
         $filename_parts = explode('.', $ind);
         if ($this->getProcessStatusByPid($filename_parts[2])) {
             $running++;
         } else {
             // indicator exists, process doesn't
             //echo "i should unlink now: ".$ind;
             unlink(myBatchBase::getBatchwatchPath() . $ind);
         }
     }
     return $running;
 }
Exemple #3
0
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
require_once realpath(dirname(__FILE__)) . '/../config/sfrootdir.php';
define('SF_APP', 'kaltura');
define('SF_ENVIRONMENT', 'batch');
define('SF_DEBUG', true);
$PHP_CMD = "php";
require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php';
$batchwatch_job_list = array("batchConvertClient", "batchConvertServer", "batchBulkUpload", "batchDownloadVideoServer", "batchEmailServer", "batchEntryDeleteServer", "batchMobileUploadServer", "batchFlattenServer", "batchImportServer", "batchNotificationServer", "newBatchCommercialConvertServer", "newBatchConvertClient", "newBatchConvertServer");
$count = 0;
$sleep_time = 1;
$write_to_the_log_seconds = 120;
while (1) {
    try {
        $files = glob(myBatchBase::getBatchwatchPath() . "/*");
        SET_CONTEXT("batchWatch");
        // the files in this directory are supposed to be batch names to be started/stopped or restarted
        foreach ($files as $file) {
            $batch_name = pathinfo($file, PATHINFO_FILENAME);
            if ($batch_name == myBatchBase::REGISTERED_BATCHS) {
                continue;
            }
            // 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