From 3798fa3ba676b0728391dacffef9061b4000b69d Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Thu, 9 May 2013 16:27:50 -0600 Subject: [PATCH 1/2] Added enqueue failure detection If a job fails to be enqueued, it would be useful to know it. So now Resque actually tells us whether the enqueue action was successful or if it failed. If your job ID comes back as FALSE, it didn't enqueue. Signed-off-by: Daniel Hunsaker --- lib/Resque.php | 6 +++++- lib/Resque/Job.php | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Resque.php b/lib/Resque.php index fa22ed1..75b8d52 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -98,7 +98,11 @@ class Resque public static function push($queue, $item) { self::redis()->sadd('queues', $queue); - self::redis()->rpush('queue:' . $queue, json_encode($item)); + if (self::redis()->rpush('queue:' . $queue, json_encode($item)) < 1) + { + return FALSE; + } + return TRUE; } /** diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index 82b11bc..fc84e1e 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -58,11 +58,14 @@ class Resque_Job ); } $id = md5(uniqid('', true)); - Resque::push($queue, array( + if ( ! Resque::push($queue, array( 'class' => $class, 'args' => array($args), 'id' => $id, - )); + ))) + { + return FALSE; + } if($monitor) { Resque_Job_Status::create($id); From 8d1a9a55649a9375af93ecff4c209312bbaf67ff Mon Sep 17 00:00:00 2001 From: Daniel Hunsaker Date: Sun, 12 May 2013 12:58:18 -0600 Subject: [PATCH 2/2] Updated to match coding style. Signed-off-by: Daniel Hunsaker --- lib/Resque.php | 8 ++++---- lib/Resque/Job.php | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Resque.php b/lib/Resque.php index 75b8d52..a463bea 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -98,11 +98,11 @@ class Resque public static function push($queue, $item) { self::redis()->sadd('queues', $queue); - if (self::redis()->rpush('queue:' . $queue, json_encode($item)) < 1) - { - return FALSE; + $length = self::redis()->rpush('queue:' . $queue, json_encode($item)); + if ($length < 1) { + return false; } - return TRUE; + return true; } /** diff --git a/lib/Resque/Job.php b/lib/Resque/Job.php index fc84e1e..d2a4e84 100755 --- a/lib/Resque/Job.php +++ b/lib/Resque/Job.php @@ -58,13 +58,12 @@ class Resque_Job ); } $id = md5(uniqid('', true)); - if ( ! Resque::push($queue, array( + if (!Resque::push($queue, array( 'class' => $class, 'args' => array($args), 'id' => $id, - ))) - { - return FALSE; + ))) { + return false; } if($monitor) {