Exemple #1
0
 public function freeUnusedInstances()
 {
     if (!Swf2Vid::getInstance()->getVideosByType('pending')) {
         $instances = Instances::getInstance();
         if ($available = $instances->findAvailable()) {
             for ($i = count($available) - 1; $i >= 0; $i--) {
                 $instances->terminate($available[$i], $i > 0);
             }
         }
     }
 }
Exemple #2
0
 /**
  * @param Video $video
  * @param bool $urgent
  *
  * @return bool|mixed
  * @throws Swf2VidError
  * @throws \Minute\Errors\ConfigError
  */
 public function queueVideo($video, $urgent = false)
 {
     $app = App::getInstance();
     $host = $app->getSelfHost();
     $config = $app->config;
     $instances = Instances::getInstance();
     $player_url = HttpUtils::prefixHostName($config->getKey(Swf2Vid::swf2vidKey . '/player-url', '/static/local/swf/player/player.swf'));
     $project_url = sprintf('%s/%d', HttpUtils::prefixHostName($config->getKey(Swf2Vid::swf2vidKey . '/project-url', '/members/projects/data')), $video->project_id);
     if ($instance = $instances->findAvailable('qPointer')) {
         $recorder_url = sprintf('%s/static/local/swf/converter/converter.swf?recorder=true&player_url=%s&project_url=%s', $host, urlencode($player_url), urlencode($project_url));
         $status_url = sprintf('%s/swf2vid/update/%d', $host, $video->video_id);
         if ($response = $instances->queryInstance($instance, ['cmd' => 'record', 'player_url' => $recorder_url, 'status_url' => $status_url])) {
             $video->vid_status = $response['status'] == 'ok' ? 'processing' : 'fail';
             return $video->save_direct();
         }
     } else {
         $instances->addInstance($urgent);
     }
     return false;
 }