Browse Source

2.0.0 Add namespacing + PHP8.0 support (#1)

2.0.0 (2021-02-19)

Moved to PSR-4
Namespaced codebase
Added more comments throughout
Co-Authored-By: idanoo <daniel@m2.nz>
Co-Committed-By: idanoo <daniel@m2.nz>
master 2.0.0
idanoo 8 months ago
parent
commit
80d64e79ff
  1. 3
      .gitignore
  2. 27
      .gitlab-ci.yml
  3. 13
      .travis.yml
  4. 7
      CHANGELOG.md
  5. 10
      HOWITWORKS.md
  6. 4
      README.md
  7. 32
      bin/resque
  8. 18
      build.xml
  9. 21
      composer.json
  10. 1406
      composer.lock
  11. 8
      demo/bad_job.php
  12. 9
      demo/php_error_job.php
  13. 7
      demo/resque.php
  14. 11
      examples/BadPHPJob.php
  15. 9
      examples/CheckStatus.php
  16. 6
      examples/Init.php
  17. 6
      examples/LongPHPJob.php
  18. 13
      examples/PHPErrorJob.php
  19. 6
      examples/PHPJob.php
  20. 25
      examples/SampleResquePlugin.php
  21. 11
      examples/queue.php
  22. 2
      examples/resque.logrotate
  23. 15
      extras/resque.monit
  24. 12
      lib/Resque/Job/FactoryInterface.php
  25. 13
      phpunit.xml
  26. 25
      ruleset.xml
  27. 9
      src/Resque/Event.php
  28. 7
      src/Resque/Exception.php
  29. 16
      src/Resque/Failure/Failure.php
  30. 8
      src/Resque/Failure/ResqueFailureInterface.php
  31. 15
      src/Resque/Failure/ResqueFailureRedis.php
  32. 6
      src/Resque/Job/DirtyExitException.php
  33. 6
      src/Resque/Job/DontCreate.php
  34. 7
      src/Resque/Job/DontPerform.php
  35. 21
      src/Resque/Job/Factory.php
  36. 21
      src/Resque/Job/FactoryInterface.php
  37. 80
      src/Resque/Job/Job.php
  38. 4
      src/Resque/Job/JobInterface.php
  39. 30
      src/Resque/Job/Status.php
  40. 26
      src/Resque/Log.php
  41. 32
      src/Resque/Redis.php
  42. 6
      src/Resque/RedisException.php
  43. 43
      src/Resque/Resque.php
  44. 10
      src/Resque/Stat.php
  45. 118
      src/Resque/Worker.php
  46. 109
      test/Resque/Tests/JobStatusTest.php
  47. 421
      test/Resque/Tests/JobTest.php
  48. 58
      tests/Resque/Tests/EventTest.php
  49. 110
      tests/Resque/Tests/JobStatusTest.php
  50. 423
      tests/Resque/Tests/JobTest.php
  51. 12
      tests/Resque/Tests/LogTest.php
  52. 22
      tests/Resque/Tests/RedisTest.php
  53. 30
      tests/Resque/Tests/StatTest.php
  54. 11
      tests/Resque/Tests/TestCase.php
  55. 154
      tests/Resque/Tests/WorkerTest.php
  56. 38
      tests/bootstrap.php

3
.gitignore

@ -1,3 +1,2 @@
vendor/
phpunit.xml
*.swp
.phpunit.result.cache

27
.gitlab-ci.yml

@ -12,9 +12,6 @@
&& docker-php-ext-enable redis
docker-php-ext-install pcntl
# Hack to fix mismatched php versions
rm composer.lock
# Install Composer
wget https://getcomposer.org/composer.phar
php composer.phar install --dev
@ -28,6 +25,26 @@ test:7.4:
before_script:
- *docker_boostrap
script:
- php vendor/bin/phpunit --verbose --configuration phpunit.xml.dist
- php vendor/bin/phpunit --verbose --configuration phpunit.xml
tags:
- docker
# Test PHP 8.0
test:8.0:
image: php:8.0
before_script:
- *docker_boostrap
script:
- php vendor/bin/phpunit --verbose --configuration phpunit.xml
tags:
- docker
- docker
# Codestandards
lint:
image: php:8.0
allow_failure: true
script:
- apt update && apt install -y wget unzip git
- wget https://getcomposer.org/composer.phar
- php composer.phar install --dev
- php -d memory_limit=256M vendor/bin/phpcs -s --standard=ruleset.xml

13
.travis.yml

@ -1,13 +0,0 @@
language: php
php:
- 7.0
- 7.1
- 7.2
services:
- redis-server
before_script:
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- composer install

7
CHANGELOG.md

@ -1,3 +1,8 @@
## 2.0.0 (2021-02-19)
- Moved to PSR-4
- Namespaced codebase
- Added more comments throughout
## 1.4.7 (2020-04-11)
- Update PHPUnit to 9
- Start adding return types
@ -93,7 +98,7 @@ Changes by iskandar introduce improved support for using DSNs to connect to Redi
* Pass queue name to afterEvent callback
* Only declare RedisException if it doesn't already exist (Matt Heath)
* Add support for Composer
* Fix missing and incorrect paths for Resque and Resque_Job_Status classes in demo (jjfrey)
* Fix missing and incorrect paths for Resque and \Resque\Job\Status classes in demo (jjfrey)
* Disable autoload for the RedisException class_exists call (scragg0x)
* General tidy up of comments and files/folders

10
HOWITWORKS.md

@ -14,9 +14,9 @@ What happens when you call `Resque::enqueue()`?
4. `Resque_Job::create()` pushes the job to the requested queue (first
argument)
5. `Resque_Job::create()`, if status monitoring is enabled for the job (fourth
argument), calls `Resque_Job_Status::create()` with the job ID as its only
argument), calls `\Resque\Job\Status::create()` with the job ID as its only
argument
6. `Resque_Job_Status::create()` creates a key in Redis with the job ID in its
6. `\Resque\Job\Status::create()` creates a key in Redis with the job ID in its
name, and the current status (as well as a couple of timestamps) as its
value, then returns control to `Resque_Job::create()`
7. `Resque_Job::create()` returns control to `Resque::enqueue()`, with the job
@ -85,15 +85,15 @@ How do the workers process the queues?
* Worker
1. The worker waits for the job process to complete
2. If the exit status is not 0, the worker calls `Resque_Job->fail()` with
a `Resque_Job_DirtyExitException` as its only argument.
a `Resque\Job\DirtyExitException` as its only argument.
3. `Resque_Job->fail()` triggers an `onFailure` event
4. `Resque_Job->fail()` updates the job status from `RUNNING` to `FAILED`
5. `Resque_Job->fail()` calls `Resque_Failure::create()` with the job
payload, the `Resque_Job_DirtyExitException`, the internal ID of the
payload, the `Resque\Job\DirtyExitException`, the internal ID of the
worker, and the queue name as arguments
6. `Resque_Failure::create()` creates a new object of whatever type has
been set as the `Resque_Failure` "backend" handler; by default, this is
a `Resque_Failure_Redis` object, whose constructor simply collects the
a `ResqueFailureRedis` object, whose constructor simply collects the
data passed into `Resque_Failure::create()` and pushes it into Redis
in the `failed` queue
7. `Resque_Job->fail()` increments two failure counters in Redis: one for

