public function convert()
 {
     SET_CONTEXT("KCS({$this->server_id})");
     KalturaLog::debug("----------------- kConversionServer ------------------- ");
     KalturaLog::debug("------ cmd_path [{$this->cmd_path}] ------");
     KalturaLog::debug("------ res_path [{$this->res_path}] ------");
     //		self::init();
     list($sleep_between_cycles, $number_of_times_to_skip_writing_sleeping) = self::getSleepParams('app_conversion_server_');
     $temp_count = 0;
     while (true) {
         self::exitIfDone();
         try {
             $this->convertAllFilesInQueue($temp_count == 0);
         } catch (Exception $ex) {
             // TODO - log exceptions !!!
             // try to recover !!
             KalturaLog::debug($ex->getTraceAsString());
         }
         if ($temp_count == 0) {
             KalturaLog::debug("Ended conversion of all files in queue. Resting for a while (" . $sleep_between_cycles . ") seconds. " . "Will write to the log in (" . $sleep_between_cycles * $number_of_times_to_skip_writing_sleeping . ") seconds");
         }
         $temp_count++;
         if ($temp_count >= $number_of_times_to_skip_writing_sleeping) {
             $temp_count = 0;
         }
         sleep($sleep_between_cycles);
     }
 }
 public function convert()
 {
     SET_CONTEXT("CC {$this->mode}");
     list($sleep_between_cycles, $number_of_times_to_skip_writing_sleeping) = self::getSleepParams('app_conversion_client_');
     self::initDb();
     $temp_count = 0;
     while (true) {
         self::exitIfDone();
         try {
             $this->sentToCenversion($temp_count == 0);
             self::succeeded();
         } catch (Exception $ex) {
             // try to recover !!
             echo $ex;
             self::initDb(true);
             self::failed();
         }
         try {
             $this->pollConverted($temp_count == 0);
         } catch (Exception $ex) {
             // TODO - log exceptions !!!
             // try to recover !!
             echo $ex;
             self::initDb(true);
             self::failed();
         }
         if ($temp_count == 0) {
             KalturaLog::debug("Ended conversion. sleeping for a while (" . $sleep_between_cycles . " seconds). Will write to the log in (" . $sleep_between_cycles * $number_of_times_to_skip_writing_sleeping . ") seconds");
         }
         $temp_count++;
         if ($temp_count >= $number_of_times_to_skip_writing_sleeping) {
             $temp_count = 0;
         }
         sleep($sleep_between_cycles);
     }
 }
Ejemplo n.º 3
0
 public function myBatchFlattenServer($script_name)
 {
     $this->script_name = $script_name;
     $this->register($script_name);
     SET_CONTEXT("FS");
     $MAX_ITERATIONS_DUE_TO_PROPEL_MEMORY_LEAK = 10000000;
     self::initDb();
     list($sleep_between_cycles, $number_of_times_to_skip_writing_sleeping) = self::getSleepParams('app_flatten_');
     $last_worker_count = 0;
     $iteration = 0;
     $c = new Criteria();
     $currentDc = kDataCenterMgr::getCurrentDc();
     $c->add(BatchJobPeer::DC, kDataCenterMgr::getCurrentDcId());
     $c->add(BatchJobPeer::JOB_TYPE, BatchJobType::FLATTEN);
     $c->add(BatchJobPeer::STATUS, BatchJob::BATCHJOB_STATUS_PROCESSED);
     $temp_count = 0;
     while (1) {
         self::exitIfDone();
         try {
             sleep($sleep_between_cycles);
             $jobs = BatchJobPeer::doSelect($c);
             foreach ($jobs as $job) {
                 $data = json_decode($job->getData(true), true);
                 $entry_id = $data['entryId'];
                 $entry_int_id = $data['entryIntId'];
                 $entry_version = $data['entryVersion'];
                 $file_format = $data['fileFormat'];
                 $entry = entryPeer::retrieveByPK($entry_id);
                 if (!$entry) {
                     // entry is probably deleted if it is not returned from retrieveByPK
                     // close job as failed
                     $job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
                     $job->setDescription("could not retrieve entry, probably deleted");
                     TRACE("could not retrieve entry {$entry_id} , probably deleted");
                     $job->save();
                     continue;
                 }
                 $fileSyncKey = $entry->getSyncKey(entry::FILE_SYNC_ENTRY_SUB_TYPE_DOWNLOAD, $file_format);
                 $fullFinalPath = kFileSyncUtils::getLocalFilePathForKey($fileSyncKey);
                 $finalPathNoExt = substr($fullFinalPath, 0, strlen($fullFinalPath) - strlen($file_format));
                 myContentStorage::fullMkdir($fullFinalPath);
                 $wildcardFinalPath = $finalPathNoExt . "*";
                 $older_files = glob($wildcardFinalPath);
                 foreach ($older_files as $older_file) {
                     TRACE("removing old file: [{$older_file}]");
                     @unlink($older_file);
                 }
                 TRACE("Downloading: {$fullFinalPath}");
                 kFile::downloadUrlToFile($data["serverUrl"], $fullFinalPath);
                 if (!file_exists($fullFinalPath)) {
                     TRACE("file doesnt exist: " . $data["serverUrl"]);
                     $job->setDescription("file doesnt exist: " . $data["serverUrl"]);
                     $job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
                 } else {
                     if (filesize($fullFinalPath) < 100000) {
                         @unlink($fullFinalPath);
                         TRACE("file too small: " . $data["serverUrl"]);
                         $job->setDescription("file too small: " . $data["serverUrl"]);
                         $job->setStatus(BatchJob::BATCHJOB_STATUS_FAILED);
                     } else {
                         if ($data['email']) {
                             $downloadLink = $entry->getDownloadUrl() . '/format/' . $file_format;
                             kJobsManager::addMailJob(null, $entry_id, $entry->getPartnerId(), self::KALTURAS_FLATTEN_READY, kMailJobData::MAIL_PRIORITY_NORMAL, kConf::get("batch_flatten_video_sender_email"), kConf::get("batch_flatten_video_sender_name"), $data['email'], array($data['email'], $downloadLink));
                         }
                         TRACE("Deleting: " . $data["deleteUrl"]);
                         kFile::downloadUrlToString($data["deleteUrl"]);
                         myNotificationMgr::createNotification(kNotificationJobData::NOTIFICATION_TYPE_ENTRY_UPDATE, $entry);
                         $job->setStatus(BatchJob::BATCHJOB_STATUS_FINISHED);
                         $filePath = kFileSyncUtils::getLocalFilePathForKey($fileSyncKey);
                         if (file_exists($filePath)) {
                             try {
                                 kFileSyncUtils::createSyncFileForKey($fileSyncKey);
                             } catch (Exception $ex) {
                                 TRACE("ignore ERROR: " . $ex->getMessage());
                             }
                         } else {
                             TRACE("The file [{$filePath}] doesn't exists, not creating FileSync");
                         }
                     }
                 }
                 $job->save();
             }
         } catch (Exception $ex) {
             TRACE("ERROR: " . $ex->getMessage());
             self::initDb(true);
             self::failed();
         }
         if ($temp_count == 0) {
             TRACE("Ended conversion. sleeping for a while (" . $sleep_between_cycles . " seconds). Will write to the log in (" . $sleep_between_cycles * $number_of_times_to_skip_writing_sleeping . ") seconds");
         }
         $temp_count++;
         if ($temp_count >= $number_of_times_to_skip_writing_sleeping) {
             $temp_count = 0;
         }
     }
 }
Ejemplo n.º 4
0
 * 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
                //				$cmd_line = "service $batch_name $command";