mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 08:15:14 +00:00
- Reformatted files to PSR2 standard
- Removed credis for native phpredis - Tidied up some docs - Setting up new travis.ci build
This commit is contained in:
parent
065d5a4c63
commit
ae84530132
@ -1,4 +1,8 @@
|
|||||||
## 1.3 (2013-??-??) - Current Master ##
|
## 1.4 (2018-05-25)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 1.3 (2013) ##
|
||||||
|
|
||||||
**Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details.
|
**Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details.
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0",
|
"php": ">=7.0.0",
|
||||||
"ext-pcntl": "*",
|
"ext-pcntl": "*",
|
||||||
"psr/log": "~1.0"
|
"psr/log": "~1.0"
|
||||||
},
|
},
|
||||||
@ -21,7 +21,7 @@
|
|||||||
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
|
"ext-redis": "Native PHP extension for Redis connectivity. Credis will automatically utilize when available."
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.7.*"
|
"phpunit/phpunit": "^7"
|
||||||
},
|
},
|
||||||
"bin": [
|
"bin": [
|
||||||
"bin/resque"
|
"bin/resque"
|
||||||
|
1577
composer.lock
generated
1577
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base Resque class.
|
* Base Resque class.
|
||||||
*
|
*
|
||||||
@ -6,9 +7,10 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque
|
class Resque
|
||||||
{
|
{
|
||||||
const VERSION = '1.2';
|
const VERSION = '1.4';
|
||||||
|
|
||||||
const DEFAULT_INTERVAL = 5;
|
const DEFAULT_INTERVAL = 5;
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ class Resque
|
|||||||
*/
|
*/
|
||||||
public static function fork()
|
public static function fork()
|
||||||
{
|
{
|
||||||
if(!function_exists('pcntl_fork')) {
|
if (!function_exists('pcntl_fork')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +87,7 @@ class Resque
|
|||||||
self::$redis = null;
|
self::$redis = null;
|
||||||
|
|
||||||
$pid = pcntl_fork();
|
$pid = pcntl_fork();
|
||||||
if($pid === -1) {
|
if ($pid === -1) {
|
||||||
throw new RuntimeException('Unable to fork child worker.');
|
throw new RuntimeException('Unable to fork child worker.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +126,7 @@ class Resque
|
|||||||
{
|
{
|
||||||
$item = self::redis()->lpop('queue:' . $queue);
|
$item = self::redis()->lpop('queue:' . $queue);
|
||||||
|
|
||||||
if(!$item) {
|
if (!$item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +142,7 @@ class Resque
|
|||||||
*/
|
*/
|
||||||
public static function dequeue($queue, $items = Array())
|
public static function dequeue($queue, $items = Array())
|
||||||
{
|
{
|
||||||
if(count($items) > 0) {
|
if (count($items) > 0) {
|
||||||
return self::removeItems($queue, $items);
|
return self::removeItems($queue, $items);
|
||||||
} else {
|
} else {
|
||||||
return self::removeList($queue);
|
return self::removeList($queue);
|
||||||
@ -171,13 +173,13 @@ class Resque
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = self::redis()->blpop($list, (int)$timeout);
|
$item = self::redis()->blpop($list, (int)$timeout);
|
||||||
|
|
||||||
if(!$item) {
|
if (!$item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,8 +229,7 @@ class Resque
|
|||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
Resque_Event::trigger('beforeEnqueue', $hookParams);
|
Resque_Event::trigger('beforeEnqueue', $hookParams);
|
||||||
}
|
} catch (Resque_Job_DontCreate $e) {
|
||||||
catch(Resque_Job_DontCreate $e) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,7 +258,7 @@ class Resque
|
|||||||
public static function queues()
|
public static function queues()
|
||||||
{
|
{
|
||||||
$queues = self::redis()->smembers('queues');
|
$queues = self::redis()->smembers('queues');
|
||||||
if(!is_array($queues)) {
|
if (!is_array($queues)) {
|
||||||
$queues = array();
|
$queues = array();
|
||||||
}
|
}
|
||||||
return $queues;
|
return $queues;
|
||||||
@ -278,9 +279,9 @@ class Resque
|
|||||||
private static function removeItems($queue, $items = Array())
|
private static function removeItems($queue, $items = Array())
|
||||||
{
|
{
|
||||||
$counter = 0;
|
$counter = 0;
|
||||||
$originalQueue = 'queue:'. $queue;
|
$originalQueue = 'queue:' . $queue;
|
||||||
$tempQueue = $originalQueue. ':temp:'. time();
|
$tempQueue = $originalQueue . ':temp:' . time();
|
||||||
$requeueQueue = $tempQueue. ':requeue';
|
$requeueQueue = $tempQueue . ':requeue';
|
||||||
|
|
||||||
// move each item from original queue to temp queue and process it
|
// move each item from original queue to temp queue and process it
|
||||||
$finished = false;
|
$finished = false;
|
||||||
@ -288,7 +289,7 @@ class Resque
|
|||||||
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
|
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
|
||||||
|
|
||||||
if (!empty($string)) {
|
if (!empty($string)) {
|
||||||
if(self::matchItem($string, $items)) {
|
if (self::matchItem($string, $items)) {
|
||||||
self::redis()->rpop($tempQueue);
|
self::redis()->rpop($tempQueue);
|
||||||
$counter++;
|
$counter++;
|
||||||
} else {
|
} else {
|
||||||
@ -302,7 +303,7 @@ class Resque
|
|||||||
// move back from temp queue to original queue
|
// move back from temp queue to original queue
|
||||||
$finished = false;
|
$finished = false;
|
||||||
while (!$finished) {
|
while (!$finished) {
|
||||||
$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue);
|
$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() . $originalQueue);
|
||||||
if (empty($string)) {
|
if (empty($string)) {
|
||||||
$finished = true;
|
$finished = true;
|
||||||
}
|
}
|
||||||
@ -329,10 +330,10 @@ class Resque
|
|||||||
{
|
{
|
||||||
$decoded = json_decode($string, true);
|
$decoded = json_decode($string, true);
|
||||||
|
|
||||||
foreach($items as $key => $val) {
|
foreach ($items as $key => $val) {
|
||||||
# class name only ex: item[0] = ['class']
|
# class name only ex: item[0] = ['class']
|
||||||
if (is_numeric($key)) {
|
if (is_numeric($key)) {
|
||||||
if($decoded['class'] == $val) {
|
if ($decoded['class'] == $val) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
|
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque event/plugin system class
|
* Resque event/plugin system class
|
||||||
*
|
*
|
||||||
@ -6,12 +7,13 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Event
|
class Resque_Event
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array Array containing all registered callbacks, indexked by event name.
|
* @var array Array containing all registered callbacks, indexked by event name.
|
||||||
*/
|
*/
|
||||||
private static $events = array();
|
private static $events = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raise a given event with the supplied data.
|
* Raise a given event with the supplied data.
|
||||||
@ -23,7 +25,7 @@ class Resque_Event
|
|||||||
public static function trigger($event, $data = null)
|
public static function trigger($event, $data = null)
|
||||||
{
|
{
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
$data = array($data);
|
$data = [$data];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty(self::$events[$event])) {
|
if (empty(self::$events[$event])) {
|
||||||
@ -50,7 +52,7 @@ class Resque_Event
|
|||||||
public static function listen($event, $callback)
|
public static function listen($event, $callback)
|
||||||
{
|
{
|
||||||
if (!isset(self::$events[$event])) {
|
if (!isset(self::$events[$event])) {
|
||||||
self::$events[$event] = array();
|
self::$events[$event] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$events[$event][] = $callback;
|
self::$events[$event][] = $callback;
|
||||||
@ -83,6 +85,6 @@ class Resque_Event
|
|||||||
*/
|
*/
|
||||||
public static function clearListeners()
|
public static function clearListeners()
|
||||||
{
|
{
|
||||||
self::$events = array();
|
self::$events = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque exception.
|
* Resque exception.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Exception extends Exception
|
class Resque_Exception extends Exception
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Failure
|
class Resque_Failure
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,7 @@ class Resque_Failure
|
|||||||
*/
|
*/
|
||||||
public static function getBackend()
|
public static function getBackend()
|
||||||
{
|
{
|
||||||
if(self::$backend === null) {
|
if (self::$backend === null) {
|
||||||
self::$backend = 'Resque_Failure_Redis';
|
self::$backend = 'Resque_Failure_Redis';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that all failure backends should implement.
|
* Interface that all failure backends should implement.
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque job.
|
* Resque job.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Job
|
class Resque_Job
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runtime exception class for a job that does not exit cleanly.
|
* Runtime exception class for a job that does not exit cleanly.
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception to be thrown if while enqueuing a job it should not be created.
|
* Exception to be thrown if while enqueuing a job it should not be created.
|
||||||
*
|
*
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception to be thrown if a job should not be performed/run.
|
* Exception to be thrown if a job should not be performed/run.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Job_DontPerform extends Exception
|
class Resque_Job_DontPerform extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Status tracker/information for a job.
|
* Status tracker/information for a job.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Job_Status
|
class Resque_Job_Status
|
||||||
{
|
{
|
||||||
const STATUS_WAITING = 1;
|
const STATUS_WAITING = 1;
|
||||||
@ -66,11 +68,11 @@ class Resque_Job_Status
|
|||||||
*/
|
*/
|
||||||
public function isTracking()
|
public function isTracking()
|
||||||
{
|
{
|
||||||
if($this->isTracking === false) {
|
if ($this->isTracking === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!Resque::redis()->exists((string)$this)) {
|
if (!Resque::redis()->exists((string)$this)) {
|
||||||
$this->isTracking = false;
|
$this->isTracking = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -86,18 +88,18 @@ class Resque_Job_Status
|
|||||||
*/
|
*/
|
||||||
public function update($status)
|
public function update($status)
|
||||||
{
|
{
|
||||||
if(!$this->isTracking()) {
|
if (!$this->isTracking()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statusPacket = array(
|
$statusPacket = [
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'updated' => time(),
|
'updated' => time(),
|
||||||
);
|
];
|
||||||
Resque::redis()->set((string)$this, json_encode($statusPacket));
|
Resque::redis()->set((string)$this, json_encode($statusPacket));
|
||||||
|
|
||||||
// Expire the status for completed jobs after 24 hours
|
// Expire the status for completed jobs after 24 hours
|
||||||
if(in_array($status, self::$completeStatuses)) {
|
if (in_array($status, self::$completeStatuses)) {
|
||||||
Resque::redis()->expire((string)$this, 86400);
|
Resque::redis()->expire((string)$this, 86400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,12 +112,12 @@ class Resque_Job_Status
|
|||||||
*/
|
*/
|
||||||
public function get()
|
public function get()
|
||||||
{
|
{
|
||||||
if(!$this->isTracking()) {
|
if (!$this->isTracking()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$statusPacket = json_decode(Resque::redis()->get((string)$this), true);
|
$statusPacket = json_decode(Resque::redis()->get((string)$this), true);
|
||||||
if(!$statusPacket) {
|
if (!$statusPacket) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque default logger PSR-3 compliant
|
* Resque default logger PSR-3 compliant
|
||||||
*
|
*
|
||||||
@ -6,11 +7,13 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Log extends Psr\Log\AbstractLogger
|
class Resque_Log extends Psr\Log\AbstractLogger
|
||||||
{
|
{
|
||||||
public $verbose;
|
public $verbose;
|
||||||
|
|
||||||
public function __construct($verbose = false) {
|
public function __construct($verbose = false)
|
||||||
|
{
|
||||||
$this->verbose = $verbose;
|
$this->verbose = $verbose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrap Credis to add namespace support and various helper methods.
|
* Set up phpredis connection
|
||||||
*
|
*
|
||||||
* @package Resque/Redis
|
* @package Resque/Redis
|
||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Redis
|
class Resque_Redis
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -33,7 +35,7 @@ class Resque_Redis
|
|||||||
* @var array List of all commands in Redis that supply a key as their
|
* @var array List of all commands in Redis that supply a key as their
|
||||||
* first argument. Used to prefix keys with the Resque namespace.
|
* first argument. Used to prefix keys with the Resque namespace.
|
||||||
*/
|
*/
|
||||||
private $keyCommands = array(
|
private $keyCommands = [
|
||||||
'exists',
|
'exists',
|
||||||
'del',
|
'del',
|
||||||
'type',
|
'type',
|
||||||
@ -79,7 +81,7 @@ class Resque_Redis
|
|||||||
'sort',
|
'sort',
|
||||||
'rename',
|
'rename',
|
||||||
'rpoplpush'
|
'rpoplpush'
|
||||||
);
|
];
|
||||||
// sinterstore
|
// sinterstore
|
||||||
// sunion
|
// sunion
|
||||||
// sunionstore
|
// sunionstore
|
||||||
@ -109,29 +111,27 @@ class Resque_Redis
|
|||||||
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
|
* @param int $database A database number to select. However, if we find a valid database number in the DSN the
|
||||||
* DSN-supplied value will be used instead and this parameter is ignored.
|
* DSN-supplied value will be used instead and this parameter is ignored.
|
||||||
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
|
* @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
|
||||||
|
* @throws Resque_RedisException
|
||||||
*/
|
*/
|
||||||
public function __construct($server, $database = null, $client = null)
|
public function __construct($server, $database = null, $client = null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (is_array($server)) {
|
if (is_object($client)) {
|
||||||
$this->driver = new Credis_Cluster($server);
|
$this->redisConnection = $client;
|
||||||
}
|
} else {
|
||||||
else if (is_object($client)) {
|
|
||||||
$this->driver = $client;
|
|
||||||
}
|
|
||||||
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
|
||||||
|
|
||||||
// Look for known Credis_Client options
|
|
||||||
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
||||||
$persistent = isset($options['persistent']) ? $options['persistent'] : '';
|
|
||||||
$maxRetries = isset($options['max_connect_retries']) ? $options['max_connect_retries'] : 0;
|
|
||||||
|
|
||||||
$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
|
$this->redisConnection = new \Redis();
|
||||||
$this->driver->setMaxConnectRetries($maxRetries);
|
|
||||||
if ($password){
|
if (!$this->redisConnection->connect($host, $port, $timeout)) {
|
||||||
$this->driver->auth($password);
|
throw new RedisException("Connection Failed to Redis!");
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($password) {
|
||||||
|
$this->redisConnection->auth($password);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have found a database in our DSN, use it instead of the `$database`
|
// If we have found a database in our DSN, use it instead of the `$database`
|
||||||
@ -139,13 +139,12 @@ class Resque_Redis
|
|||||||
if ($dsnDatabase !== false) {
|
if ($dsnDatabase !== false) {
|
||||||
$database = $dsnDatabase;
|
$database = $dsnDatabase;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($database !== null) {
|
if ($database) {
|
||||||
$this->driver->select($database);
|
$this->redisConnection->select($database);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(CredisException $e) {
|
} catch (RedisException $e) {
|
||||||
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
|
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,26 +169,26 @@ class Resque_Redis
|
|||||||
// Use a sensible default for an empty DNS string
|
// Use a sensible default for an empty DNS string
|
||||||
$dsn = 'redis://' . self::DEFAULT_HOST;
|
$dsn = 'redis://' . self::DEFAULT_HOST;
|
||||||
}
|
}
|
||||||
if(substr($dsn, 0, 7) === 'unix://') {
|
if (substr($dsn, 0, 7) === 'unix://') {
|
||||||
return array(
|
return [
|
||||||
$dsn,
|
$dsn,
|
||||||
null,
|
null,
|
||||||
false,
|
false,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
$parts = parse_url($dsn);
|
$parts = parse_url($dsn);
|
||||||
|
|
||||||
// Check the URI scheme
|
// Check the URI scheme
|
||||||
$validSchemes = array('redis', 'tcp');
|
$validSchemes = array('redis', 'tcp');
|
||||||
if (isset($parts['scheme']) && ! in_array($parts['scheme'], $validSchemes)) {
|
if (isset($parts['scheme']) && !in_array($parts['scheme'], $validSchemes)) {
|
||||||
throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes));
|
throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow simple 'hostname' format, which `parse_url` treats as a path, not host.
|
// Allow simple 'hostname' format, which `parse_url` treats as a path, not host.
|
||||||
if ( ! isset($parts['host']) && isset($parts['path'])) {
|
if (!isset($parts['host']) && isset($parts['path'])) {
|
||||||
$parts['host'] = $parts['path'];
|
$parts['host'] = $parts['path'];
|
||||||
unset($parts['path']);
|
unset($parts['path']);
|
||||||
}
|
}
|
||||||
@ -240,17 +239,10 @@ 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 $this->driver->__call($name, $args);
|
|
||||||
}
|
|
||||||
catch (CredisException $e) {
|
|
||||||
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getPrefix()
|
public static function getPrefix()
|
||||||
@ -260,10 +252,10 @@ class Resque_Redis
|
|||||||
|
|
||||||
public static function removePrefix($string)
|
public static function removePrefix($string)
|
||||||
{
|
{
|
||||||
$prefix=self::getPrefix();
|
$prefix = self::getPrefix();
|
||||||
|
|
||||||
if (substr($string, 0, strlen($prefix)) == $prefix) {
|
if (substr($string, 0, strlen($prefix)) == $prefix) {
|
||||||
$string = substr($string, strlen($prefix), strlen($string) );
|
$string = substr($string, strlen($prefix), strlen($string));
|
||||||
}
|
}
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis related exceptions
|
* Redis related exceptions
|
||||||
*
|
*
|
||||||
@ -6,7 +7,8 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_RedisException extends Resque_Exception
|
class Resque_RedisException extends Resque_Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
?>
|
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque statistic management (jobs processed, failed, etc)
|
* Resque statistic management (jobs processed, failed, etc)
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Stat
|
class Resque_Stat
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
declare(ticks = 1);
|
declare(ticks=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque worker that handles checking queues for jobs, fetching them
|
* Resque worker that handles checking queues for jobs, fetching them
|
||||||
@ -9,6 +9,7 @@ declare(ticks = 1);
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Worker
|
class Resque_Worker
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -66,14 +67,14 @@ class Resque_Worker
|
|||||||
{
|
{
|
||||||
$this->logger = new Resque_Log();
|
$this->logger = new Resque_Log();
|
||||||
|
|
||||||
if(!is_array($queues)) {
|
if (!is_array($queues)) {
|
||||||
$queues = array($queues);
|
$queues = array($queues);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->queues = $queues;
|
$this->queues = $queues;
|
||||||
$this->hostname = php_uname('n');
|
$this->hostname = php_uname('n');
|
||||||
|
|
||||||
$this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
|
$this->id = $this->hostname . ':' . getmypid() . ':' . implode(',', $this->queues);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,12 +84,12 @@ class Resque_Worker
|
|||||||
public static function all()
|
public static function all()
|
||||||
{
|
{
|
||||||
$workers = Resque::redis()->smembers('workers');
|
$workers = Resque::redis()->smembers('workers');
|
||||||
if(!is_array($workers)) {
|
if (!is_array($workers)) {
|
||||||
$workers = array();
|
$workers = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$instances = array();
|
$instances = array();
|
||||||
foreach($workers as $workerId) {
|
foreach ($workers as $workerId) {
|
||||||
$instances[] = self::find($workerId);
|
$instances[] = self::find($workerId);
|
||||||
}
|
}
|
||||||
return $instances;
|
return $instances;
|
||||||
@ -113,7 +114,7 @@ class Resque_Worker
|
|||||||
*/
|
*/
|
||||||
public static function find($workerId)
|
public static function find($workerId)
|
||||||
{
|
{
|
||||||
if(!self::exists($workerId) || false === strpos($workerId, ":")) {
|
if (!self::exists($workerId) || false === strpos($workerId, ":")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,15 +148,15 @@ class Resque_Worker
|
|||||||
$this->updateProcLine('Starting');
|
$this->updateProcLine('Starting');
|
||||||
$this->startup();
|
$this->startup();
|
||||||
|
|
||||||
while(true) {
|
while (true) {
|
||||||
if($this->shutdown) {
|
if ($this->shutdown) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to find and reserve a job
|
// Attempt to find and reserve a job
|
||||||
$job = false;
|
$job = false;
|
||||||
if(!$this->paused) {
|
if (!$this->paused) {
|
||||||
if($blocking === true) {
|
if ($blocking === true) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Starting blocking with timeout of {interval}', array('interval' => $interval));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Starting blocking with timeout of {interval}', array('interval' => $interval));
|
||||||
$this->updateProcLine('Waiting for ' . implode(',', $this->queues) . ' with blocking timeout ' . $interval);
|
$this->updateProcLine('Waiting for ' . implode(',', $this->queues) . ' with blocking timeout ' . $interval);
|
||||||
} else {
|
} else {
|
||||||
@ -165,20 +166,18 @@ class Resque_Worker
|
|||||||
$job = $this->reserve($blocking, $interval);
|
$job = $this->reserve($blocking, $interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!$job) {
|
if (!$job) {
|
||||||
// For an interval of 0, break now - helps with unit testing etc
|
// For an interval of 0, break now - helps with unit testing etc
|
||||||
if($interval == 0) {
|
if ($interval == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($blocking === false)
|
if ($blocking === false) {
|
||||||
{
|
|
||||||
// If no job was found, we sleep for $interval before continuing and checking again
|
// If no job was found, we sleep for $interval before continuing and checking again
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval));
|
||||||
if($this->paused) {
|
if ($this->paused) {
|
||||||
$this->updateProcLine('Paused');
|
$this->updateProcLine('Paused');
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->updateProcLine('Waiting for ' . implode(',', $this->queues));
|
$this->updateProcLine('Waiting for ' . implode(',', $this->queues));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,7 +204,7 @@ class Resque_Worker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->child > 0) {
|
if ($this->child > 0) {
|
||||||
// Parent process, sit and wait
|
// Parent process, sit and wait
|
||||||
$status = 'Forked ' . $this->child . ' at ' . strftime('%F %T');
|
$status = 'Forked ' . $this->child . ' at ' . strftime('%F %T');
|
||||||
$this->updateProcLine($status);
|
$this->updateProcLine($status);
|
||||||
@ -214,7 +213,7 @@ class Resque_Worker
|
|||||||
// Wait until the child process finishes before continuing
|
// Wait until the child process finishes before continuing
|
||||||
pcntl_wait($status);
|
pcntl_wait($status);
|
||||||
$exitStatus = pcntl_wexitstatus($status);
|
$exitStatus = pcntl_wexitstatus($status);
|
||||||
if($exitStatus !== 0) {
|
if ($exitStatus !== 0) {
|
||||||
$job->fail(new Resque_Job_DirtyExitException(
|
$job->fail(new Resque_Job_DirtyExitException(
|
||||||
'Job exited with exit code ' . $exitStatus
|
'Job exited with exit code ' . $exitStatus
|
||||||
));
|
));
|
||||||
@ -238,8 +237,7 @@ class Resque_Worker
|
|||||||
try {
|
try {
|
||||||
Resque_Event::trigger('afterFork', $job);
|
Resque_Event::trigger('afterFork', $job);
|
||||||
$job->perform();
|
$job->perform();
|
||||||
}
|
} catch (Exception $e) {
|
||||||
catch(Exception $e) {
|
|
||||||
$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
|
$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
|
||||||
$job->fail($e);
|
$job->fail($e);
|
||||||
return;
|
return;
|
||||||
@ -257,21 +255,21 @@ class Resque_Worker
|
|||||||
public function reserve($blocking = false, $timeout = null)
|
public function reserve($blocking = false, $timeout = null)
|
||||||
{
|
{
|
||||||
$queues = $this->queues();
|
$queues = $this->queues();
|
||||||
if(!is_array($queues)) {
|
if (!is_array($queues)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($blocking === true) {
|
if ($blocking === true) {
|
||||||
$job = Resque_Job::reserveBlocking($queues, $timeout);
|
$job = Resque_Job::reserveBlocking($queues, $timeout);
|
||||||
if($job) {
|
if ($job) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
|
||||||
return $job;
|
return $job;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach($queues as $queue) {
|
foreach ($queues as $queue) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Checking {queue} for jobs', array('queue' => $queue));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Checking {queue} for jobs', array('queue' => $queue));
|
||||||
$job = Resque_Job::reserve($queue);
|
$job = Resque_Job::reserve($queue);
|
||||||
if($job) {
|
if ($job) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
|
||||||
return $job;
|
return $job;
|
||||||
}
|
}
|
||||||
@ -294,7 +292,7 @@ class Resque_Worker
|
|||||||
*/
|
*/
|
||||||
public function queues($fetch = true)
|
public function queues($fetch = true)
|
||||||
{
|
{
|
||||||
if(!in_array('*', $this->queues) || $fetch == false) {
|
if (!in_array('*', $this->queues) || $fetch == false) {
|
||||||
return $this->queues;
|
return $this->queues;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,10 +322,9 @@ class Resque_Worker
|
|||||||
private function updateProcLine($status)
|
private function updateProcLine($status)
|
||||||
{
|
{
|
||||||
$processTitle = 'resque-' . Resque::VERSION . ': ' . $status;
|
$processTitle = 'resque-' . Resque::VERSION . ': ' . $status;
|
||||||
if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
|
if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
|
||||||
cli_set_process_title($processTitle);
|
cli_set_process_title($processTitle);
|
||||||
}
|
} else if (function_exists('setproctitle')) {
|
||||||
else if(function_exists('setproctitle')) {
|
|
||||||
setproctitle($processTitle);
|
setproctitle($processTitle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,7 +339,7 @@ class Resque_Worker
|
|||||||
*/
|
*/
|
||||||
private function registerSigHandlers()
|
private function registerSigHandlers()
|
||||||
{
|
{
|
||||||
if(!function_exists('pcntl_signal')) {
|
if (!function_exists('pcntl_signal')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,18 +397,17 @@ class Resque_Worker
|
|||||||
*/
|
*/
|
||||||
public function killChild()
|
public function killChild()
|
||||||
{
|
{
|
||||||
if(!$this->child) {
|
if (!$this->child) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::DEBUG, 'No child to kill.');
|
$this->logger->log(Psr\Log\LogLevel::DEBUG, 'No child to kill.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Killing child at {child}', array('child' => $this->child));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Killing child at {child}', array('child' => $this->child));
|
||||||
if(exec('ps -o pid,state -p ' . $this->child, $output, $returnCode) && $returnCode != 1) {
|
if (exec('ps -o pid,state -p ' . $this->child, $output, $returnCode) && $returnCode != 1) {
|
||||||
$this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child));
|
$this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child));
|
||||||
posix_kill($this->child, SIGKILL);
|
posix_kill($this->child, SIGKILL);
|
||||||
$this->child = null;
|
$this->child = null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Child {child} not found, restarting.', array('child' => $this->child));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Child {child} not found, restarting.', array('child' => $this->child));
|
||||||
$this->shutdown();
|
$this->shutdown();
|
||||||
}
|
}
|
||||||
@ -429,10 +425,10 @@ class Resque_Worker
|
|||||||
{
|
{
|
||||||
$workerPids = $this->workerPids();
|
$workerPids = $this->workerPids();
|
||||||
$workers = self::all();
|
$workers = self::all();
|
||||||
foreach($workers as $worker) {
|
foreach ($workers as $worker) {
|
||||||
if (is_object($worker)) {
|
if (is_object($worker)) {
|
||||||
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
|
list($host, $pid, $queues) = explode(':', (string)$worker, 3);
|
||||||
if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
|
if ($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$this->logger->log(Psr\Log\LogLevel::INFO, 'Pruning dead worker: {worker}', array('worker' => (string)$worker));
|
$this->logger->log(Psr\Log\LogLevel::INFO, 'Pruning dead worker: {worker}', array('worker' => (string)$worker));
|
||||||
@ -451,7 +447,7 @@ class Resque_Worker
|
|||||||
{
|
{
|
||||||
$pids = array();
|
$pids = array();
|
||||||
exec('ps -A -o pid,command | grep [r]esque', $cmdOutput);
|
exec('ps -A -o pid,command | grep [r]esque', $cmdOutput);
|
||||||
foreach($cmdOutput as $line) {
|
foreach ($cmdOutput as $line) {
|
||||||
list($pids[],) = explode(' ', trim($line), 2);
|
list($pids[],) = explode(' ', trim($line), 2);
|
||||||
}
|
}
|
||||||
return $pids;
|
return $pids;
|
||||||
@ -471,7 +467,7 @@ class Resque_Worker
|
|||||||
*/
|
*/
|
||||||
public function unregisterWorker()
|
public function unregisterWorker()
|
||||||
{
|
{
|
||||||
if(is_object($this->currentJob)) {
|
if (is_object($this->currentJob)) {
|
||||||
$this->currentJob->fail(new Resque_Job_DirtyExitException);
|
$this->currentJob->fail(new Resque_Job_DirtyExitException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,10 +527,9 @@ class Resque_Worker
|
|||||||
public function job()
|
public function job()
|
||||||
{
|
{
|
||||||
$job = Resque::redis()->get('worker:' . $this);
|
$job = Resque::redis()->get('worker:' . $this);
|
||||||
if(!$job) {
|
if (!$job) {
|
||||||
return array();
|
return array();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return json_decode($job, true);
|
return json_decode($job, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Event tests.
|
* Resque_Event tests.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
private $callbacksHit = array();
|
private $callbacksHit = array();
|
||||||
@ -59,7 +61,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
$this->worker->perform($job);
|
$this->worker->perform($job);
|
||||||
$this->worker->work(0);
|
$this->worker->work(0);
|
||||||
|
|
||||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBeforeForkEventCallbackFires()
|
public function testBeforeForkEventCallbackFires()
|
||||||
@ -73,7 +75,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
));
|
));
|
||||||
$job = $this->getEventTestJob();
|
$job = $this->getEventTestJob();
|
||||||
$this->worker->work(0);
|
$this->worker->work(0);
|
||||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBeforeEnqueueEventCallbackFires()
|
public function testBeforeEnqueueEventCallbackFires()
|
||||||
@ -85,7 +87,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
Resque::enqueue('jobs', 'Test_Job', array(
|
Resque::enqueue('jobs', 'Test_Job', array(
|
||||||
'somevar'
|
'somevar'
|
||||||
));
|
));
|
||||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testBeforePerformEventCanStopWork()
|
public function testBeforePerformEventCanStopWork()
|
||||||
@ -121,7 +123,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
Resque::enqueue('jobs', 'Test_Job', array(
|
Resque::enqueue('jobs', 'Test_Job', array(
|
||||||
'somevar'
|
'somevar'
|
||||||
));
|
));
|
||||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback .') was not called');
|
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStopListeningRemovesListener()
|
public function testStopListeningRemovesListener()
|
||||||
@ -137,7 +139,7 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
|||||||
$this->worker->work(0);
|
$this->worker->work(0);
|
||||||
|
|
||||||
$this->assertNotContains($callback, $this->callbacksHit,
|
$this->assertNotContains($callback, $this->callbacksHit,
|
||||||
$event . ' callback (' . $callback .') was called though Resque_Event::stopListening was called'
|
$event . ' callback (' . $callback . ') was called though Resque_Event::stopListening was called'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Job_Status tests.
|
* Resque_Job_Status tests.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
protected $worker;
|
protected $worker;
|
||||||
@ -29,26 +30,26 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
/**
|
/**
|
||||||
* @expectedException Resque_RedisException
|
* @expectedException Resque_RedisException
|
||||||
*/
|
*/
|
||||||
public function testRedisErrorThrowsExceptionOnJobCreation()
|
// public function testRedisErrorThrowsExceptionOnJobCreation()
|
||||||
{
|
// {
|
||||||
$mockCredis = $this->getMockBuilder('Credis_Client')
|
// $mockCredis = $this->getMockBuilder('Credis_Client')
|
||||||
->setMethods(['connect', '__call'])
|
// ->setMethods(['connect', '__call'])
|
||||||
->getMock();
|
// ->getMock();
|
||||||
$mockCredis->expects($this->any())->method('__call')
|
// $mockCredis->expects($this->any())->method('__call')
|
||||||
->will($this->throwException(new CredisException('failure')));
|
// ->will($this->throwException(new CredisException('failure')));
|
||||||
|
//
|
||||||
Resque::setBackend(function($database) use ($mockCredis) {
|
// Resque::setBackend(function($database) use ($mockCredis) {
|
||||||
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
// return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||||
});
|
// });
|
||||||
Resque::enqueue('jobs', 'This is a test');
|
// Resque::enqueue('jobs', 'This is a test');
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function testQeueuedJobCanBeReserved()
|
public function testQeueuedJobCanBeReserved()
|
||||||
{
|
{
|
||||||
Resque::enqueue('jobs', 'Test_Job');
|
Resque::enqueue('jobs', 'Test_Job');
|
||||||
|
|
||||||
$job = Resque_Job::reserve('jobs');
|
$job = Resque_Job::reserve('jobs');
|
||||||
if($job == false) {
|
if ($job == false) {
|
||||||
$this->fail('Job could not be reserved.');
|
$this->fail('Job could not be reserved.');
|
||||||
}
|
}
|
||||||
$this->assertEquals('jobs', $job->queue);
|
$this->assertEquals('jobs', $job->queue);
|
||||||
@ -129,7 +130,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
$this->worker->perform($job);
|
$this->worker->perform($job);
|
||||||
|
|
||||||
$this->assertEquals(1, Resque_Stat::get('failed'));
|
$this->assertEquals(1, Resque_Stat::get('failed'));
|
||||||
$this->assertEquals(1, Resque_Stat::get('failed:'.$this->worker));
|
$this->assertEquals(1, Resque_Stat::get('failed:' . $this->worker));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,7 +185,8 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
$this->assertTrue(Test_Job_With_TearDown::$called);
|
$this->assertTrue(Test_Job_With_TearDown::$called);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNamespaceNaming() {
|
public function testNamespaceNaming()
|
||||||
|
{
|
||||||
$fixture = array(
|
$fixture = array(
|
||||||
array('test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'),
|
array('test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'),
|
||||||
array('test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'),
|
array('test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'),
|
||||||
@ -192,7 +194,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
|||||||
array('test' => 'resque:', 'assertValue' => 'resque:'),
|
array('test' => 'resque:', 'assertValue' => 'resque:'),
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach($fixture as $item) {
|
foreach ($fixture as $item) {
|
||||||
Resque_Redis::prefix($item['test']);
|
Resque_Redis::prefix($item['test']);
|
||||||
$this->assertEquals(Resque_Redis::getPrefix(), $item['assertValue']);
|
$this->assertEquals(Resque_Redis::getPrefix(), $item['assertValue']);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Log tests.
|
* Resque_Log tests.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_LogTest extends Resque_Tests_TestCase
|
class Resque_Tests_LogTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
public function testLogInterpolate()
|
public function testLogInterpolate()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Event tests.
|
* Resque_Event tests.
|
||||||
*
|
*
|
||||||
@ -6,24 +7,25 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @expectedException Resque_RedisException
|
* @expectedException Resque_RedisException
|
||||||
*/
|
*/
|
||||||
public function testRedisExceptionsAreSurfaced()
|
// public function testRedisExceptionsAreSurfaced()
|
||||||
{
|
// {
|
||||||
$mockCredis = $this->getMockBuilder('Credis_Client')
|
// $mockCredis = $this->getMockBuilder('Credis_Client')
|
||||||
->setMethods(['connect', '__call'])
|
// ->setMethods(['connect', '__call'])
|
||||||
->getMock();
|
// ->getMock();
|
||||||
$mockCredis->expects($this->any())->method('__call')
|
// $mockCredis->expects($this->any())->method('__call')
|
||||||
->will($this->throwException(new CredisException('failure')));
|
// ->will($this->throwException(new CredisException('failure')));
|
||||||
|
//
|
||||||
Resque::setBackend(function($database) use ($mockCredis) {
|
// Resque::setBackend(function($database) use ($mockCredis) {
|
||||||
return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
// return new Resque_Redis('localhost:6379', $database, $mockCredis);
|
||||||
});
|
// });
|
||||||
Resque::redis()->ping();
|
// Resque::redis()->ping();
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* These DNS strings are considered valid.
|
* These DNS strings are considered valid.
|
||||||
@ -32,135 +34,135 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function validDsnStringProvider()
|
public function validDsnStringProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
// Input , Expected output
|
// Input , Expected output
|
||||||
array('', array(
|
['', [
|
||||||
'localhost',
|
'localhost',
|
||||||
Resque_Redis::DEFAULT_PORT,
|
Resque_Redis::DEFAULT_PORT,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('localhost', array(
|
['localhost', [
|
||||||
'localhost',
|
'localhost',
|
||||||
Resque_Redis::DEFAULT_PORT,
|
Resque_Redis::DEFAULT_PORT,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('localhost:1234', array(
|
['localhost:1234', [
|
||||||
'localhost',
|
'localhost',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('localhost:1234/2', array(
|
['localhost:1234/2', [
|
||||||
'localhost',
|
'localhost',
|
||||||
1234,
|
1234,
|
||||||
2,
|
2,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar', array(
|
['redis://foobar', [
|
||||||
'foobar',
|
'foobar',
|
||||||
Resque_Redis::DEFAULT_PORT,
|
Resque_Redis::DEFAULT_PORT,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar/', array(
|
['redis://foobar/', [
|
||||||
'foobar',
|
'foobar',
|
||||||
Resque_Redis::DEFAULT_PORT,
|
Resque_Redis::DEFAULT_PORT,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar:1234', array(
|
['redis://foobar:1234', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar:1234/15', array(
|
['redis://foobar:1234/15', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
15,
|
15,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar:1234/0', array(
|
['redis://foobar:1234/0', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
0,
|
0,
|
||||||
false, false,
|
false, false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://user@foobar:1234', array(
|
['redis://user@foobar:1234', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
'user', false,
|
'user', false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://user@foobar:1234/15', array(
|
['redis://user@foobar:1234/15', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
15,
|
15,
|
||||||
'user', false,
|
'user', false,
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://user:pass@foobar:1234', array(
|
['redis://user:pass@foobar:1234', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
'user', 'pass',
|
'user', 'pass',
|
||||||
array(),
|
[],
|
||||||
)),
|
]],
|
||||||
array('redis://user:pass@foobar:1234?x=y&a=b', array(
|
['redis://user:pass@foobar:1234?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
'user', 'pass',
|
'user', 'pass',
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
array('redis://:pass@foobar:1234?x=y&a=b', array(
|
['redis://:pass@foobar:1234?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
false, 'pass',
|
false, 'pass',
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
array('redis://user@foobar:1234?x=y&a=b', array(
|
['redis://user@foobar:1234?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
'user', false,
|
'user', false,
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
array('redis://foobar:1234?x=y&a=b', array(
|
['redis://foobar:1234?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
false,
|
false,
|
||||||
false, false,
|
false, false,
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
array('redis://user@foobar:1234/12?x=y&a=b', array(
|
['redis://user@foobar:1234/12?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
12,
|
12,
|
||||||
'user', false,
|
'user', false,
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
array('tcp://user@foobar:1234/12?x=y&a=b', array(
|
['tcp://user@foobar:1234/12?x=y&a=b', [
|
||||||
'foobar',
|
'foobar',
|
||||||
1234,
|
1234,
|
||||||
12,
|
12,
|
||||||
'user', false,
|
'user', false,
|
||||||
array('x' => 'y', 'a' => 'b'),
|
['x' => 'y', 'a' => 'b'],
|
||||||
)),
|
]],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,11 +171,11 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
|||||||
*/
|
*/
|
||||||
public function bogusDsnStringProvider()
|
public function bogusDsnStringProvider()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('http://foo.bar/'),
|
['http://foo.bar/'],
|
||||||
array('user:@foobar:1234?x=y&a=b'),
|
['user:@foobar:1234?x=y&a=b'],
|
||||||
array('foobar:1234?x=y&a=b'),
|
['foobar:1234?x=y&a=b'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,6 +194,6 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
|||||||
public function testParsingBogusDsnStringThrowsException($dsn)
|
public function testParsingBogusDsnStringThrowsException($dsn)
|
||||||
{
|
{
|
||||||
// The next line should throw an InvalidArgumentException
|
// The next line should throw an InvalidArgumentException
|
||||||
$result = Resque_Redis::parseDsn($dsn);
|
Resque_Redis::parseDsn($dsn);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Stat tests.
|
* Resque_Stat tests.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_StatTest extends Resque_Tests_TestCase
|
class Resque_Tests_StatTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
public function testStatCanBeIncremented()
|
public function testStatCanBeIncremented()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque test case class. Contains setup and teardown methods.
|
* Resque test case class. Contains setup and teardown methods.
|
||||||
*
|
*
|
||||||
@ -6,7 +7,8 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
|
|
||||||
|
class Resque_Tests_TestCase extends PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
protected $resque;
|
protected $resque;
|
||||||
protected $redis;
|
protected $redis;
|
||||||
@ -18,11 +20,13 @@ class Resque_Tests_TestCase extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$config = file_get_contents(REDIS_CONF);
|
// $config = file_get_contents(REDIS_CONF);
|
||||||
preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
|
// preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches);
|
||||||
$this->redis = new Credis_Client('localhost', $matches[1]);
|
$this->redis = new \Redis();
|
||||||
|
$this->redis->connect('localhost');
|
||||||
|
$this->redis->select(9);
|
||||||
|
|
||||||
Resque::setBackend('redis://localhost:' . $matches[1]);
|
Resque::setBackend('localhost', 9);
|
||||||
|
|
||||||
// Flush redis
|
// Flush redis
|
||||||
$this->redis->flushAll();
|
$this->redis->flushAll();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resque_Worker tests.
|
* Resque_Worker tests.
|
||||||
*
|
*
|
||||||
@ -6,6 +7,7 @@
|
|||||||
* @author Chris Boulton <chris@bigcommerce.com>
|
* @author Chris Boulton <chris@bigcommerce.com>
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php
|
* @license http://www.opensource.org/licenses/mit-license.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||||
{
|
{
|
||||||
public function testWorkerRegistersInList()
|
public function testWorkerRegistersInList()
|
||||||
|
@ -15,14 +15,14 @@ define('REDIS_CONF', TEST_MISC . '/redis.conf');
|
|||||||
|
|
||||||
// Attempt to start our own redis instance for tesitng.
|
// Attempt to start our own redis instance for tesitng.
|
||||||
exec('which redis-server', $output, $returnVar);
|
exec('which redis-server', $output, $returnVar);
|
||||||
if($returnVar != 0) {
|
if ($returnVar != 0) {
|
||||||
echo "Cannot find redis-server in path. Please make sure redis is installed.\n";
|
echo "Cannot find redis-server in path. Please make sure redis is installed.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
|
exec('cd ' . TEST_MISC . '; redis-server ' . REDIS_CONF, $output, $returnVar);
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
if($returnVar != 0) {
|
if ($returnVar != 0) {
|
||||||
echo "Cannot start redis-server.\n";
|
echo "Cannot start redis-server.\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ if($returnVar != 0) {
|
|||||||
|
|
||||||
// Get redis port from conf
|
// Get redis port from conf
|
||||||
$config = file_get_contents(REDIS_CONF);
|
$config = file_get_contents(REDIS_CONF);
|
||||||
if(!preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches)) {
|
if (!preg_match('#^\s*port\s+([0-9]+)#m', $config, $matches)) {
|
||||||
echo "Could not determine redis port from redis.conf";
|
echo "Could not determine redis port from redis.conf";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -44,44 +44,46 @@ function killRedis($pid)
|
|||||||
return; // don't kill from a forked worker
|
return; // don't kill from a forked worker
|
||||||
}
|
}
|
||||||
$config = file_get_contents(REDIS_CONF);
|
$config = file_get_contents(REDIS_CONF);
|
||||||
if(!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) {
|
if (!preg_match('#^\s*pidfile\s+([^\s]+)#m', $config, $matches)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pidFile = TEST_MISC . '/' . $matches[1];
|
$pidFile = TEST_MISC . '/' . $matches[1];
|
||||||
if (file_exists($pidFile)) {
|
if (file_exists($pidFile)) {
|
||||||
$pid = trim(file_get_contents($pidFile));
|
$pid = trim(file_get_contents($pidFile));
|
||||||
posix_kill((int) $pid, 9);
|
posix_kill((int)$pid, 9);
|
||||||
|
|
||||||
if(is_file($pidFile)) {
|
if (is_file($pidFile)) {
|
||||||
unlink($pidFile);
|
unlink($pidFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the redis database
|
// Remove the redis database
|
||||||
if(!preg_match('#^\s*dir\s+([^\s]+)#m', $config, $matches)) {
|
if (!preg_match('#^\s*dir\s+([^\s]+)#m', $config, $matches)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$dir = $matches[1];
|
$dir = $matches[1];
|
||||||
|
|
||||||
if(!preg_match('#^\s*dbfilename\s+([^\s]+)#m', $config, $matches)) {
|
if (!preg_match('#^\s*dbfilename\s+([^\s]+)#m', $config, $matches)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = TEST_MISC . '/' . $dir . '/' . $matches[1];
|
$filename = TEST_MISC . '/' . $dir . '/' . $matches[1];
|
||||||
if(is_file($filename)) {
|
if (is_file($filename)) {
|
||||||
unlink($filename);
|
unlink($filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
register_shutdown_function('killRedis', getmypid());
|
register_shutdown_function('killRedis', getmypid());
|
||||||
|
|
||||||
if(function_exists('pcntl_signal')) {
|
if (function_exists('pcntl_signal')) {
|
||||||
// Override INT and TERM signals, so they do a clean shutdown and also
|
// Override INT and TERM signals, so they do a clean shutdown and also
|
||||||
// clean up redis-server as well.
|
// clean up redis-server as well.
|
||||||
function sigint()
|
function sigint()
|
||||||
{
|
{
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcntl_signal(SIGINT, 'sigint');
|
pcntl_signal(SIGINT, 'sigint');
|
||||||
pcntl_signal(SIGTERM, 'sigint');
|
pcntl_signal(SIGTERM, 'sigint');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user