4
README.md

@ -1,6 +1,8 @@
php-resque: PHP Resque Worker (and Enqueue)
===========================================
[![pipeline status](https://gitlab.com/idanoo/php-resque/badges/master/pipeline.svg)](https://gitlab.com/idanoo/php-resque/-/commits/master)
Resque is a Redis-backed library for creating background jobs, placing
those jobs on one or more queues, and processing them later.
@ -367,8 +369,6 @@ your `APP_INCLUDE` script should initialize and register any listeners required
for operation. If you have rolled your own worker manager, then it is again your
responsibility to register listeners.
A sample plugin is included in the `extras` directory.
### Events ###
#### beforeFirstFork ####

32
bin/resque

@ -9,7 +9,6 @@ $files = [
__DIR__ . '/../vendor/autoload.php',
];
$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
@ -25,6 +24,7 @@ if (!class_exists('Composer\Autoload\ClassLoader', false)) {
);
}
// Set which queues to monitor '*'
$QUEUE = getenv('QUEUE');
if (empty($QUEUE)) {
die("Set QUEUE env var containing the list of queues to work.\n");
@ -38,22 +38,24 @@ if (empty($QUEUE)) {
*/
$REDIS_BACKEND = getenv('REDIS_BACKEND');
// A redis database number
// Override redis DB numbers
$REDIS_BACKEND_DB = getenv('REDIS_BACKEND_DB');
if (!empty($REDIS_BACKEND)) {
if (empty($REDIS_BACKEND_DB)) {
Resque::setBackend($REDIS_BACKEND);
\Resque\Resque::setBackend($REDIS_BACKEND);
} else {
Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
\Resque\Resque::setBackend($REDIS_BACKEND, $REDIS_BACKEND_DB);
}
}
// Set Logging level
$logLevel = false;
$LOGGING = getenv('LOGLEVEL');
if (!empty($LOGGING)) {
$logLevel = $LOGGING;
}
// Bootstrap file
$APP_INCLUDE = getenv('APP_INCLUDE');
if ($APP_INCLUDE) {
if (!file_exists($APP_INCLUDE)) {
@ -66,41 +68,45 @@ if ($APP_INCLUDE) {
// See if the APP_INCLUDE containes a logger object,
// If none exists, fallback to internal logger
if (!isset($logger) || !is_object($logger)) {
$logger = new Resque_Log($logLevel);
$logger = new \Resque\Log($logLevel);
}
// Determines if blocking or not
$BLOCKING = getenv('BLOCKING') !== FALSE;
// Interval to check for jobs
$interval = 5;
$INTERVAL = getenv('INTERVAL');
if (!empty($INTERVAL)) {
$interval = $INTERVAL;
}
// Sets worker count
$count = 1;
$COUNT = getenv('COUNT');
if (!empty($COUNT) && $COUNT > 1) {
$count = $COUNT;
}
// Determines redis key prefix
$PREFIX = getenv('PREFIX');
if (!empty($PREFIX)) {
$logger->log(Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', ['prefix' => $PREFIX]);
Resque_Redis::prefix($PREFIX);
$logger->log(\Psr\Log\LogLevel::INFO, 'Prefix set to {prefix}', ['prefix' => $PREFIX]);
\Resque\Redis::prefix($PREFIX);
}
if ($count > 1) {
for ($i = 0; $i < $count; ++$i) {
$pid = Resque::fork();
$pid = \Resque\Resque::fork();
if ($pid === false || $pid === -1) {
$logger->log(Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', ['count' => $i]);
$logger->log(\Psr\Log\LogLevel::EMERGENCY, 'Could not fork worker {count}', ['count' => $i]);
die();
} elseif (!$pid) {
// Child, start the worker
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker = new \Resque\Worker($queues);
$worker->setLogger($logger);
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', ['worker' => $worker]);
$logger->log(\Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', ['worker' => $worker]);
$worker->work($interval, $BLOCKING);
break;
}
@ -108,7 +114,7 @@ if ($count > 1) {
} else {
// Start a single worker
$queues = explode(',', $QUEUE);
$worker = new Resque_Worker($queues);
$worker = new \Resque\Worker($queues);
$worker->setLogger($logger);
$PIDFILE = getenv('PIDFILE');
@ -117,6 +123,6 @@ if ($count > 1) {
die('Could not write PID information to ' . $PIDFILE);
}
$logger->log(Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', ['worker' => $worker]);
$logger->log(\Psr\Log\LogLevel::NOTICE, 'Starting worker {worker}', ['worker' => $worker]);
$worker->work($interval, $BLOCKING);
}

18
build.xml

@ -1,18 +0,0 @@
<!--suppress PhingDomInspection -->
<project name="php-resque" default="build">
<target name="clean">
<delete dir="${basedir}/build" />
</target>
<target name="prepare">
<mkdir dir="${basedir}/build" />
<mkdir dir="${basedir}/build/logs" />
</target>
<target name="phpunit">
<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" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpunit" />
</project>

21
composer.json

@ -1,6 +1,5 @@
{
"name": "idanoo/php-resque",
"version": "1.4.7",
"type": "library",
"replace": {
"chrisboulton/php-resque": "*",
@ -17,21 +16,25 @@
}
],
"require": {
"php": "^7.0",
"ext-pcntl": "*",
"ext-redis": "*",
"psr/log": "~1.0",
"colinmollenhour/credis": "^1.10"
"php": ">7.4",
"psr/log": "^1.1.0",
"colinmollenhour/credis": "^1.12.0"
},
"require-dev": {
"phpunit/phpunit": "^9"
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "3.*"
},
"bin": [
"bin/resque"
],
"autoload": {
"psr-0": {
"Resque": "lib"
"psr-4": {
"Resque\\": "src/Resque"
}
},
"autoload-dev": {
"psr-4": {
"Resque\\Test\\": "tests/Resque/Tests"
}
},
"support": {

1406
composer.lock

File diff suppressed because it is too large

8
demo/bad_job.php

@ -1,8 +0,0 @@
<?php
class Bad_PHP_Job
{
public function perform()
{
throw new Exception('Unable to run this job!');
}
}

9
demo/php_error_job.php

@ -1,9 +0,0 @@
<?php /** @noinspection PhpUndefinedFunctionInspection */
class PHP_Error_Job
{
public function perform()
{
callToUndefinedFunction();
}
}

7
demo/resque.php

@ -1,7 +0,0 @@
<?php
date_default_timezone_set('GMT');
require 'bad_job.php';
require 'job.php';
require 'php_error_job.php';
require '../bin/resque';

11
examples/BadPHPJob.php

@ -0,0 +1,11 @@
<?php
namespace Resque\Example;
class BadPHPJob
{
public function perform()
{
throw new \Exception('Unable to run this job!');
}
}

9
demo/check_status.php → examples/CheckStatus.php

@ -1,4 +1,7 @@
<?php
namespace Resque\Example;
if (empty($argv[1])) {
die('Specify the ID of a job to monitor the status of.');
}
@ -6,12 +9,12 @@ if (empty($argv[1])) {
require __DIR__ . '/init.php';
date_default_timezone_set('GMT');
Resque::setBackend('127.0.0.1:6379');
\Resque\Resque::setBackend('127.0.0.1:6379');
// You can also use a DSN-style format:
//Resque::setBackend('redis://user:pass@127.0.0.1:6379');
//Resque::setBackend('redis://user:pass@a.host.name:3432/2');
$status = new Resque_Job_Status($argv[1]);
$status = new \Resque\Job\Status($argv[1]);
if (!$status->isTracking()) {
die("Resque is not tracking the status of this job.\n");
}
@ -20,4 +23,4 @@ echo "Tracking status of " . $argv[1] . ". Press [break] to stop.\n\n";
while (true) {
fwrite(STDOUT, "Status of " . $argv[1] . " is: " . $status->get() . "\n");
sleep(1);
}
}

6
demo/init.php → examples/Init.php

@ -1,4 +1,7 @@
<?php
namespace Resque\Example;
// Find and initialize Composer
// NOTE: You should NOT use this when developing against php-resque.
// The autoload code below is specifically for this demo.
@ -8,7 +11,6 @@ $files = [
__DIR__ . '/../vendor/autoload.php',
];
$found = false;
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
@ -22,4 +24,4 @@ if (!class_exists('Composer\Autoload\ClassLoader', false)) {
'curl -s http://getcomposer.org/installer | php' . PHP_EOL .
'php composer.phar install' . PHP_EOL
);
}
}

6
demo/long_job.php → examples/LongPHPJob.php

@ -1,9 +1,11 @@
<?php
class Long_PHP_Job
namespace Resque\Example;
class LongPHPJob
{
public function perform()
{
sleep(600);
}
}
}

13
examples/PHPErrorJob.php

@ -0,0 +1,13 @@
<?php
/** @noinspection PhpUndefinedFunctionInspection */
namespace Resque\Example;
class PHPErrorJob
{
public function perform()
{
callToUndefinedFunction();
}
}

6
demo/job.php → examples/PHPJob.php

@ -1,6 +1,8 @@
<?php
class PHP_Job
namespace Resque\Example;
class PHPJob
{
public function perform()
{
@ -8,4 +10,4 @@ class PHP_Job
sleep(1);
fwrite(STDOUT, 'Job ended!' . PHP_EOL);
}
}
}

25
extras/sample-plugin.php → examples/SampleResquePlugin.php

@ -1,14 +1,17 @@
<?php
namespace Resque\Example;
// Somewhere in our application, we need to register:
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
// \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 SampleResquePlugin
{
public static function afterEnqueue($class, $arguments)
{
@ -34,7 +37,7 @@ class Sample_Resque_Plugin
public static function beforePerform($job)
{
echo "Cancelling " . $job . "\n";
// throw new Resque_Job_DontPerform;
// throw new Resque_Job_DontPerform;
}
public static function afterPerform($job)
@ -46,4 +49,4 @@ class Sample_Resque_Plugin
{
echo $job . " threw an exception:\n" . $exception;
}
}
}

11
demo/queue.php → examples/queue.php

@ -1,11 +1,14 @@
<?php
namespace Resque\Example;
if (empty($argv[1])) {
die('Specify the name of a job to add. e.g, php queue.php PHP_Job');
die('Specify the name of a job to add. e.g, php queue.php PHPJob');
}
require __DIR__ . '/init.php';
date_default_timezone_set('GMT');
Resque::setBackend('127.0.0.1:6379');
\Resque\Resque::setBackend('127.0.0.1:6379');
// You can also use a DSN-style format:
//Resque::setBackend('redis://user:pass@127.0.0.1:6379');
@ -18,9 +21,9 @@ $args = [
],
];
if (empty($argv[2])) {
$jobId = Resque::enqueue('default', $argv[1], $args, true);
$jobId = \Resque\Resque::enqueue('default', $argv[1], $args, true);
} else {
$jobId = Resque::enqueue($argv[1], $argv[2], $args, true);
$jobId = \Resque\Resque::enqueue($argv[1], $argv[2], $args, true);
}
echo "Queued job " . $jobId . "\n\n";

2
extras/resque.logrotate → examples/resque.logrotate

@ -5,6 +5,6 @@
compress
compressoptions -4
notifempty
create 640 root adm
create 640 root www-data
copytruncate
}

15
extras/resque.monit

@ -1,15 +0,0 @@
# Borrowed with modifications from
# https://github.com/defunkt/resque/blob/master/examples/monit/resque.monit
# Replace these with your own:
# [QUEUE]
# [PATH/TO/RESQUE]
# [UID]
# [GID]
# [APP_INCLUDE]
check process resque_worker_[QUEUE]
with pidfile /var/run/resque/worker_[QUEUE].pid
start program = "/bin/sh -c 'APP_INCLUDE=[APP_INCLUDE] QUEUE=[QUEUE] VERBOSE=1 PIDFILE=/var/run/resque/worker_[QUEUE].pid nohup php -f [PATH/TO/RESQUE]/bin/resque > /var/log/resque/worker_[QUEUE].log &'" as uid [UID] and gid [GID]
stop program = "/bin/sh -c 'kill -s QUIT `cat /var/run/resque/worker_[QUEUE].pid` && rm -f /var/run/resque/worker_[QUEUE].pid; exit 0;'"
if totalmem is greater than 300 MB for 10 cycles then restart # eating up memory?
group resque_workers

12
lib/Resque/Job/FactoryInterface.php

@ -1,12 +0,0 @@
<?php
interface Resque_Job_FactoryInterface
{
/**
* @param $className
* @param array $args
* @param $queue
* @return Resque_JobInterface
*/
public function create($className, $args, $queue);
}

13
phpunit.xml.dist → phpunit.xml

@ -1,24 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
bootstrap="test/bootstrap.php"
bootstrap="tests/bootstrap.php"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
processIsolation="true"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Resque Test Suite">
<directory>./test/Resque/</directory>
<directory>./tests/Resque/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./lib/Resque/</directory>
</whitelist>
</filter>
</phpunit>

25
ruleset.xml

@ -0,0 +1,25 @@
<?xml version="1.0"?>
<ruleset name="phpresque" namespace="ezyVet\PHPCS">
<description>PSR12</description>
<file>.</file>
<exclude-pattern>vendor/</exclude-pattern>
<exclude-pattern>tests/</exclude-pattern>
<arg name="extensions" value="php" />
<arg name="colors"/>
<arg value="sp"/>
<arg name="parallel" value="16"/>
<arg name="report-width" value="140" />
<ini name="memory_limit" value="256M"/>
<rule ref="PSR12">
<!-- <severity>8</severity> -->
<show_warnings>0</show_warnings>
</rule>
<!-- <rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>src</exclude-pattern>
</rule> -->
</ruleset>

9
lib/Resque/Event.php → src/Resque/Event.php

@ -1,14 +1,16 @@
<?php
namespace Resque;
/**
* Resque event/plugin system class
*
* @package Resque/Event
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Event
class Event
{
/**
* @var array Array containing all registered callbacks, indexked by event name.
@ -36,7 +38,8 @@ class Resque_Event
if (!is_callable($callback)) {
continue;
}
call_user_func_array($callback, $data);
call_user_func_array($callback, array_values($data));
}
return true;

7
lib/Resque/Exception.php → src/Resque/Exception.php

@ -1,13 +1,16 @@
<?php
namespace Resque;
/**
* Resque exception.
*
* @package Resque
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Exception extends Exception
class Exception extends \Exception
{
}

16
lib/Resque/Failure.php → src/Resque/Failure/Failure.php

@ -1,14 +1,16 @@
<?php
namespace Resque\Failure;
/**
* Failed Resque job.
*
* @package Resque/Failure
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Failure
class Failure
{
/**
* @var string Class name representing the backend to pass failed jobs off to.
@ -19,11 +21,11 @@ class Resque_Failure
* Create a new failed job on the backend.
*
* @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 \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.
*/
public static function create($payload, Exception $exception, Resque_Worker $worker, $queue)
public static function create($payload, \Exception $exception, \Resque\Worker $worker, $queue)
{
$backend = self::getBackend();
new $backend($payload, $exception, $worker, $queue);
@ -37,7 +39,7 @@ class Resque_Failure
public static function getBackend()
{
if (self::$backend === null) {
self::$backend = 'Resque_Failure_Redis';
self::$backend = '\\Resque\\Failure\\ResqueFailureRedis';
}
return self::$backend;
@ -54,4 +56,4 @@ class Resque_Failure
{
self::$backend = $backend;
}
}
}

8
lib/Resque/Failure/Interface.php → src/Resque/Failure/ResqueFailureInterface.php

@ -1,13 +1,15 @@
<?php
namespace Resque\Failure;
/**
* Interface that all failure backends should implement.
*
* @package Resque/Failure
* @author Chris Boulton <chris@bigcommerce.com>
* @package Resque\Failure
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
interface Resque_Failure_Interface
interface ResqueFailureInterface
{
/**
* Initialize a failed job class and save it (where appropriate).

15
lib/Resque/Failure/Redis.php → src/Resque/Failure/ResqueFailureRedis.php

@ -1,13 +1,16 @@
<?php
namespace Resque\Failure;
/**
* Redis backend for storing failed Resque jobs.
*
* @package Resque/Failure
* @author Chris Boulton <chris@bigcommerce.com>
* @package Resque\Failure
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Failure_Redis implements Resque_Failure_Interface
class ResqueFailureRedis implements ResqueFailureInterface
{
/**
* Initialize a failed job class and save it (where appropriate).
@ -16,11 +19,11 @@ class Resque_Failure_Redis implements Resque_Failure_Interface
* @param object $exception Instance of the exception that was thrown by the failed job.
* @param object $worker Instance of Resque_Worker that received the job.
* @param string $queue The name of the queue the job was fetched from.
* @throws Resque_RedisException
* @throws \Resque\RedisException
*/
public function __construct($payload, $exception, $worker, $queue)
{
$data = new stdClass;
$data = new \stdClass();
$data->failed_at = strftime('%a %b %d %H:%M:%S %Z %Y');
$data->payload = $payload;
$data->exception = get_class($exception);
@ -29,6 +32,6 @@ class Resque_Failure_Redis implements Resque_Failure_Interface
$data->worker = (string)$worker;
$data->queue = $queue;
$data = json_encode($data);
Resque::redis()->rpush('failed', $data);
\Resque\Resque::redis()->rpush('failed', $data);
}
}

6
lib/Resque/Job/DirtyExitException.php → src/Resque/Job/DirtyExitException.php

@ -1,13 +1,15 @@
<?php
namespace Resque\Job;
/**
* Runtime exception class for a job that does not exit cleanly.
*
* @package Resque/Job
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Job_DirtyExitException extends RuntimeException
class DirtyExitException extends \RuntimeException
{
}

6
lib/Resque/Job/DontCreate.php → src/Resque/Job/DontCreate.php

@ -1,13 +1,15 @@
<?php
namespace Resque\Job;
/**
* Exception to be thrown if while enqueuing a job it should not be created.
*
* @package Resque/Job
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Job_DontCreate extends Exception
class DontCreate extends \Exception
{
}

7
lib/Resque/Job/DontPerform.php → src/Resque/Job/DontPerform.php

@ -1,14 +1,15 @@
<?php
namespace Resque\Job;
/**
* Exception to be thrown if a job should not be performed/run.
*
* @package Resque/Job
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Job_DontPerform extends Exception
class DontPerform extends \Exception
{
}

21
lib/Resque/Job/Factory.php → src/Resque/Job/Factory.php

@ -1,30 +1,39 @@
<?php
class Resque_Job_Factory implements Resque_Job_FactoryInterface
namespace Resque\Job;
/**
* Job Factory!
*
* @package Resque/Job
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Factory implements FactoryInterface
{
/**
* @param $className
* @param array $args
* @param $queue
* @return Resque_JobInterface
* @throws Resque_Exception
* @return \Resque\Job\JobInterface
* @throws \Resque\Exception
*/
public function create($className, $args, $queue)
{
if (!class_exists($className)) {
throw new Resque_Exception(
throw new \Resque\Exception(
'Could not find job class ' . $className . '.'
);
}
if (!method_exists($className, 'perform')) {
throw new Resque_Exception(
throw new \Resque\Exception(
'Job class ' . $className . ' does not contain a perform method.'
);
}
$instance = new $className;
$instance = new $className();
$instance->args = $args;
$instance->queue = $queue;
return $instance;

21
src/Resque/Job/FactoryInterface.php

@ -0,0 +1,21 @@
<?php
namespace Resque\Job;
/**
* Job Interface
*
* @package Resque/Job
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
interface FactoryInterface
{
/**
* @param $className
* @param array $args
* @param $queue
* @return \Resque\Job\JobInterface
*/
public function create($className, $args, $queue);
}

80
lib/Resque/Job.php → src/Resque/Job/Job.php

@ -1,14 +1,16 @@
<?php
namespace Resque\Job;
/**
* Resque job.
*
* @package Resque/Job
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Job
class Job
{
/**
* @var string The name of the queue that this job belongs to.
@ -16,7 +18,7 @@ class Resque_Job
public $queue;
/**
* @var Resque_Worker Instance of the Resque worker running this job.
* @var \Resque\Worker Instance of the Resque worker running this job.
*/
public $worker;
@ -26,12 +28,12 @@ class Resque_Job
public $payload;
/**
* @var object|Resque_JobInterface Instance of the class performing work for this job.
* @var object|\Resque\Job\JobInterface Instance of the class performing work for this job.
*/
private $instance;
/**
* @var Resque_Job_FactoryInterface
* @var \Resque\Job\FactoryInterface
*/
private $jobFactory;
@ -57,20 +59,20 @@ class Resque_Job
* @param string $id Unique identifier for tracking the job. Generated if not supplied.
*
* @return string
* @throws InvalidArgumentException
* @throws \InvalidArgumentException
*/
public static function create($queue, $class, $args = null, $monitor = false, $id = null)
{
if (is_null($id)) {
$id = Resque::generateJobId();
$id = \Resque\Resque::generateJobId();
}
if ($args !== null && !is_array($args)) {
throw new InvalidArgumentException(
throw new \InvalidArgumentException(
'Supplied $args must be an array.'
);
}
Resque::push($queue, [
\Resque\Resque::push($queue, [
'class' => $class,
'args' => [$args],
'id' => $id,
@ -78,7 +80,7 @@ class Resque_Job
]);
if ($monitor) {
Resque_Job_Status::create($id);
Status::create($id);
}
return $id;
@ -86,43 +88,43 @@ class Resque_Job
/**
* Find the next available job from the specified queue and return an
* instance of Resque_Job for it.
* instance of \Resque\Job\Job for it.
*
* @param string $queue The name of the queue to check for a job in.
* @return false|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
* @return false|object Null when there aren't any waiting jobs, instance of \Resque\Job\Job when a job was found.
*/
public static function reserve($queue)
{
$payload = Resque::pop($queue);
$payload = \Resque\Resque::pop($queue);
if (!is_array($payload)) {
return false;
}
return new Resque_Job($queue, $payload);
return new Job($queue, $payload);
}
/**
* Find the next available job from the specified queues using blocking list pop
* and return an instance of Resque_Job for it.
* and return an instance of \Resque\Job\Job for it.
*
* @param array $queues
* @param int $timeout
* @return false|object Null when there aren't any waiting jobs, instance of Resque_Job when a job was found.
* @return false|object Null when there aren't any waiting jobs, instance of \Resque\Job\Job when a job was found.
*/
public static function reserveBlocking(array $queues, $timeout = null)
{
$item = Resque::blpop($queues, $timeout);
$item = \Resque\Resque::blpop($queues, $timeout);
if (!is_array($item)) {
return false;
}
return new Resque_Job($item['queue'], $item['payload']);
return new Job($item['queue'], $item['payload']);
}
/**
* Update the status of the current job.
*
* @param int $status Status constant from Resque_Job_Status indicating the current status of a job.
* @param int $status Status constant from \Resque\Job\Status indicating the current status of a job.
*/
public function updateStatus($status): bool
{
@ -130,7 +132,7 @@ class Resque_Job
return false;
}
$statusInstance = new Resque_Job_Status($this->payload['id']);
$statusInstance = new Status($this->payload['id']);
$statusInstance->update($status);
return true;
}
@ -138,11 +140,11 @@ class Resque_Job
/**
* Return the status of the current job.
*
* @return int The status of the job as one of the Resque_Job_Status constants.
* @return int The status of the job as one of the \Resque\Job\Status constants.
*/
public function getStatus()
{
$status = new Resque_Job_Status($this->payload['id']);
$status = new Status($this->payload['id']);
return $status->get();
}
@ -162,7 +164,7 @@ 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.
* @return \Resque\Job\JobInterface Instance of the object that this job belongs to.
*/
public function getInstance()
{
@ -180,12 +182,12 @@ class Resque_Job
* associated with the job with the supplied arguments.
*
* @return bool
* @throws Resque_Exception When the job's class could not be found or it does not contain a perform method.
* @throws \Resque\Exception When the job's class could not be found or it does not contain a perform method.
*/
public function perform()
{
try {
Resque_Event::trigger('beforePerform', $this);
\Resque\Event::trigger('beforePerform', $this);
$instance = $this->getInstance();
if (method_exists($instance, 'setUp')) {
@ -198,9 +200,9 @@ class Resque_Job
$instance->tearDown();
}
Resque_Event::trigger('afterPerform', $this);
} // beforePerform/setUp have said don't perform this job. Return.
/** @noinspection PhpRedundantCatchClauseInspection */ catch (Resque_Job_DontPerform $e) {
\Resque\Event::trigger('afterPerform', $this);
} catch (DontPerform $e) {
/** @noinspection PhpRedundantCatchClauseInspection */
return false;
}
@ -214,20 +216,20 @@ class Resque_Job
*/
public function fail($exception)
{
Resque_Event::trigger('onFailure', [
\Resque\Event::trigger('onFailure', [
'exception' => $exception,
'job' => $this,
]);
$this->updateStatus(Resque_Job_Status::STATUS_FAILED);
Resque_Failure::create(
$this->updateStatus(Status::STATUS_FAILED);
\Resque\Failure\Failure::create(
$this->payload,
$exception,
$this->worker,
$this->queue
);
Resque_Stat::incr('failed');
Resque_Stat::incr('failed:' . $this->worker);
\Resque\Stat::incr('failed');
\Resque\Stat::incr('failed:' . $this->worker);
}
/**
@ -236,7 +238,7 @@ class Resque_Job
*/
public function recreate()
{
$status = new Resque_Job_Status($this->payload['id']);
$status = new Status($this->payload['id']);
$monitor = false;
if ($status->isTracking()) {
$monitor = true;
@ -266,10 +268,10 @@ class Resque_Job
}
/**
* @param Resque_Job_FactoryInterface $jobFactory
* @return Resque_Job
* @param FactoryInterface $jobFactory
* @return Job
*/
public function setJobFactory(Resque_Job_FactoryInterface $jobFactory)
public function setJobFactory(FactoryInterface $jobFactory)
{
$this->jobFactory = $jobFactory;
@ -277,12 +279,12 @@ class Resque_Job
}
/**
* @return Resque_Job_FactoryInterface
* @return FactoryInterface
*/
public function getJobFactory()
{
if ($this->jobFactory === null) {
$this->jobFactory = new Resque_Job_Factory();
$this->jobFactory = new Factory();
}
return $this->jobFactory;
}

4
lib/Resque/JobInterface.php → src/Resque/Job/JobInterface.php

@ -1,6 +1,8 @@
<?php
interface Resque_JobInterface
namespace Resque\Job;
interface JobInterface
{
/**
* @return bool

30
lib/Resque/Job/Status.php → src/Resque/Job/Status.php

@ -1,19 +1,21 @@
<?php
namespace Resque\Job;
/**
* Status tracker/information for a job.
*
* @package Resque/Job
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Job_Status
class Status
{
const STATUS_WAITING = 1;
const STATUS_RUNNING = 2;
const STATUS_FAILED = 3;
const STATUS_COMPLETE = 4;
public const STATUS_WAITING = 1;
public const STATUS_RUNNING = 2;
public const STATUS_FAILED = 3;
public const STATUS_COMPLETE = 4;
/**
* @var string The ID of the job this status class refers back to.
@ -57,7 +59,7 @@ class Resque_Job_Status
'updated' => time(),
'started' => time(),
];
Resque::redis()->set('job:' . $id . ':status', json_encode($statusPacket));
\Resque\Resque::redis()->set('job:' . $id . ':status', json_encode($statusPacket));
}
/**
@ -72,7 +74,7 @@ class Resque_Job_Status
return false;
}
if (!Resque::redis()->exists((string)$this)) {
if (!\Resque\Resque::redis()->exists((string)$this)) {
$this->isTracking = false;
return false;
}
@ -84,7 +86,7 @@ class Resque_Job_Status
/**
* Update the status indicator for the current job with a new status.
*
* @param int The status of the job (see constants in Resque_Job_Status)
* @param int The status of the job (see constants in \Resque\Job\Status)
*/
public function update($status)
{
@ -96,11 +98,11 @@ class Resque_Job_Status
'status' => $status,
'updated' => time(),
];
Resque::redis()->set((string)$this, json_encode($statusPacket));
\Resque\Resque::redis()->set((string)$this, json_encode($statusPacket));
// Expire the status for completed jobs after 24 hours
if (in_array($status, self::$completeStatuses)) {
Resque::redis()->expire((string)$this, 86400);
\Resque\Resque::redis()->expire((string)$this, 86400);
}
}
@ -108,7 +110,7 @@ class Resque_Job_Status
* Fetch the status for the job being monitored.
*
* @return mixed False if the status is not being monitored, otherwise the status as
* as an integer, based on the Resque_Job_Status constants.
* as an integer, based on the \Resque\Job\Status constants.
*/
public function get()
{
@ -116,7 +118,7 @@ class Resque_Job_Status
return false;
}
$statusPacket = json_decode(Resque::redis()->get((string)$this), true);
$statusPacket = json_decode(\Resque\Resque::redis()->get((string)$this), true);
if (!$statusPacket) {
return false;
}
@ -129,7 +131,7 @@ class Resque_Job_Status
*/
public function stop()
{
Resque::redis()->del((string)$this);
\Resque\Resque::redis()->del((string)$this);
}
/**

26
lib/Resque/Log.php → src/Resque/Log.php

@ -1,14 +1,16 @@
<?php
namespace Resque;
/**
* Resque default logger PSR-3 compliant
*
* @package Resque/Stat
* @author Chris Boulton <chris@bigcommerce.com>
* @package Resque
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Log extends Psr\Log\AbstractLogger
class Log extends \Psr\Log\AbstractLogger
{
public $logLevel;
@ -28,16 +30,16 @@ class Resque_Log extends Psr\Log\AbstractLogger
public function log($level, $message, array $context = [])
{
$logLevels = [
"emergency",
"alert",
"critical",
"error",
"warning",
"notice",
"info",
"debug"
"emergency",
"alert",
"critical",
"error",
"warning",
"notice",
"info",
"debug",
];
/**
* Only log things with a higher level than the current log level.
* e.g If set as 'alert' will only alert for 'emergency' and 'alert' logs.

32
lib/Resque/Redis.php → src/Resque/Redis.php

@ -1,18 +1,20 @@
<?php
namespace Resque;
/**
* Set up phpredis connection
*
* @package Resque/Redis
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Redis
class Redis
{
/**
* Redis Client
* @var Credis_Client
* @var \Credis_Client
*/
private $driver;
@ -25,17 +27,17 @@ class Resque_Redis
/**
* A default host to connect to
*/
const DEFAULT_HOST = 'localhost';
public const DEFAULT_HOST = 'localhost';
/**
* The default Redis port
*/
const DEFAULT_PORT = 6379;
public const DEFAULT_PORT = 6379;
/**
* The default Redis Database number
*/
const DEFAULT_DATABASE = 0;
public const DEFAULT_DATABASE = 0;
/**
* @var array List of all commands in Redis that supply a key as their
@ -116,8 +118,8 @@ class Resque_Redis
* @param string|array $server A DSN or array
* @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.
* @param object $client Optional Credis_Client instance instantiated by you
* @throws Resque_RedisException
* @param object $client Optional \Credis_Client instance instantiated by you
* @throws \Resque\RedisException
*/
public function __construct($server, $database = null, $client = null)
{
@ -131,7 +133,7 @@ class Resque_Redis
$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->driver = new \Credis_Client($host, $port, $timeout, $persistent);
$this->driver->setMaxConnectRetries($maxRetries);
if ($password) {
$this->driver->auth($password);
@ -145,8 +147,8 @@ class Resque_Redis
if ($database !== null) {
$this->driver->select($database);
}
} catch (Exception $e) {
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
} catch (\Exception $e) {
throw new RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
}
}
@ -185,7 +187,7 @@ class Resque_Redis
// Check the URI scheme
$validSchemes = ['redis', 'tcp'];
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.
@ -238,7 +240,7 @@ class Resque_Redis
{
if (in_array($name, $this->keyCommands)) {
if (is_array($args[0])) {
foreach ($args[0] AS $i => $v) {
foreach ($args[0] as $i => $v) {
$args[0][$i] = self::$defaultNamespace . $v;
}
} else {
@ -247,8 +249,8 @@ class Resque_Redis
}
try {
return $this->driver->__call($name, $args);
} catch (CredisException $e) {
throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
} catch (\CredisException $e) {
throw new RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
}
}

6
lib/Resque/RedisException.php → src/Resque/RedisException.php

@ -1,14 +1,16 @@
<?php
namespace Resque;
/**
* Redis related exceptions
*
* @package Resque
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_RedisException extends Resque_Exception
class RedisException extends \Exception
{
}

43
lib/Resque.php → src/Resque/Resque.php

@ -1,18 +1,20 @@
<?php
namespace Resque;
/**
* Base Resque class.
*
* @package Resque
* @author Chris Boulton <chris@bigcommerce.com>
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque
{
const VERSION = '1.4.7';
public const VERSION = '2.0.0';
const DEFAULT_INTERVAL = 5;
public const DEFAULT_INTERVAL = 5;
/**
* @var Resque_Redis Instance of Resque_Redis that talks to redis.
@ -50,9 +52,9 @@ class Resque
/**
* Return an instance of the Resque_Redis class instantiated for Resque.
*
* @return Resque_Redis Instance of Resque_Redis.
* @return \Resque\Redis Instance of Resque_Redis.
*
* @throws Resque_RedisException
* @throws \Resque\RedisException
*/
public static function redis()
{
@ -63,7 +65,7 @@ class Resque
if (is_callable(self::$redisServer)) {
self::$redis = call_user_func(self::$redisServer, self::$redisDatabase);
} else {
self::$redis = new Resque_Redis(self::$redisServer, self::$redisDatabase);
self::$redis = new \Resque\Redis(self::$redisServer, self::$redisDatabase);
}
return self::$redis;
@ -90,7 +92,7 @@ class Resque
$pid = pcntl_fork();
if ($pid === -1) {
throw new RuntimeException('Unable to fork child worker.');
throw new \RuntimeException('Unable to fork child worker.');
}
return $pid;
@ -179,7 +181,7 @@ class Resque
*/
public static function blpop(array $queues, $timeout)
{
$list = array();
$list = [];
foreach ($queues as $queue) {
$list[] = 'queue:' . $queue;
}
@ -228,20 +230,20 @@ class Resque
public static function enqueue($queue, $class, $args = null, $trackStatus = false)
{
$id = Resque::generateJobId();
$hookParams = array(
$hookParams = [
'class' => $class,
'args' => $args,
'queue' => $queue,
'id' => $id,
);
];
try {
Resque_Event::trigger('beforeEnqueue', $hookParams);
} catch (Resque_Job_DontCreate $e) {
\Resque\Event::trigger('beforeEnqueue', $hookParams);
} catch (\Resque\Job\DontCreate $e) {
return false;
}
Resque_Job::create($queue, $class, $args, $trackStatus, $id);
Resque_Event::trigger('afterEnqueue', $hookParams);
\Resque\Job\Job::create($queue, $class, $args, $trackStatus, $id);
\Resque\Event::trigger('afterEnqueue', $hookParams);
return $id;
}
@ -251,11 +253,11 @@ class Resque
*
* @param string $queue Queue to fetch next available job from.
*
* @return false|object|Resque_Job
* @return false|object|\Resque\Job\Job
*/
public static function reserve($queue)
{
return Resque_Job::reserve($queue);
return \Resque\Job\Job::reserve($queue);
}
/**
@ -347,8 +349,11 @@ class Resque
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
} elseif (is_array($val)) {
$decodedArgs = (array)$decoded['args'][0];
if ($decoded['class'] == $key &&
count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) {
if (
$decoded['class'] == $key
&& count($decodedArgs) > 0
&& count(array_diff($decodedArgs, $val)) == 0
) {
return true;
}
# class name with ID, example: item[0] = ['class' => 'id']
@ -369,7 +374,7 @@ class Resque
* @params string $queue the name of the queue
* @param $queue
* @return integer number of deleted items belongs to this list
* @throws Resque_RedisException
* @throws \Resque\RedisException
*/
private static function removeList($queue)
{

10
lib/Resque/Stat.php → src/Resque/Stat.php

@ -1,14 +1,16 @@
<?php
namespace Resque;
/**
* Resque statistic management (jobs processed, failed, etc)
*
* @package Resque/Stat
* @author Chris Boulton <chris@bigcommerce.com>
* @package Resque
* @author Daniel Mason <daniel@m2.nz>
* @license http://www.opensource.org/licenses/mit-license.php
*/
class Resque_Stat
class Stat
{
/**
* Get the value of the supplied statistic counter for the specified statistic.