Pass job id with rip options to work around gearman limitation

The Perl version of gearman doesn't support passing the unique value to
the worker, so the job id is now passed in the workload request.
Also fixed a bug to ensure changes to job status are visible
immediately, rather than only on the next page load.
This commit is contained in:
2010-09-01 20:07:05 +01:00
parent c769f40c2a
commit 60ba21ac03

View File

@@ -223,6 +223,7 @@ class RippingCluster_Job {
// Construct the rip options
$rip_options = array(
'id' => $this->id,
'nice' => $config->get('rips.nice', 15),
'input_filename' => $this->source_filename,
'output_filename' => $this->destination_filename,
@@ -240,12 +241,13 @@ class RippingCluster_Job {
);
// Enqueue this rip
if ( ! $this->id) {
throw new RippingCluster_Exception_LogicException("Rip cannot be queued without being saved!");
}
$task = $gearman->addTask('handbrake_rip', serialize($rip_options), $config->get('rips.context'), $this->id);
if ($task) {
$log->debug("Queued job", $this->id);
$this->updateStatus(RippingCluster_JobStatus::QUEUED);
} else {
$log->warning("Failed to queue job", $this->id);
$this->updateStatus(RippingCluster_JobStatus::FAILED);
}
}
@@ -266,7 +268,10 @@ class RippingCluster_Job {
}
public function updateStatus($new_status, $rip_progress = null) {
return RippingCluster_JobStatus::updateStatusForJob($this, $new_status, $rip_progress);
$this->loadStatuses();
$new_status = RippingCluster_JobStatus::updateStatusForJob($this, $new_status, $rip_progress);
$this->statuses[] = $new_status;
return $new_status;
}
public function calculateETA() {