Improvements to Status Handling
Added link to jobs page to fix any issues caused by non-synchronised time between webserver/worker machine leaving jobs permanently in the running state. Prevented the insertion of new status records unless the state is actually being changed. Made the HandBrake worker process write the status complete message instead of the run-jobs dispatched, in case it crashes.
This commit is contained in:
@@ -22,6 +22,10 @@ class RippingCluster_Job {
|
||||
private $audio_names;
|
||||
private $subtitle_tracks;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array(RippingCluster_JobStatus)
|
||||
*/
|
||||
private $statuses = null;
|
||||
|
||||
private static $cache = array();
|
||||
@@ -269,8 +273,13 @@ class RippingCluster_Job {
|
||||
|
||||
public function updateStatus($new_status, $rip_progress = null) {
|
||||
$this->loadStatuses();
|
||||
$new_status = RippingCluster_JobStatus::updateStatusForJob($this, $new_status, $rip_progress);
|
||||
$this->statuses[] = $new_status;
|
||||
|
||||
// Only update the status if the state is changing
|
||||
if ($this->currentStatus()->status() != $new_status) {
|
||||
$new_status = RippingCluster_JobStatus::updateStatusForJob($this, $new_status, $rip_progress);
|
||||
$this->statuses[] = $new_status;
|
||||
}
|
||||
|
||||
return $new_status;
|
||||
}
|
||||
|
||||
@@ -289,7 +298,30 @@ class RippingCluster_Job {
|
||||
|
||||
return $remaining_time;
|
||||
}
|
||||
|
||||
|
||||
public function fixBrokenTimestamps() {
|
||||
$this->loadStatuses();
|
||||
|
||||
// See if we have both a RUNNING and a COMPLETE status set
|
||||
$statuses = array();
|
||||
foreach ($this->statuses as $status) {
|
||||
switch ($status->status()) {
|
||||
case RippingCluster_JobStatus::RUNNING:
|
||||
case RippingCluster_JobStatus::COMPLETE:
|
||||
$statuses[$status->status()] = $status;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($statuses[RippingCluster_JobStatus::RUNNING]) && isset($statuses[RippingCluster_JobStatus::COMPLETE])) {
|
||||
// Ensure the timestamp on the complete is >= that of the running status
|
||||
if ($statuses[RippingCluster_JobStatus::COMPLETE]->mtime() < $statuses[RippingCluster_JobStatus::RUNNING]->mtime()) {
|
||||
$statuses[RippingCluster_JobStatus::COMPLETE]->mtime($statuses[RippingCluster_JobStatus::RUNNING]->mtime() + 1);
|
||||
$statuses[RippingCluster_JobStatus::COMPLETE]->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class RippingCluster_JobStatus {
|
||||
}
|
||||
|
||||
return $statuses;
|
||||
}
|
||||
}
|
||||
|
||||
protected function create() {
|
||||
$database = RippingCluster_Main::instance()->database();
|
||||
@@ -104,11 +104,22 @@ class RippingCluster_JobStatus {
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function hasProgressInfo() {
|
||||
return ($this->status == self::RUNNING);
|
||||
}
|
||||
|
||||
public static function fixBrokenTimestamps() {
|
||||
$statuses = array();
|
||||
|
||||
$database = RippingCluster_Main::instance()->database();
|
||||
foreach ($database->selectList('SELECT * FROM job_status WHERE status=4 AND job_id IN (SELECT job_id FROM job_status WHERE status=3)') as $row) {
|
||||
$status = RippingCluster_JobStatus::fromDatabaseRow($row);
|
||||
$status->mtime = time();
|
||||
$status->save();
|
||||
}
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
@@ -129,7 +140,11 @@ class RippingCluster_JobStatus {
|
||||
return $this->ctime;
|
||||
}
|
||||
|
||||
public function mtime() {
|
||||
public function mtime($new_mtime = null) {
|
||||
if ($new_mtime !== null) {
|
||||
$this->mtime = $new_mtime;
|
||||
}
|
||||
|
||||
return $this->mtime;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,8 @@ class RippingCluster_Worker_Plugin_HandBrake implements RippingCluster_Worker_IP
|
||||
list($return_val, $stdout, $stderr) = RippingCluster_ForegroundTask::execute($handbrake_cmd, null, null, null, array($this, 'callbackOutput'), array($this, 'callbackOutput'), $this);
|
||||
if ($return_val) {
|
||||
$this->gearman_job->sendFail($return_val);
|
||||
} else {
|
||||
$this->job->updateStatus(RippingCluster_JobStatus::COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user