mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-21 16:01:53 +00:00
Passing pipelines
This commit is contained in:
parent
deb9af2781
commit
1b044f2b7d
@ -100,6 +100,7 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @param string $queue The name of the queue to add the job to.
|
* @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.
|
* @param array $item Job description as an array to be JSON encoded.
|
||||||
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function push($queue, $item)
|
public static function push($queue, $item)
|
||||||
{
|
{
|
||||||
@ -120,14 +121,14 @@ class Resque
|
|||||||
* return it.
|
* return it.
|
||||||
*
|
*
|
||||||
* @param string $queue The name of the queue to fetch an item from.
|
* @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)
|
public static function pop($queue)
|
||||||
{
|
{
|
||||||
$item = self::redis()->lpop('queue:' . $queue);
|
$item = self::redis()->lpop('queue:' . $queue);
|
||||||
|
|
||||||
if (!$item) {
|
if (!$item) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return json_decode($item, true);
|
return json_decode($item, true);
|
||||||
|
@ -121,7 +121,6 @@ class Resque_Redis
|
|||||||
} else {
|
} else {
|
||||||
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
||||||
// $user is not used, only $password
|
// $user is not used, only $password
|
||||||
|
|
||||||
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
||||||
|
|
||||||
$this->redisConnection = new Redis();
|
$this->redisConnection = new Redis();
|
||||||
@ -231,6 +230,7 @@ class Resque_Redis
|
|||||||
* @param string $name The name of the method called.
|
* @param string $name The name of the method called.
|
||||||
* @param array $args Array of supplied arguments to the method.
|
* @param array $args Array of supplied arguments to the method.
|
||||||
* @return mixed Return value from Resident::call() based on the command.
|
* @return mixed Return value from Resident::call() based on the command.
|
||||||
|
* @throws Resque_RedisException
|
||||||
*/
|
*/
|
||||||
public function __call($name, $args)
|
public function __call($name, $args)
|
||||||
{
|
{
|
||||||
@ -239,10 +239,16 @@ class Resque_Redis
|
|||||||
foreach ($args[0] AS $i => $v) {
|
foreach ($args[0] AS $i => $v) {
|
||||||
$args[0][$i] = self::$defaultNamespace . $v;
|
$args[0][$i] = self::$defaultNamespace . $v;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
$args[0] = self::$defaultNamespace . $args[0];
|
$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()
|
public static function getPrefix()
|
||||||
|
@ -27,23 +27,6 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
$this->assertTrue((bool)Resque::enqueue('jobs', 'Test_Job'));
|
$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()
|
public function testQeueuedJobCanBeReserved()
|
||||||
{
|
{
|
||||||
Resque::enqueue('jobs', 'Test_Job');
|
Resque::enqueue('jobs', 'Test_Job');
|
||||||
@ -404,20 +387,6 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
$instance = $job->getInstance();
|
$instance = $job->getInstance();
|
||||||
$this->assertInstanceOf('Resque_JobInterface', $instance);
|
$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
|
class Some_Job_Class implements Resque_JobInterface
|
||||||
|
@ -290,6 +290,6 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(2, $i);
|
$this->assertEquals(2, $i, "End");
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user