mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-24 17:25:13 +00:00
Merge branch 'dev' into 'master'
Update for PHP7.4 compatibility + PHPUnit 9 See merge request idanoo/php-resque!2
This commit is contained in:
commit
ebec2f7bf7
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# Install git (the php image doesn't have it) which is required by composer
|
# Install git (the php image doesn't have it) which is required by composer
|
||||||
apt-get update -yq
|
apt-get update -yq
|
||||||
apt-get install git wget procps -y
|
apt-get install git wget procps unzip -y
|
||||||
|
|
||||||
# Install pcntl and redis extentions
|
# Install pcntl and redis extentions
|
||||||
pecl install -o -f redis \
|
pecl install -o -f redis \
|
||||||
@ -17,55 +17,17 @@
|
|||||||
|
|
||||||
# Install Composer
|
# Install Composer
|
||||||
wget https://getcomposer.org/composer.phar
|
wget https://getcomposer.org/composer.phar
|
||||||
php composer.phar install
|
php composer.phar install --dev
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- redis:latest
|
- redis:latest
|
||||||
|
|
||||||
# Test PHP 7.0
|
# Test PHP 7.4
|
||||||
test:7.0:
|
test:7.4:
|
||||||
image: php:7.0
|
image: php:7.4
|
||||||
before_script:
|
before_script:
|
||||||
- *docker_boostrap
|
- *docker_boostrap
|
||||||
script:
|
script:
|
||||||
- curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-6.5.9.phar
|
- php vendor/bin/phpunit --verbose --configuration phpunit.xml.dist
|
||||||
- chmod +x /usr/local/bin/phpunit
|
|
||||||
- phpunit --verbose --configuration phpunit.xml.dist
|
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
|
||||||
# Test PHP 7.1
|
|
||||||
test:7.1:
|
|
||||||
image: php:7.1
|
|
||||||
before_script:
|
|
||||||
- *docker_boostrap
|
|
||||||
script:
|
|
||||||
- curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-7.5.9.phar
|
|
||||||
- chmod +x /usr/local/bin/phpunit
|
|
||||||
- phpunit --verbose --configuration phpunit.xml.dist
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
# Test PHP 7.2
|
|
||||||
test:7.2:
|
|
||||||
image: php:7.2
|
|
||||||
before_script:
|
|
||||||
- *docker_boostrap
|
|
||||||
script:
|
|
||||||
- curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit-7.5.9.phar
|
|
||||||
- chmod +x /usr/local/bin/phpunit
|
|
||||||
- phpunit --verbose --configuration phpunit.xml.dist
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
# Test PHP 7.3
|
|
||||||
test:7.3:
|
|
||||||
image: php:7.3
|
|
||||||
before_script:
|
|
||||||
- *docker_boostrap
|
|
||||||
script:
|
|
||||||
- curl --location --output /usr/local/bin/phpunit https://phar.phpunit.de/phpunit.phar
|
|
||||||
- chmod +x /usr/local/bin/phpunit
|
|
||||||
- phpunit --verbose --configuration phpunit.xml.dist
|
|
||||||
tags:
|
|
||||||
- docker
|
|
@ -1,3 +1,7 @@
|
|||||||
|
## 1.4.7 (2020-04-11)
|
||||||
|
- Update PHPUnit to 9
|
||||||
|
- Start adding return types
|
||||||
|
|
||||||
## 1.4.6 (2020-01-10)
|
## 1.4.6 (2020-01-10)
|
||||||
- Switched IF Statement order to prevent excess calls to redis.
|
- Switched IF Statement order to prevent excess calls to redis.
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "idanoo/php-resque",
|
"name": "idanoo/php-resque",
|
||||||
"version": "1.4.6",
|
"version": "1.4.7",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"replace": {
|
"replace": {
|
||||||
"chrisboulton/php-resque": "*",
|
"chrisboulton/php-resque": "*",
|
||||||
"danhunsaker/php-resque": "*"
|
"danhunsaker/php-resque": "*"
|
||||||
},
|
},
|
||||||
"description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby. Originally forked from chrisboulton/php-resque.",
|
"description": "Redis backed library for creating background jobs and processing them later. Based on resque for Ruby. Originally forked from chrisboulton/php-resque.",
|
||||||
"keywords": ["job", "background", "redis", "resque"],
|
"keywords": ["job", "background", "redis", "resque", "php"],
|
||||||
"homepage": "http://www.github.com/idanoo/php-resque/",
|
"homepage": "http://www.github.com/idanoo/php-resque/",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -24,7 +24,7 @@
|
|||||||
"colinmollenhour/credis": "^1.10"
|
"colinmollenhour/credis": "^1.10"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^6"
|
"phpunit/phpunit": "^9"
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
"bin/resque"
|
"bin/resque"
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
class Resque
|
class Resque
|
||||||
{
|
{
|
||||||
const VERSION = '1.4.6';
|
const VERSION = '1.4.7';
|
||||||
|
|
||||||
const DEFAULT_INTERVAL = 5;
|
const DEFAULT_INTERVAL = 5;
|
||||||
|
|
||||||
@ -51,6 +51,7 @@ class Resque
|
|||||||
* Return an instance of the Resque_Redis class instantiated for Resque.
|
* Return an instance of the Resque_Redis class instantiated for Resque.
|
||||||
*
|
*
|
||||||
* @return Resque_Redis Instance of Resque_Redis.
|
* @return Resque_Redis Instance of Resque_Redis.
|
||||||
|
*
|
||||||
* @throws Resque_RedisException
|
* @throws Resque_RedisException
|
||||||
*/
|
*/
|
||||||
public static function redis()
|
public static function redis()
|
||||||
@ -101,9 +102,10 @@ 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
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function push($queue, $item)
|
public static function push($queue, $item): bool
|
||||||
{
|
{
|
||||||
$encodedItem = json_encode($item);
|
$encodedItem = json_encode($item);
|
||||||
if ($encodedItem === false) {
|
if ($encodedItem === false) {
|
||||||
@ -122,6 +124,7 @@ 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 mixed Decoded item from the queue.
|
* @return mixed Decoded item from the queue.
|
||||||
*/
|
*/
|
||||||
public static function pop($queue)
|
public static function pop($queue)
|
||||||
@ -142,7 +145,7 @@ class Resque
|
|||||||
* @param array $items
|
* @param array $items
|
||||||
* @return integer number of deleted items
|
* @return integer number of deleted items
|
||||||
*/
|
*/
|
||||||
public static function dequeue($queue, $items = Array())
|
public static function dequeue($queue, $items = [])
|
||||||
{
|
{
|
||||||
if (count($items) > 0) {
|
if (count($items) > 0) {
|
||||||
return self::removeItems($queue, $items);
|
return self::removeItems($queue, $items);
|
||||||
@ -155,13 +158,14 @@ class Resque
|
|||||||
* Remove specified queue
|
* Remove specified queue
|
||||||
*
|
*
|
||||||
* @param string $queue The name of the queue to remove.
|
* @param string $queue The name of the queue to remove.
|
||||||
* @return integer Number of deleted items
|
*
|
||||||
|
* @return int Number of deleted items
|
||||||
*/
|
*/
|
||||||
public static function removeQueue($queue)
|
public static function removeQueue($queue): int
|
||||||
{
|
{
|
||||||
$num = self::removeList($queue);
|
$num = self::removeList($queue);
|
||||||
self::redis()->srem('queues', $queue);
|
self::redis()->srem('queues', $queue);
|
||||||
return $num;
|
return intval($num);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -170,12 +174,13 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @param array $queues
|
* @param array $queues
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
|
*
|
||||||
* @return array|null|void
|
* @return array|null|void
|
||||||
*/
|
*/
|
||||||
public static function blpop(array $queues, $timeout)
|
public static function blpop(array $queues, $timeout)
|
||||||
{
|
{
|
||||||
$list = array();
|
$list = array();
|
||||||
foreach ($queues AS $queue) {
|
foreach ($queues as $queue) {
|
||||||
$list[] = 'queue:' . $queue;
|
$list[] = 'queue:' . $queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,10 +197,10 @@ class Resque
|
|||||||
*/
|
*/
|
||||||
$queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
|
$queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
|
||||||
|
|
||||||
return array(
|
return [
|
||||||
'queue' => $queue,
|
'queue' => $queue,
|
||||||
'payload' => json_decode($item[1], true)
|
'payload' => json_decode($item[1], true)
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,9 +210,9 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @return int The size of the queue.
|
* @return int The size of the queue.
|
||||||
*/
|
*/
|
||||||
public static function size($queue)
|
public static function size($queue): int
|
||||||
{
|
{
|
||||||
return self::redis()->llen('queue:' . $queue);
|
return intval(self::redis()->llen('queue:' . $queue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -245,6 +250,7 @@ class Resque
|
|||||||
* Reserve and return the next available job in the specified queue.
|
* Reserve and return the next available job in the specified queue.
|
||||||
*
|
*
|
||||||
* @param string $queue Queue to fetch next available job from.
|
* @param string $queue Queue to fetch next available job from.
|
||||||
|
*
|
||||||
* @return false|object|Resque_Job
|
* @return false|object|Resque_Job
|
||||||
*/
|
*/
|
||||||
public static function reserve($queue)
|
public static function reserve($queue)
|
||||||
@ -257,13 +263,10 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @return array Array of queues.
|
* @return array Array of queues.
|
||||||
*/
|
*/
|
||||||
public static function queues()
|
public static function queues(): array
|
||||||
{
|
{
|
||||||
$queues = self::redis()->smembers('queues');
|
$queues = self::redis()->smembers('queues');
|
||||||
if (!is_array($queues)) {
|
return is_array($queues) ? $queues : [];
|
||||||
$queues = array();
|
|
||||||
}
|
|
||||||
return $queues;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -276,9 +279,10 @@ class Resque
|
|||||||
*
|
*
|
||||||
* @param string $queue The name of the queue
|
* @param string $queue The name of the queue
|
||||||
* @param array $items
|
* @param array $items
|
||||||
* @return integer number of deleted items
|
*
|
||||||
|
* @return int number of deleted items
|
||||||
*/
|
*/
|
||||||
private static function removeItems($queue, $items = Array())
|
private static function removeItems($queue, $items = []): int
|
||||||
{
|
{
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
$originalQueue = 'queue:' . $queue;
|
$originalQueue = 'queue:' . $queue;
|
||||||
|
@ -13,7 +13,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
private $callbacksHit = [];
|
private $callbacksHit = [];
|
||||||
private $worker;
|
private $worker;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
Test_Job::$called = false;
|
Test_Job::$called = false;
|
||||||
|
|
||||||
@ -23,7 +23,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
$this->worker->registerWorker();
|
$this->worker->registerWorker();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
Resque_Event::clearListeners();
|
Resque_Event::clearListeners();
|
||||||
$this->callbacksHit = [];
|
$this->callbacksHit = [];
|
||||||
|
@ -15,7 +15,7 @@ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
protected $worker;
|
protected $worker;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
{
|
{
|
||||||
protected $worker;
|
protected $worker;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
@ -44,7 +44,9 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testObjectArgumentsCannotBePassedToJob()
|
public function testObjectArgumentsCannotBePassedToJob()
|
||||||
{
|
{
|
||||||
$args = new stdClass;
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
|
$args = new stdClass();
|
||||||
$args->test = 'somevalue';
|
$args->test = 'somevalue';
|
||||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||||
}
|
}
|
||||||
@ -121,6 +123,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testJobWithoutPerformMethodThrowsException()
|
public function testJobWithoutPerformMethodThrowsException()
|
||||||
{
|
{
|
||||||
|
$this->expectException(Resque_Exception::class);
|
||||||
Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
|
Resque::enqueue('jobs', 'Test_Job_Without_Perform_Method');
|
||||||
$job = $this->worker->reserve();
|
$job = $this->worker->reserve();
|
||||||
$job->worker = $this->worker;
|
$job->worker = $this->worker;
|
||||||
@ -132,6 +135,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidJobThrowsException()
|
public function testInvalidJobThrowsException()
|
||||||
{
|
{
|
||||||
|
$this->expectException(Resque_Exception::class);
|
||||||
Resque::enqueue('jobs', 'Invalid_Job');
|
Resque::enqueue('jobs', 'Invalid_Job');
|
||||||
$job = $this->worker->reserve();
|
$job = $this->worker->reserve();
|
||||||
$job->worker = $this->worker;
|
$job->worker = $this->worker;
|
||||||
@ -334,7 +338,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
$this->assertEquals($removedItems, 2);
|
$this->assertEquals($removedItems, 2);
|
||||||
$this->assertEquals(Resque::size($queue), 1);
|
$this->assertEquals(Resque::size($queue), 1);
|
||||||
$item = Resque::pop($queue);
|
$item = Resque::pop($queue);
|
||||||
$this->assertInternalType('array', $item['args']);
|
$this->assertIsArray($item['args']);
|
||||||
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
|
$this->assertEquals(10, $item['args'][0]['bar'], 'Wrong items were dequeued from queue!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,12 +181,14 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider bogusDsnStringProvider
|
* @dataProvider bogusDsnStringProvider
|
||||||
|
*
|
||||||
* @expectedException InvalidArgumentException
|
* @expectedException InvalidArgumentException
|
||||||
|
*
|
||||||
* @param $dsn
|
* @param $dsn
|
||||||
*/
|
*/
|
||||||
public function testParsingBogusDsnStringThrowsException($dsn)
|
public function testParsingBogusDsnStringThrowsException($dsn)
|
||||||
{
|
{
|
||||||
// The next line should throw an InvalidArgumentException
|
$this->expectException(InvalidArgumentException::class);
|
||||||
Resque_Redis::parseDsn($dsn);
|
Resque_Redis::parseDsn($dsn);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,12 +13,12 @@ class Resque_Tests_TestCase extends PHPUnit\Framework\TestCase
|
|||||||
protected $resque;
|
protected $resque;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
|
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass(): void
|
||||||
{
|
{
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp()
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
// Setup redis connection for testing.
|
// Setup redis connection for testing.
|
||||||
global $redisTestServer;
|
global $redisTestServer;
|
||||||
|
Loading…
Reference in New Issue
Block a user