2 Commits

Author SHA1 Message Date
47946bcf98 Update handbrake backend to rip to temp dir 2011-08-07 15:40:17 +01:00
d2b2dc7925 Add output filesize to jobs summary page 2011-08-06 23:11:15 +01:00
4 changed files with 46 additions and 11 deletions

View File

@@ -30,11 +30,14 @@ class Net_Gearman_Job_HandBrake extends Net_Gearman_Job_Common implements Rippin
$this->job = RippingCluster_Job::fromId($args['rip_options']['id']); $this->job = RippingCluster_Job::fromId($args['rip_options']['id']);
// Substitute a temporary output filename into the rip options
$args['temp_output_filename'] = tempnam($config->get('rips.temp_dir', '/tmp'), 'hbr_');
$handbrake_cmd_raw = array( $handbrake_cmd_raw = array(
'-n', $config->get('rips.nice'), '-n', $config->get('rips.nice'),
$config->get('rips.handbrake_binary'), $config->get('rips.handbrake_binary'),
self::evaluateOption($args['rip_options'], 'input_filename', '-i'), self::evaluateOption($args['rip_options'], 'input_filename', '-i'),
self::evaluateOption($args['rip_options'], 'output_filename', '-o'), self::evaluateOption($args, 'temp_output_filename', '-o'),
self::evaluateOption($args['rip_options'], 'title'), self::evaluateOption($args['rip_options'], 'title'),
self::evaluateOption($args['rip_options'], 'format', '-f'), self::evaluateOption($args['rip_options'], 'format', '-f'),
self::evaluateOption($args['rip_options'], 'video_codec', '-e'), self::evaluateOption($args['rip_options'], 'video_codec', '-e'),
@@ -61,12 +64,24 @@ class Net_Gearman_Job_HandBrake extends Net_Gearman_Job_Common implements Rippin
list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this); list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this);
if ($return_val) { if ($return_val) {
// Remove any temporary output files
if (file_exists($args['temp_output_filename'])) {
unlink($args['temp_output_filename']);
}
$this->fail($return_val); $this->fail($return_val);
} else { } else {
$this->job->updateStatus(RippingCluster_JobStatus::COMPLETE); // Move the temporary output file to the desired destination
$this->complete( array( $move = rename($args['temp_output_filename'], $args['rip_options']['output_filename']);
'id' => $this->job->id() if ($move) {
)); $this->job->updateStatus(RippingCluster_JobStatus::COMPLETE);
$this->complete( array(
'id' => $this->job->id()
));
} else {
RippingCluster_WorkerLogEntry::error($log, $this->job->id(), "Failed to move temporary output file to proper destination. File retained as '{$args['temp_output_filename']}'.");
$this->job->updateStatus(RippingCluster_JobStatus::FAILED);
$this->fail('-1');
}
} }
} }

View File

@@ -272,6 +272,19 @@ class RippingCluster_Job {
return $new_status; return $new_status;
} }
public function isFinished() {
$current_status = $this->currentStatus()->status();
return ($current_status == RippingCluster_JobStatus::COMPLETE || $current_status == RippingCluster_JobStatus::FAILED);
}
public function outputFilesize() {
if (file_exists($this->destination_filename)) {
return filesize($this->destination_filename);
}
return null;
}
public function calculateETA() { public function calculateETA() {
$current_status = $this->currentStatus(); $current_status = $this->currentStatus();
if ($current_status->status() != RippingCluster_JobStatus::RUNNING) { if ($current_status->status() != RippingCluster_JobStatus::RUNNING) {

View File

@@ -18,13 +18,15 @@ class RippingCluster_Main extends SihnonFramework_Main {
switch (HBC_File) { switch (HBC_File) {
case 'index': { case 'index': {
$smarty_tmp = '/tmp/ripping-cluster';
$this->smarty = new Smarty(); $this->smarty = new Smarty();
$this->smarty->template_dir = './source/templates'; $this->smarty->template_dir = static::makeAbsolutePath('./source/templates');
$this->smarty->compile_dir = './tmp/templates'; $this->smarty->compile_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/templates');
$this->smarty->cache_dir = './tmp/cache'; $this->smarty->cache_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/cache');
$this->smarty->config_dir = './config'; $this->smarty->config_dir = static::makeAbsolutePath($smarty_tmp . '/config');
$this->smarty->registerPlugin('modifier', 'formatDuration', array('RippingCluster_Main', 'formatDuration')); $this->smarty->registerPlugin('modifier', 'formatDuration', array('RippingCluster_Main', 'formatDuration'));
$this->smarty->registerPlugin('modifier', 'formatFilesize', array('RippingCluster_Main', 'formatFilesize'));
$this->smarty->assign('version', '0.1'); $this->smarty->assign('version', '0.1');
$this->smarty->assign('messages', array()); $this->smarty->assign('messages', array());

View File

@@ -43,7 +43,12 @@
{assign var=current_status value=$job->currentStatus()} {assign var=current_status value=$job->currentStatus()}
<tr> <tr>
<td><a href="{$base_uri}job-details/id/{$job->id()}" title="View job details">{$job->name()}</a></td> <td><a href="{$base_uri}job-details/id/{$job->id()}" title="View job details">{$job->name()}</a></td>
<td>{$job->destinationFilename()}</td> <td>
{$job->destinationFilename()}
{if $job->isFinished()}
({$job->outputFilesize()|formatFilesize})
{/if}
</td>
<td>{$job->title()}</td> <td>{$job->title()}</td>
<td> <td>
{$current_status->statusName()} {$current_status->statusName()}