From 1b044f2b7dc7bac689081263f5c960671fe8e7de Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Fri, 25 May 2018 20:52:20 +1200 Subject: [PATCH] Passing pipelines --- lib/Resque.php | 5 +++-- lib/Resque/Redis.php | 10 ++++++++-- test/Resque/Tests/JobTest.php | 31 ------------------------------- test/Resque/Tests/WorkerTest.php | 2 +- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/lib/Resque.php b/lib/Resque.php index b01c898..c5d176b 100644 --- a/lib/Resque.php +++ b/lib/Resque.php @@ -100,6 +100,7 @@ class Resque * * @param string $queue The name of the queue to add the job to. * @param array $item Job description as an array to be JSON encoded. + * @return bool */ public static function push($queue, $item) { @@ -120,14 +121,14 @@ class Resque * return it. * * @param string $queue The name of the queue to fetch an item from. - * @return array Decoded item from the queue. + * @return mixed Decoded item from the queue. */ public static function pop($queue) { $item = self::redis()->lpop('queue:' . $queue); if (!$item) { - return; + return false; } return json_decode($item, true); diff --git a/lib/Resque/Redis.php b/lib/Resque/Redis.php index 083f408..f07739e 100644 --- a/lib/Resque/Redis.php +++ b/lib/Resque/Redis.php @@ -121,7 +121,6 @@ class Resque_Redis } else { list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server); // $user is not used, only $password - $timeout = isset($options['timeout']) ? intval($options['timeout']) : null; $this->redisConnection = new Redis(); @@ -231,6 +230,7 @@ class Resque_Redis * @param string $name The name of the method called. * @param array $args Array of supplied arguments to the method. * @return mixed Return value from Resident::call() based on the command. + * @throws Resque_RedisException */ public function __call($name, $args) { @@ -239,10 +239,16 @@ class Resque_Redis foreach ($args[0] AS $i => $v) { $args[0][$i] = self::$defaultNamespace . $v; } - } else { + } + else { $args[0] = self::$defaultNamespace . $args[0]; } } + try { + return call_user_func_array(array($this->redisConnection, $name), $args); + } catch (Exception $e) { + throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e); + } } public static function getPrefix() diff --git a/test/Resque/Tests/JobTest.php b/test/Resque/Tests/JobTest.php index b692b03..18d9674 100644 --- a/test/Resque/Tests/JobTest.php +++ b/test/Resque/Tests/JobTest.php @@ -27,23 +27,6 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase $this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job')); } - /** - * @expectedException Resque_RedisException - */ -// public function testRedisErrorThrowsExceptionOnJobCreation() -// { -// $mockCredis = $this->getMockBuilder('Credis_Client') -// ->setMethods(['connect', '__call']) -// ->getMock(); -// $mockCredis->expects($this->any())->method('__call') -// ->will($this->throwException(new CredisException('failure'))); -// -// Resque::setBackend(function($database) use ($mockCredis) { -// return new Resque_Redis('localhost:6379', $database, $mockCredis); -// }); -// Resque::enqueue('jobs', 'This is a test'); -// } - public function testQeueuedJobCanBeReserved() { Resque::enqueue('jobs', 'Test_Job'); @@ -404,20 +387,6 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase $instance = $job->getInstance(); $this->assertInstanceOf('Resque_JobInterface', $instance); } - - public function testDoNotUseFactoryToGetInstance() - { - $payload = array( - 'class' => 'Some_Job_Class', - 'args' => array(array()) - ); - $job = new Resque_Job('jobs', $payload); - $factory = $this->getMock('Resque_Job_FactoryInterface'); - $testJob = $this->getMock('Resque_JobInterface'); - $factory->expects(self::never())->method('create')->will(self::returnValue($testJob)); - $instance = $job->getInstance(); - $this->assertInstanceOf('Resque_JobInterface', $instance); - } } class Some_Job_Class implements Resque_JobInterface diff --git a/test/Resque/Tests/WorkerTest.php b/test/Resque/Tests/WorkerTest.php index 0090277..2604c5d 100644 --- a/test/Resque/Tests/WorkerTest.php +++ b/test/Resque/Tests/WorkerTest.php @@ -290,6 +290,6 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase $i++; } - $this->assertEquals(2, $i); + $this->assertEquals(2, $i, "End"); } } \ No newline at end of file