/** * Avvia un Job in coda * * @param array $params * @param LoggerInterface $logger (optional) * @return bool */ public function run() { $fs = new Filesystem(); $taskId = $this->getParam('taskId'); $taskModel = TaskModel::where('id', '=', $taskId)->firstOrFail(); $this->setLogContext($taskModel->toArray()); $jobModel = $taskModel->job()->first(); $fileModel = $jobModel->files()->first(); //prendi il jobservice col dao del job associato al task settato $job = $taskModel->job()->firstOrFail(); $this->logInfo("Controllo della directory "); $service = new JobService(); $service->setDao($job); $folder = $service->resolveArtifactsPath(); $fsM = SymfonyFileSystemManager::getInstance(); $fsM->createDir($folder, '0700', true); $input = $fileModel->path; $output = $folder . DIRECTORY_SEPARATOR . BinaryFile::resolveName(); //transcoding $transcoder = JambonCoreFactory::getInstance(); $resolution = $this->resolveResolution($taskModel); $taskModel->updateResolution($resolution); $taskModel->setStarted(); $transcoder->initTranscodeOperation($taskModel->format, false, $resolution, 2, $input, $output); $ffprobeInfo = $transcoder->performTranscodeOperation(); $output = $transcoder->getOutputPath(); $taskModel->setCompleted(); $ffprobeInfoArray = @json_decode($ffprobeInfo, true); if (!empty($ffprobeInfoArray)) { //risoluzione del filename in output $fileName = $fileModel->getName(); $vanillaName = pathinfo($fileName, PATHINFO_FILENAME); $extension = pathinfo($output, PATHINFO_EXTENSION); $name = $vanillaName . '_' . $resolution . '.' . $extension; //salvataggio del model file in db $fileModel = FileModel::create($output, FileModel::FILE_ROLE_ARTIFACT, $name); //salvataggio del ffprobe $fileModel->setMeta(FileModel::META_FFPROBE_KEY, $ffprobeInfoArray, true); $fileModel->updateFileHash(); $taskModel->files()->attach($fileModel->id); $taskModel->save(); } else { throw new \Exception("Error Processing transcoding"); } //se non ci sono task aperti chiudo il job //$shouldCloseJob = (TaskModel::where('completed_at', '=', null)->count() === 0); //dump($shouldCloseJob); // if($shouldCloseJob) { // } }
/** * Esegue il QueueJob * * @param array $params * @param LoggerInterface $logger (optional) * @return bool */ public function run() { $jobModel = JobModel::where('id', '=', $this->getParam('jobId'))->firstOrFail(); $service = new JobService(); $service->setDao($jobModel)->resolveSource(false); }