public static function commonInit($project, $type) { PasoJob::where('project_id', '=', $project->id)->where('type', '=', $type)->delete(); $job = new PasoJob(); $job->type = $type; $job->project_id = $project->id; $job->percentage = 0; $job->save(); $project->status = $type; $project->save(); return $job; }
public function handle() { $job = PasoJob::commonInit($this->project, 'fetching'); $todo = 0; foreach ($this->project->files as $f) { if ($f->status == 'fetching') { $todo++; } } if ($todo != 0) { $step = ceil(100 / $todo); foreach ($this->project->files as $f) { if ($f->fetchToLocal() == false) { $job->setError('Unable to fetch file ' . $f->original_path); break; } $job->percentage += $step; $job->save(); } } $job->percentage = 100; $job->save(); $this->project = $this->project->fresh(); if ($this->project->status != 'failed') { $this->dispatch(new RenderJob($this->project)); } }
public function handle() { $job = PasoJob::commonInit($this->project, 'rendering'); /* melt writes progresses on stderr, so I have to open a pipe on that channel. A simple popen() opens only stdout */ $command = sprintf('%s %s/config.mlt -consumer avformat:%s/output.%s %s -progress', Conf::read('melt_path'), $this->project->folder(), $this->project->folder(), $this->project->extension, $this->project->render_string); $descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w")); $process = proc_open($command, $descriptorspec, $pipes); if (is_resource($process)) { while (!feof($pipes[2])) { $buffer = fread($pipes[2], 500); preg_match('/percentage: *([0-9]{1,2})/', $buffer, $matches); if (count($matches) == 2) { $job->percentage = $matches[1]; $job->save(); } /* TODO: intercept errors from melt */ } } $job->percentage = 100; $job->save(); $this->project = $this->project->fresh(); if ($this->project->status != 'failed') { $this->project->status = 'ready'; $this->project->save(); } }
public function handle() { $job = PasoJob::commonInit($this->project, 'testing'); $f = $this->project->folder() . '/config.mlt'; $c = file_get_contents($f); $xml = new \SimpleXMLElement($c); if ($xml == null) { $job->setError('Unable to read the XML file'); return; } else { $root_node = $xml->xpath('//mlt[@root]'); $root_folder = $root_node[0]->attributes()['root']; $files1 = $xml->xpath('//property[@name="resource"]'); $files2 = $xml->xpath('//kdenlive_producer[@resource]'); $files3 = $xml->xpath('//metaproperty[@name="meta.attr.url"]'); $step = ceil(100 / (count($files1) + count($files2) + count($files3))); foreach ($files1 as $f) { if ($this->handleFile($root_folder, $f) == false) { $job->setError('Unable to retrieve file ' . $f); } $job->percentage += $step; $job->save(); } foreach ($files2 as $f) { $resource = $f->attributes()['resource']; if ($this->handleFile($root_folder, $resource) == false) { $job->setError('Unable to retrieve file ' . $resource); } $job->percentage += $step; $job->save(); } foreach ($files3 as $f) { if ($this->handleFile($root_folder, $f) == false) { $job->setError('Unable to retrieve file ' . $f); } $job->percentage += $step; $job->save(); } } $job->percentage = 100; $job->save(); $this->project = $this->project->fresh(); if ($this->project->status != 'failed') { $this->dispatch(new FetchJob($this->project)); } }