Compare commits
12 Commits
release-0.
...
release-0.
| Author | SHA1 | Date | |
|---|---|---|---|
| 8d2ca716df | |||
| 47946bcf98 | |||
| d2b2dc7925 | |||
| e84c1eba42 | |||
| b93efc9878 | |||
| 9697654594 | |||
| 5121f78cea | |||
| dbc1252bef | |||
| a3e58e4ee4 | |||
| 3b22b0f2c9 | |||
| efb7db35d8 | |||
| 841a5b9f92 |
@@ -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']);
|
||||
|
||||
// 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(
|
||||
'-n', $config->get('rips.nice'),
|
||||
$config->get('rips.handbrake_binary'),
|
||||
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'], 'format', '-f'),
|
||||
self::evaluateOption($args['rip_options'], 'video_codec', '-e'),
|
||||
@@ -61,12 +64,34 @@ 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);
|
||||
if ($return_val) {
|
||||
// Remove any temporary output files
|
||||
if (file_exists($args['temp_output_filename'])) {
|
||||
$result = unlink($args['temp_output_filename']);
|
||||
if ($result) {
|
||||
RippingCluster_WorkerLogEntry::warning($log, $this->job->id(), "Failed to remove temporary output file, still exists at '{$args['temp_output_filename']}'.");
|
||||
}
|
||||
}
|
||||
$this->fail($return_val);
|
||||
} else {
|
||||
// Copy the temporary output file to the desired destination
|
||||
$move = copy($args['temp_output_filename'], $args['rip_options']['output_filename']);
|
||||
if ($move) {
|
||||
// Remove the temporary output file
|
||||
$result = unlink($args['temp_output_filename']);
|
||||
if ($result) {
|
||||
RippingCluster_WorkerLogEntry::warning($log, $this->job->id(), "Failed to remove temporary output file, still exists at '{$args['temp_output_filename']}'.");
|
||||
}
|
||||
|
||||
//Report success
|
||||
$this->job->updateStatus(RippingCluster_JobStatus::COMPLETE);
|
||||
$this->complete( array(
|
||||
'id' => $this->job->id()
|
||||
));
|
||||
} else {
|
||||
RippingCluster_WorkerLogEntry::error($log, $this->job->id(), "Failed to copy temporary output file to proper destination. File retained as '{$args['temp_output_filename']}'.");
|
||||
$this->job->updateStatus(RippingCluster_JobStatus::FAILED);
|
||||
$this->fail('-1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -272,6 +272,19 @@ class RippingCluster_Job {
|
||||
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() {
|
||||
$current_status = $this->currentStatus();
|
||||
if ($current_status->status() != RippingCluster_JobStatus::RUNNING) {
|
||||
|
||||
@@ -4,12 +4,20 @@ class RippingCluster_LogEntry extends SihnonFramework_LogEntry {
|
||||
|
||||
protected $job_id;
|
||||
|
||||
protected static $types;
|
||||
|
||||
public static function initialise() {
|
||||
self::$types['job_id'] = 'int';
|
||||
// Copy the list of datatypes from the parent
|
||||
// We can't modify it in place, else we'll break any logging done inside the SihnonFramework tree
|
||||
// or other subclass trees.
|
||||
static::$types = parent::$types;
|
||||
|
||||
// Add the new data types for this subclass
|
||||
static::$types['job_id'] = 'int';
|
||||
}
|
||||
|
||||
protected function __construct($level, $category, $ctime, $pid, $file, $line, $message, $job_id) {
|
||||
parent::__construct($level, $category, $ctime, $pid, $file, $line, $message);
|
||||
protected function __construct($level, $category, $ctime, $hostname, $progname, $pid, $file, $line, $message, $job_id) {
|
||||
parent::__construct($level, $category, $ctime, $hostname, $progname, $pid, $file, $line, $message);
|
||||
|
||||
$this->job_id = $job_id;
|
||||
}
|
||||
@@ -19,6 +27,8 @@ class RippingCluster_LogEntry extends SihnonFramework_LogEntry {
|
||||
$row['level'],
|
||||
$row['category'],
|
||||
$row['ctime'],
|
||||
$row['hostname'],
|
||||
$row['progname'],
|
||||
$row['pid'],
|
||||
$row['file'],
|
||||
$row['line'],
|
||||
@@ -32,8 +42,8 @@ class RippingCluster_LogEntry extends SihnonFramework_LogEntry {
|
||||
$this->level,
|
||||
$this->category,
|
||||
$this->ctime,
|
||||
static::$hostname,
|
||||
static::$progname,
|
||||
$this->hostname,
|
||||
$this->progname,
|
||||
$this->pid,
|
||||
$this->file,
|
||||
$this->line,
|
||||
@@ -48,7 +58,7 @@ class RippingCluster_LogEntry extends SihnonFramework_LogEntry {
|
||||
|
||||
protected static function log($logger, $severity, $job_id, $message, $category = SihnonFramework_Log::CATEGORY_DEFAULT) {
|
||||
$backtrace = debug_backtrace(false);
|
||||
$entry = new self($severity, $category, time(), getmypid(), $backtrace[1]['file'], $backtrace[1]['line'], $message, $job_id);
|
||||
$entry = new self($severity, $category, time(), static::$localHostname, static::$localProgname, getmypid(), $backtrace[1]['file'], $backtrace[1]['line'], $message, $job_id);
|
||||
|
||||
$logger->log($entry);
|
||||
}
|
||||
|
||||
@@ -16,19 +16,24 @@ class RippingCluster_Main extends SihnonFramework_Main {
|
||||
|
||||
$this->request = new RippingCluster_RequestParser($request_string);
|
||||
|
||||
if (HBC_File == 'index') {
|
||||
switch (HBC_File) {
|
||||
case 'index': {
|
||||
$smarty_tmp = '/tmp/ripping-cluster';
|
||||
$this->smarty = new Smarty();
|
||||
$this->smarty->template_dir = './source/templates';
|
||||
$this->smarty->compile_dir = './tmp/templates';
|
||||
$this->smarty->cache_dir = './tmp/cache';
|
||||
$this->smarty->config_dir = './config';
|
||||
$this->smarty->template_dir = static::makeAbsolutePath('./source/templates');
|
||||
$this->smarty->compile_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/templates');
|
||||
$this->smarty->cache_dir = static::makeAbsolutePath($smarty_tmp . '/tmp/cache');
|
||||
$this->smarty->config_dir = static::makeAbsolutePath($smarty_tmp . '/config');
|
||||
|
||||
$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('messages', array());
|
||||
|
||||
$this->smarty->assign('base_uri', $this->base_uri);
|
||||
} break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
require_once '/etc/ripping-cluster/config.php';
|
||||
require_once RippingCluster_Lib . 'RippingCluster/Main.class.php';
|
||||
require_once SihnonFramework_Lib . 'SihnonFramework/Main.class.php';
|
||||
|
||||
RippingCluster_Main::registerAutoloadClasses('SihnonFramework', SihnonFramework_Lib,
|
||||
SihnonFramework_Main::registerAutoloadClasses('SihnonFramework', SihnonFramework_Lib,
|
||||
'RippingCluster', RippingCluster_Lib);
|
||||
|
||||
?>
|
||||
|
||||
@@ -6,6 +6,7 @@ require '_inc.php';
|
||||
|
||||
try {
|
||||
$main = RippingCluster_Main::instance();
|
||||
RippingCluster_LogEntry::setLocalProgname('webui');
|
||||
$smarty = $main->smarty();
|
||||
|
||||
$page = new RippingCluster_Page($smarty, $main->request());
|
||||
|
||||
@@ -43,7 +43,12 @@
|
||||
{assign var=current_status value=$job->currentStatus()}
|
||||
<tr>
|
||||
<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>
|
||||
{$current_status->statusName()}
|
||||
|
||||
@@ -2,7 +2,17 @@
|
||||
|
||||
define('HBC_File', 'worker');
|
||||
|
||||
require_once '/etc/ripping-cluster/config.php';
|
||||
$options = array();
|
||||
if (isset($_SERVER['argv'])) {
|
||||
$options = getopt('c:', array('config:'));
|
||||
}
|
||||
|
||||
if (isset($options['config'])) {
|
||||
require_once $options['config'];
|
||||
} else {
|
||||
require_once '/etc/ripping-cluster/config.php';
|
||||
}
|
||||
|
||||
require_once(SihnonFramework_Lib . 'SihnonFramework/Main.class.php');
|
||||
require_once 'Net/Gearman/Worker.php';
|
||||
|
||||
@@ -16,6 +26,7 @@ try {
|
||||
set_time_limit(0);
|
||||
|
||||
$main = RippingCluster_Main::instance();
|
||||
RippingCluster_LogEntry::setLocalProgname('ripping-cluster-worker');
|
||||
$smarty = $main->smarty();
|
||||
|
||||
$worker = new RippingCluster_Worker();
|
||||
|
||||
Reference in New Issue
Block a user