From 60ba21ac03ea927af7e8d1318822468fa759f48a Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Wed, 1 Sep 2010 20:07:05 +0100 Subject: [PATCH] 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. --- lib/RippingCluster/Job.class.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/RippingCluster/Job.class.php b/lib/RippingCluster/Job.class.php index c2c08f0..f0687c1 100644 --- a/lib/RippingCluster/Job.class.php +++ b/lib/RippingCluster/Job.class.php @@ -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() {