mirror of
https://github.com/idanoo/php-resque.git
synced 2024-11-22 00:11:53 +00:00
Added 48 hour TTL to worker:xxx:started keys to prevent db pollution
This commit is contained in:
parent
b235fce1bd
commit
493d6dc6d8
@ -2,14 +2,16 @@
|
||||
- Updated travis builds to run on PHP 7.0, 7.1 and 7.2.
|
||||
- Added ability to specify multiple log levels. [DEBUG/INFO/NOTICE/WARNING/ERROR/CRITICAL/ALERT/EMERGENCY]
|
||||
- Default `LOGLEVEL` is now `WARNING`.
|
||||
- Removed VERBOSE / VVERBOSE flags.
|
||||
- Enabled date/time logging by default.
|
||||
- Removed VERBOSE / VVERBOSE flags and always output timestamp in logs.
|
||||
- Added 48 hour TTL to the worker started timestamp to prevent db pollution on server termination.
|
||||
|
||||
## 1.4 (2018-05-25)
|
||||
- Forked from chrisboulton/php-resque.
|
||||
- Replaced credis (rather unmaintained) in favour of phpredis.
|
||||
- Reformatted codebase to be PSR2 compliant.
|
||||
|
||||
## 1.3 (2013) ##
|
||||
|
||||
## 1.3 (2013)
|
||||
|
||||
**Note:** This release introduces backwards incompatible changes with all previous versions of php-resque. Please see below for details.
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
<!--suppress PhingDomInspection -->
|
||||
<project name="php-resque" default="build">
|
||||
<target name="clean">
|
||||
<delete dir="${basedir}/build" />
|
||||
@ -7,7 +8,7 @@
|
||||
<mkdir dir="${basedir}/build/logs" />
|
||||
</target>
|
||||
<target name="phpunit">
|
||||
<exec dir="${basedir}" executable="phpunit" failonerror="true">
|
||||
<exec dir="${basedir}" executable="phpunit">
|
||||
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml
|
||||
--coverage-clover ${basedir}/build/logs/clover.xml
|
||||
--coverage-html ${basedir}/build/coverage" />
|
||||
|
@ -2,11 +2,11 @@
|
||||
// Find and initialize Composer
|
||||
// NOTE: You should NOT use this when developing against php-resque.
|
||||
// The autoload code below is specifically for this demo.
|
||||
$files = array(
|
||||
$files = [
|
||||
__DIR__ . '/../../vendor/autoload.php',
|
||||
__DIR__ . '/../../../../autoload.php',
|
||||
__DIR__ . '/../vendor/autoload.php',
|
||||
);
|
||||
];
|
||||
|
||||
$found = false;
|
||||
foreach ($files as $file) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection PhpUndefinedFunctionInspection */
|
||||
|
||||
class PHP_Error_Job
|
||||
{
|
||||
|
@ -1,12 +1,12 @@
|
||||
<?php
|
||||
// Somewhere in our application, we need to register:
|
||||
Resque_Event::listen('afterEnqueue', array('My_Resque_Plugin', 'afterEnqueue'));
|
||||
Resque_Event::listen('beforeFirstFork', array('My_Resque_Plugin', 'beforeFirstFork'));
|
||||
Resque_Event::listen('beforeFork', array('My_Resque_Plugin', 'beforeFork'));
|
||||
Resque_Event::listen('afterFork', array('My_Resque_Plugin', 'afterFork'));
|
||||
Resque_Event::listen('beforePerform', array('My_Resque_Plugin', 'beforePerform'));
|
||||
Resque_Event::listen('afterPerform', array('My_Resque_Plugin', 'afterPerform'));
|
||||
Resque_Event::listen('onFailure', array('My_Resque_Plugin', 'onFailure'));
|
||||
Resque_Event::listen('afterEnqueue', ['My_Resque_Plugin', 'afterEnqueue']);
|
||||
Resque_Event::listen('beforeFirstFork', ['My_Resque_Plugin', 'beforeFirstFork']);
|
||||
Resque_Event::listen('beforeFork', ['My_Resque_Plugin', 'beforeFork']);
|
||||
Resque_Event::listen('afterFork', ['My_Resque_Plugin', 'afterFork']);
|
||||
Resque_Event::listen('beforePerform', ['My_Resque_Plugin', 'beforePerform']);
|
||||
Resque_Event::listen('afterPerform', ['My_Resque_Plugin', 'afterPerform']);
|
||||
Resque_Event::listen('onFailure', ['My_Resque_Plugin', 'onFailure']);
|
||||
|
||||
class Sample_Resque_Plugin
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php /** @noinspection ALL */
|
||||
|
||||
/**
|
||||
* Base Resque class.
|
||||
@ -51,6 +51,7 @@ class Resque
|
||||
* Return an instance of the Resque_Redis class instantiated for Resque.
|
||||
*
|
||||
* @return Resque_Redis Instance of Resque_Redis.
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
public static function redis()
|
||||
{
|
||||
@ -169,7 +170,7 @@ class Resque
|
||||
*
|
||||
* @param array $queues
|
||||
* @param int $timeout
|
||||
* @return null|array Decoded item from the queue.
|
||||
* @return array|null|void
|
||||
*/
|
||||
public static function blpop(array $queues, $timeout)
|
||||
{
|
||||
@ -181,7 +182,7 @@ class Resque
|
||||
$item = self::redis()->blpop($list, (int)$timeout);
|
||||
|
||||
if (!$item) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,7 +245,7 @@ class Resque
|
||||
* Reserve and return the next available job in the specified queue.
|
||||
*
|
||||
* @param string $queue Queue to fetch next available job from.
|
||||
* @return Resque_Job Instance of Resque_Job to be processed, false if none or error.
|
||||
* @return false|object|Resque_Job
|
||||
*/
|
||||
public static function reserve($queue)
|
||||
{
|
||||
@ -325,7 +326,9 @@ class Resque
|
||||
* @params string $string redis result in json
|
||||
* @params $items
|
||||
*
|
||||
* @return (bool)
|
||||
* @param $string
|
||||
* @param $items
|
||||
* @return bool (bool)
|
||||
*/
|
||||
private static function matchItem($string, $items)
|
||||
{
|
||||
@ -360,7 +363,9 @@ class Resque
|
||||
* @private
|
||||
*
|
||||
* @params string $queue the name of the queue
|
||||
* @param $queue
|
||||
* @return integer number of deleted items belongs to this list
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
private static function removeList($queue)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ class Resque_Failure
|
||||
/**
|
||||
* Create a new failed job on the backend.
|
||||
*
|
||||
* @param object $payload The contents of the job that has just failed.
|
||||
* @param array $payload The contents of the job that has just failed.
|
||||
* @param \Exception $exception The exception generated when the job failed to run.
|
||||
* @param \Resque_Worker $worker Instance of Resque_Worker that was running this job when it failed.
|
||||
* @param string $queue The name of the queue that this job was fetched from.
|
||||
@ -32,7 +32,7 @@ class Resque_Failure
|
||||
/**
|
||||
* Return an instance of the backend for saving job failures.
|
||||
*
|
||||
* @return object Instance of backend object.
|
||||
* @return object|string
|
||||
*/
|
||||
public static function getBackend()
|
||||
{
|
||||
|
@ -70,12 +70,12 @@ class Resque_Job
|
||||
'Supplied $args must be an array.'
|
||||
);
|
||||
}
|
||||
Resque::push($queue, array(
|
||||
Resque::push($queue, [
|
||||
'class' => $class,
|
||||
'args' => array($args),
|
||||
'args' => [$args],
|
||||
'id' => $id,
|
||||
'queue_time' => microtime(true),
|
||||
));
|
||||
]);
|
||||
|
||||
if ($monitor) {
|
||||
Resque_Job_Status::create($id);
|
||||
@ -153,7 +153,7 @@ class Resque_Job
|
||||
public function getArguments()
|
||||
{
|
||||
if (!isset($this->payload['args'])) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->payload['args'][0];
|
||||
@ -162,7 +162,6 @@ class Resque_Job
|
||||
/**
|
||||
* Get the instantiated object for this job that will be performing work.
|
||||
* @return Resque_JobInterface Instance of the object that this job belongs to.
|
||||
* @throws Resque_Exception
|
||||
*/
|
||||
public function getInstance()
|
||||
{
|
||||
@ -200,7 +199,7 @@ class Resque_Job
|
||||
|
||||
Resque_Event::trigger('afterPerform', $this);
|
||||
} // beforePerform/setUp have said don't perform this job. Return.
|
||||
catch (Resque_Job_DontPerform $e) {
|
||||
/** @noinspection PhpRedundantCatchClauseInspection */ catch (Resque_Job_DontPerform $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -214,10 +213,10 @@ class Resque_Job
|
||||
*/
|
||||
public function fail($exception)
|
||||
{
|
||||
Resque_Event::trigger('onFailure', array(
|
||||
Resque_Event::trigger('onFailure', [
|
||||
'exception' => $exception,
|
||||
'job' => $this,
|
||||
));
|
||||
]);
|
||||
|
||||
$this->updateStatus(Resque_Job_Status::STATUS_FAILED);
|
||||
Resque_Failure::create(
|
||||
@ -252,9 +251,9 @@ class Resque_Job
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$name = array(
|
||||
$name = [
|
||||
'Job{' . $this->queue . '}'
|
||||
);
|
||||
];
|
||||
if (!empty($this->payload['id'])) {
|
||||
$name[] = 'ID: ' . $this->payload['id'];
|
||||
}
|
||||
|
@ -29,10 +29,10 @@ class Resque_Job_Status
|
||||
/**
|
||||
* @var array Array of statuses that are considered final/complete.
|
||||
*/
|
||||
private static $completeStatuses = array(
|
||||
private static $completeStatuses = [
|
||||
self::STATUS_FAILED,
|
||||
self::STATUS_COMPLETE
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Setup a new instance of the job monitor class for the supplied job ID.
|
||||
@ -52,11 +52,11 @@ class Resque_Job_Status
|
||||
*/
|
||||
public static function create($id)
|
||||
{
|
||||
$statusPacket = array(
|
||||
$statusPacket = [
|
||||
'status' => self::STATUS_WAITING,
|
||||
'updated' => time(),
|
||||
'started' => time(),
|
||||
);
|
||||
];
|
||||
Resque::redis()->set('job:' . $id . ':status', json_encode($statusPacket));
|
||||
}
|
||||
|
||||
|
@ -119,6 +119,7 @@ class Resque_Redis
|
||||
if (is_object($client)) {
|
||||
$this->redisConnection = $client;
|
||||
} else {
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
|
||||
// $user is not used, only $password
|
||||
$timeout = isset($options['timeout']) ? intval($options['timeout']) : null;
|
||||
|
@ -101,6 +101,7 @@ class Resque_Worker
|
||||
*
|
||||
* @param string $workerId ID of the worker.
|
||||
* @return boolean True if the worker exists, false if not.
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
public static function exists($workerId)
|
||||
{
|
||||
@ -111,14 +112,15 @@ class Resque_Worker
|
||||
* Given a worker ID, find it and return an instantiated worker class for it.
|
||||
*
|
||||
* @param string $workerId The ID of the worker.
|
||||
* @return Resque_Worker Instance of the worker. False if the worker does not exist.
|
||||
* @return bool|Resque_Worker
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
public static function find($workerId)
|
||||
{
|
||||
if (!self::exists($workerId) || false === strpos($workerId, ":")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnusedLocalVariableInspection */
|
||||
list($hostname, $pid, $queues) = explode(':', $workerId, 3);
|
||||
$queues = explode(',', $queues);
|
||||
$worker = new self($queues);
|
||||
@ -143,6 +145,8 @@ class Resque_Worker
|
||||
* Queues are checked every $interval (seconds) for new jobs.
|
||||
*
|
||||
* @param int $interval How often to check for new jobs across the queues.
|
||||
* @param bool $blocking
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false)
|
||||
{
|
||||
@ -199,6 +203,7 @@ class Resque_Worker
|
||||
$status = 'Processing ' . $job->queue . ' since ' . strftime('%F %T');
|
||||
$this->updateProcLine($status);
|
||||
$this->logger->log(Psr\Log\LogLevel::INFO, $status);
|
||||
/** @noinspection PhpParamsInspection */
|
||||
$this->perform($job);
|
||||
if ($this->child === 0) {
|
||||
exit(0);
|
||||
@ -456,11 +461,12 @@ class Resque_Worker
|
||||
|
||||
/**
|
||||
* Register this worker in Redis.
|
||||
* 48 hour TTL so we don't pollute the db on server termination.
|
||||
*/
|
||||
public function registerWorker()
|
||||
{
|
||||
Resque::redis()->sadd('workers', (string)$this);
|
||||
Resque::redis()->set('worker:' . (string)$this . ':started', strftime('%a %b %d %H:%M:%S %Z %Y'));
|
||||
Resque::redis()->setex('worker:' . (string)$this . ':started', 172800, strftime('%a %b %d %H:%M:%S %Z %Y'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,7 +489,8 @@ class Resque_Worker
|
||||
/**
|
||||
* Tell Redis which job we're currently working on.
|
||||
*
|
||||
* @param object $job Resque_Job instance containing the job we're working on.
|
||||
* @param Resque_Job $job Resque_Job instance containing the job we're working on.
|
||||
* @throws Resque_RedisException
|
||||
*/
|
||||
public function workingOn(Resque_Job $job)
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
{
|
||||
private $callbacksHit = array();
|
||||
private $callbacksHit = [];
|
||||
private $worker;
|
||||
|
||||
public function setUp()
|
||||
@ -26,17 +26,17 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
public function tearDown()
|
||||
{
|
||||
Resque_Event::clearListeners();
|
||||
$this->callbacksHit = array();
|
||||
$this->callbacksHit = [];
|
||||
}
|
||||
|
||||
public function getEventTestJob()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Test_Job',
|
||||
'args' => array(
|
||||
array('somevar'),
|
||||
),
|
||||
);
|
||||
'args' => [
|
||||
['somevar'],
|
||||
],
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
return $job;
|
||||
@ -44,19 +44,21 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
|
||||
public function eventCallbackProvider()
|
||||
{
|
||||
return array(
|
||||
array('beforePerform', 'beforePerformEventCallback'),
|
||||
array('afterPerform', 'afterPerformEventCallback'),
|
||||
array('afterFork', 'afterForkEventCallback'),
|
||||
);
|
||||
return [
|
||||
['beforePerform', 'beforePerformEventCallback'],
|
||||
['afterPerform', 'afterPerformEventCallback'],
|
||||
['afterFork', 'afterForkEventCallback'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider eventCallbackProvider
|
||||
* @param $event
|
||||
* @param $callback
|
||||
*/
|
||||
public function testEventCallbacksFire($event, $callback)
|
||||
{
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque_Event::listen($event, [$this, $callback]);
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
@ -70,11 +72,11 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
$event = 'beforeFork';
|
||||
$callback = 'beforeForkEventCallback';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
Resque_Event::listen($event, [$this, $callback]);
|
||||
Resque::enqueue('jobs', 'Test_Job', [
|
||||
'somevar'
|
||||
));
|
||||
$job = $this->getEventTestJob();
|
||||
]);
|
||||
$this->getEventTestJob();
|
||||
$this->worker->work(0);
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
@ -84,17 +86,17 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
$event = 'beforeEnqueue';
|
||||
$callback = 'beforeEnqueueEventCallback';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
Resque_Event::listen($event, [$this, $callback]);
|
||||
Resque::enqueue('jobs', 'Test_Job', [
|
||||
'somevar'
|
||||
));
|
||||
]);
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
public function testBeforePerformEventCanStopWork()
|
||||
{
|
||||
$callback = 'beforePerformEventDontPerformCallback';
|
||||
Resque_Event::listen('beforePerform', array($this, $callback));
|
||||
Resque_Event::listen('beforePerform', [$this, $callback]);
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
|
||||
@ -106,8 +108,8 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
public function testBeforeEnqueueEventStopsJobCreation()
|
||||
{
|
||||
$callback = 'beforeEnqueueEventDontCreateCallback';
|
||||
Resque_Event::listen('beforeEnqueue', array($this, $callback));
|
||||
Resque_Event::listen('afterEnqueue', array($this, 'afterEnqueueEventCallback'));
|
||||
Resque_Event::listen('beforeEnqueue', [$this, $callback]);
|
||||
Resque_Event::listen('afterEnqueue', [$this, 'afterEnqueueEventCallback']);
|
||||
|
||||
$result = Resque::enqueue('test_job', 'TestClass');
|
||||
$this->assertContains($callback, $this->callbacksHit, $callback . ' callback was not called');
|
||||
@ -120,10 +122,10 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
$callback = 'afterEnqueueEventCallback';
|
||||
$event = 'afterEnqueue';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque::enqueue('jobs', 'Test_Job', array(
|
||||
Resque_Event::listen($event, [$this, $callback]);
|
||||
Resque::enqueue('jobs', 'Test_Job', [
|
||||
'somevar'
|
||||
));
|
||||
]);
|
||||
$this->assertContains($callback, $this->callbacksHit, $event . ' callback (' . $callback . ') was not called');
|
||||
}
|
||||
|
||||
@ -132,8 +134,8 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
$callback = 'beforePerformEventCallback';
|
||||
$event = 'beforePerform';
|
||||
|
||||
Resque_Event::listen($event, array($this, $callback));
|
||||
Resque_Event::stopListening($event, array($this, $callback));
|
||||
Resque_Event::listen($event, [$this, $callback]);
|
||||
Resque_Event::stopListening($event, [$this, $callback]);
|
||||
|
||||
$job = $this->getEventTestJob();
|
||||
$this->worker->perform($job);
|
||||
@ -144,13 +146,13 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function beforePerformEventDontPerformCallback($instance)
|
||||
public function beforePerformEventDontPerformCallback()
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontPerform();
|
||||
}
|
||||
|
||||
public function beforeEnqueueEventDontCreateCallback($queue, $class, $args, $track = false)
|
||||
public function beforeEnqueueEventDontCreateCallback()
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
throw new Resque_Job_DontCreate();
|
||||
@ -170,9 +172,9 @@ class Resque_Tests_EventTest extends Resque_Tests_TestCase
|
||||
{
|
||||
$this->callbacksHit[] = __FUNCTION__;
|
||||
$this->assertEquals('Test_Job', $class);
|
||||
$this->assertEquals(array(
|
||||
$this->assertEquals([
|
||||
'somevar',
|
||||
), $args);
|
||||
], $args);
|
||||
}
|
||||
|
||||
public function beforeEnqueueEventCallback($job)
|
||||
|
@ -33,7 +33,7 @@ class Resque_Tests_JobStatusTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testJobStatusIsReturnedViaJobInstance()
|
||||
{
|
||||
$token = Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
Resque::enqueue('jobs', 'Test_Job', null, true);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
$this->assertEquals(Resque_Job_Status::STATUS_WAITING, $job->getStatus());
|
||||
|
||||
|
@ -51,17 +51,17 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testQueuedJobReturnsExactSamePassedInArguments()
|
||||
{
|
||||
$args = array(
|
||||
$args = [
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
'numArray' => [
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
],
|
||||
'assocArray' => [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
|
||||
@ -77,17 +77,17 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testRecreatedJobMatchesExistingJob()
|
||||
{
|
||||
$args = array(
|
||||
$args = [
|
||||
'int' => 123,
|
||||
'numArray' => array(
|
||||
'numArray' => [
|
||||
1,
|
||||
2,
|
||||
),
|
||||
'assocArray' => array(
|
||||
],
|
||||
'assocArray' => [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2'
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
Resque::enqueue('jobs', 'Test_Job', $args);
|
||||
$job = Resque_Job::reserve('jobs');
|
||||
@ -103,10 +103,10 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testFailedJobExceptionsAreCaught()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Failing_Job',
|
||||
'args' => null
|
||||
);
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->worker = $this->worker;
|
||||
|
||||
@ -140,13 +140,13 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testJobWithSetUpCallbackFiresSetUp()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Test_Job_With_SetUp',
|
||||
'args' => array(
|
||||
'args' => [
|
||||
'somevar',
|
||||
'somevar2',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->perform();
|
||||
|
||||
@ -155,13 +155,13 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testJobWithTearDownCallbackFiresTearDown()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Test_Job_With_TearDown',
|
||||
'args' => array(
|
||||
'args' => [
|
||||
'somevar',
|
||||
'somevar2',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$job->perform();
|
||||
|
||||
@ -170,12 +170,12 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testNamespaceNaming()
|
||||
{
|
||||
$fixture = array(
|
||||
array('test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'),
|
||||
array('test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'),
|
||||
array('test' => 'resque', 'assertValue' => 'resque:'),
|
||||
array('test' => 'resque:', 'assertValue' => 'resque:'),
|
||||
);
|
||||
$fixture = [
|
||||
['test' => 'more:than:one:with:', 'assertValue' => 'more:than:one:with:'],
|
||||
['test' => 'more:than:one:without', 'assertValue' => 'more:than:one:without:'],
|
||||
['test' => 'resque', 'assertValue' => 'resque:'],
|
||||
['test' => 'resque:', 'assertValue' => 'resque:'],
|
||||
];
|
||||
|
||||
foreach ($fixture as $item) {
|
||||
Resque_Redis::prefix($item['test']);
|
||||
@ -187,10 +187,10 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
{
|
||||
Resque_Redis::prefix('php');
|
||||
$queue = 'jobs';
|
||||
$payload = array('another_value');
|
||||
$payload = ['another_value'];
|
||||
Resque::enqueue($queue, 'Test_Job_With_TearDown', $payload);
|
||||
|
||||
$this->assertEquals(Resque::queues(), array('jobs'));
|
||||
$this->assertEquals(Resque::queues(), ['jobs']);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
|
||||
Resque_Redis::prefix('resque');
|
||||
@ -228,7 +228,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue1');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue2');
|
||||
$test = ['Test_Job_Dequeue2'];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
@ -240,7 +240,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue2', 'Test_Job_Dequeue3');
|
||||
$test = ['Test_Job_Dequeue2', 'Test_Job_Dequeue3'];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 2);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
@ -252,7 +252,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4');
|
||||
$test = ['Test_Job_Dequeue4'];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
}
|
||||
@ -264,7 +264,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue2');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue3');
|
||||
$this->assertEquals(Resque::size($queue), 3);
|
||||
$test = array('Test_Job_Dequeue4', 'Test_Job_Dequeue1');
|
||||
$test = ['Test_Job_Dequeue4', 'Test_Job_Dequeue1'];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
@ -275,7 +275,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $qid);
|
||||
$test = ['Test_Job_Dequeue' => $qid];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
@ -287,7 +287,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
#qid right but class name is wrong
|
||||
$test = array('Test_Job_Dequeue1' => $qid);
|
||||
$test = ['Test_Job_Dequeue1' => $qid];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
@ -296,9 +296,9 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
{
|
||||
$queue = 'jobs';
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$qid = Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => 'r4nD0mH4sh3dId');
|
||||
$test = ['Test_Job_Dequeue' => 'r4nD0mH4sh3dId'];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
@ -328,7 +328,7 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
// WHEN
|
||||
$test = ['Test_Job_Dequeue9' => $removeArgs];
|
||||
$removedItems = Resque::dequeue($queue, $test, "Dequeue one failed!");
|
||||
$removedItems = Resque::dequeue($queue, $test);
|
||||
|
||||
// THEN
|
||||
$this->assertEquals($removedItems, 2);
|
||||
@ -341,12 +341,12 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
public function testDequeueItemWithUnorderedArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('bar' => 2, 'foo' => 1);
|
||||
$arg = ['foo' => 1, 'bar' => 2];
|
||||
$arg2 = ['bar' => 2, 'foo' => 1];
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$test = ['Test_Job_Dequeue' => $arg2];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 1);
|
||||
$this->assertEquals(Resque::size($queue), 1);
|
||||
}
|
||||
@ -354,22 +354,22 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
public function testDequeueItemWithiWrongArg()
|
||||
{
|
||||
$queue = 'jobs';
|
||||
$arg = array('foo' => 1, 'bar' => 2);
|
||||
$arg2 = array('foo' => 2, 'bar' => 3);
|
||||
$arg = ['foo' => 1, 'bar' => 2];
|
||||
$arg2 = ['foo' => 2, 'bar' => 3];
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue');
|
||||
Resque::enqueue($queue, 'Test_Job_Dequeue', $arg);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
$test = array('Test_Job_Dequeue' => $arg2);
|
||||
$test = ['Test_Job_Dequeue' => $arg2];
|
||||
$this->assertEquals(Resque::dequeue($queue, $test), 0);
|
||||
$this->assertEquals(Resque::size($queue), 2);
|
||||
}
|
||||
|
||||
public function testUseDefaultFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => null
|
||||
);
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$instance = $job->getInstance();
|
||||
$this->assertInstanceOf('Some_Job_Class', $instance);
|
||||
@ -377,10 +377,10 @@ class Resque_Tests_JobTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testUseFactoryToGetJobInstance()
|
||||
{
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Some_Job_Class',
|
||||
'args' => array(array())
|
||||
);
|
||||
'args' => [[]]
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$factory = new Some_Stub_Factory();
|
||||
$job->setJobFactory($factory);
|
||||
|
@ -13,7 +13,7 @@ class Resque_Tests_LogTest extends Resque_Tests_TestCase
|
||||
public function testLogInterpolate()
|
||||
{
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate('string {replace}', array('replace' => 'value'));
|
||||
$actual = $logger->interpolate('string {replace}', ['replace' => 'value']);
|
||||
$expected = 'string value';
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
@ -24,7 +24,7 @@ class Resque_Tests_LogTest extends Resque_Tests_TestCase
|
||||
$logger = new Resque_Log();
|
||||
$actual = $logger->interpolate(
|
||||
'string {replace1} {replace2}',
|
||||
array('replace1' => 'value1', 'replace2' => 'value2')
|
||||
['replace1' => 'value1', 'replace2' => 'value2']
|
||||
);
|
||||
$expected = 'string value1 value2';
|
||||
|
||||
|
@ -10,9 +10,6 @@
|
||||
|
||||
class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
||||
{
|
||||
/**
|
||||
* @expectedException Test basic redis functionality.
|
||||
*/
|
||||
public function testRedisGetSet()
|
||||
{
|
||||
$this->redis->set("testKey", 24);
|
||||
@ -173,6 +170,8 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
||||
|
||||
/**
|
||||
* @dataProvider validDsnStringProvider
|
||||
* @param $dsn
|
||||
* @param $expected
|
||||
*/
|
||||
public function testParsingValidDsnString($dsn, $expected)
|
||||
{
|
||||
@ -183,6 +182,7 @@ class Resque_Tests_RedisTest extends Resque_Tests_TestCase
|
||||
/**
|
||||
* @dataProvider bogusDsnStringProvider
|
||||
* @expectedException InvalidArgumentException
|
||||
* @param $dsn
|
||||
*/
|
||||
public function testParsingBogusDsnStringThrowsException($dsn)
|
||||
{
|
||||
|
@ -57,8 +57,8 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$worker->unregisterWorker();
|
||||
|
||||
$this->assertFalse(Resque_Worker::exists((string)$worker));
|
||||
$this->assertEquals(array(), Resque_Worker::all());
|
||||
$this->assertEquals(array(), $this->redis->smembers('resque:workers'));
|
||||
$this->assertEquals([], Resque_Worker::all());
|
||||
$this->assertEquals([], $this->redis->smembers('resque:workers'));
|
||||
}
|
||||
|
||||
public function testPausedWorkerDoesNotPickUpJobs()
|
||||
@ -87,10 +87,10 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testWorkerCanWorkOverMultipleQueues()
|
||||
{
|
||||
$worker = new Resque_Worker(array(
|
||||
$worker = new Resque_Worker([
|
||||
'queue1',
|
||||
'queue2'
|
||||
));
|
||||
]);
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->registerWorker();
|
||||
Resque::enqueue('queue1', 'Test_Job_1');
|
||||
@ -105,11 +105,11 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
|
||||
public function testWorkerWorksQueuesInSpecifiedOrder()
|
||||
{
|
||||
$worker = new Resque_Worker(array(
|
||||
$worker = new Resque_Worker([
|
||||
'high',
|
||||
'medium',
|
||||
'low'
|
||||
));
|
||||
]);
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->registerWorker();
|
||||
|
||||
@ -163,7 +163,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$job = $worker->reserve();
|
||||
$worker->workingOn($job);
|
||||
$worker->doneWorking();
|
||||
$this->assertEquals(array(), $worker->job());
|
||||
$this->assertEquals([], $worker->job());
|
||||
}
|
||||
|
||||
public function testWorkerRecordsWhatItIsWorkingOn()
|
||||
@ -172,9 +172,9 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->registerWorker();
|
||||
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Test_Job'
|
||||
);
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
$worker->workingOn($job);
|
||||
|
||||
@ -214,7 +214,7 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$worker->setId($workerId[0] . ':1:jobs');
|
||||
$worker->registerWorker();
|
||||
|
||||
$worker = new Resque_Worker(array('high', 'low'));
|
||||
$worker = new Resque_Worker(['high', 'low']);
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->setId($workerId[0] . ':2:high,low');
|
||||
$worker->registerWorker();
|
||||
@ -258,9 +258,9 @@ class Resque_Tests_WorkerTest extends Resque_Tests_TestCase
|
||||
$worker->setLogger(new Resque_Log());
|
||||
$worker->registerWorker();
|
||||
|
||||
$payload = array(
|
||||
$payload = [
|
||||
'class' => 'Test_Job'
|
||||
);
|
||||
];
|
||||
$job = new Resque_Job('jobs', $payload);
|
||||
|
||||
$worker->workingOn($job);
|
||||
|
Loading…
Reference in New Issue
Block a user