v2.3.0 - Update packages
Some checks failed
CI / Linter (push) Has been cancelled
CI / PHPTest (8.1) (push) Has been cancelled
CI / PHPTest (8.2) (push) Has been cancelled

This commit is contained in:
Daniel Mason 2024-09-04 18:50:32 +12:00
parent 5ef4a63a6e
commit 2c995bd613
Signed by: idanoo
GPG Key ID: 387387CDBC02F132
8 changed files with 170 additions and 114 deletions

View File

@ -1,3 +1,6 @@
# 2.3.0 (2024-09-04)
- Update packages
# 2.2.0 (2023-03-20) # 2.2.0 (2023-03-20)
- Update pacakges - Update pacakges
- Bump requirements to PHP >= 8.1 - Bump requirements to PHP >= 8.1

131
composer.lock generated
View File

@ -8,16 +8,16 @@
"packages": [ "packages": [
{ {
"name": "colinmollenhour/credis", "name": "colinmollenhour/credis",
"version": "v1.16.0", "version": "v1.16.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/colinmollenhour/credis.git", "url": "https://github.com/colinmollenhour/credis.git",
"reference": "5641140e14a9679f5a6f66c97268727f9558b881" "reference": "f11a89fd068d3e5db0c2b5a9ba8663bc36162e95"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/colinmollenhour/credis/zipball/5641140e14a9679f5a6f66c97268727f9558b881", "url": "https://api.github.com/repos/colinmollenhour/credis/zipball/f11a89fd068d3e5db0c2b5a9ba8663bc36162e95",
"reference": "5641140e14a9679f5a6f66c97268727f9558b881", "reference": "f11a89fd068d3e5db0c2b5a9ba8663bc36162e95",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -49,9 +49,9 @@
"homepage": "https://github.com/colinmollenhour/credis", "homepage": "https://github.com/colinmollenhour/credis",
"support": { "support": {
"issues": "https://github.com/colinmollenhour/credis/issues", "issues": "https://github.com/colinmollenhour/credis/issues",
"source": "https://github.com/colinmollenhour/credis/tree/v1.16.0" "source": "https://github.com/colinmollenhour/credis/tree/v1.16.1"
}, },
"time": "2023-10-26T17:02:51+00:00" "time": "2024-07-04T15:08:03+00:00"
}, },
{ {
"name": "psr/log", "name": "psr/log",
@ -255,16 +255,16 @@
}, },
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.11.1", "version": "1.12.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/myclabs/DeepCopy.git",
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
"reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -272,11 +272,12 @@
}, },
"conflict": { "conflict": {
"doctrine/collections": "<1.6.8", "doctrine/collections": "<1.6.8",
"doctrine/common": "<2.13.3 || >=3,<3.2.2" "doctrine/common": "<2.13.3 || >=3 <3.2.2"
}, },
"require-dev": { "require-dev": {
"doctrine/collections": "^1.6.8", "doctrine/collections": "^1.6.8",
"doctrine/common": "^2.13.3 || ^3.2.2", "doctrine/common": "^2.13.3 || ^3.2.2",
"phpspec/prophecy": "^1.10",
"phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13"
}, },
"type": "library", "type": "library",
@ -302,7 +303,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/myclabs/DeepCopy/issues", "issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0"
}, },
"funding": [ "funding": [
{ {
@ -310,20 +311,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2023-03-08T13:26:56+00:00" "time": "2024-06-12T14:39:25+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
"version": "v5.0.2", "version": "v5.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/nikic/PHP-Parser.git", "url": "https://github.com/nikic/PHP-Parser.git",
"reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1",
"reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -334,7 +335,7 @@
}, },
"require-dev": { "require-dev": {
"ircmaxell/php-yacc": "^0.0.7", "ircmaxell/php-yacc": "^0.0.7",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" "phpunit/phpunit": "^9.0"
}, },
"bin": [ "bin": [
"bin/php-parse" "bin/php-parse"
@ -366,9 +367,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/nikic/PHP-Parser/issues", "issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0"
}, },
"time": "2024-03-05T20:51:40+00:00" "time": "2024-07-01T20:03:41+00:00"
}, },
{ {
"name": "phar-io/manifest", "name": "phar-io/manifest",
@ -552,35 +553,35 @@
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "9.2.31", "version": "9.2.32",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "48c34b5d8d983006bd2adc2d0de92963b9155965" "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/48c34b5d8d983006bd2adc2d0de92963b9155965", "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/85402a822d1ecf1db1096959413d35e1c37cf1a5",
"reference": "48c34b5d8d983006bd2adc2d0de92963b9155965", "reference": "85402a822d1ecf1db1096959413d35e1c37cf1a5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-dom": "*", "ext-dom": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"nikic/php-parser": "^4.18 || ^5.0", "nikic/php-parser": "^4.19.1 || ^5.1.0",
"php": ">=7.3", "php": ">=7.3",
"phpunit/php-file-iterator": "^3.0.3", "phpunit/php-file-iterator": "^3.0.6",
"phpunit/php-text-template": "^2.0.2", "phpunit/php-text-template": "^2.0.4",
"sebastian/code-unit-reverse-lookup": "^2.0.2", "sebastian/code-unit-reverse-lookup": "^2.0.3",
"sebastian/complexity": "^2.0", "sebastian/complexity": "^2.0.3",
"sebastian/environment": "^5.1.2", "sebastian/environment": "^5.1.5",
"sebastian/lines-of-code": "^1.0.3", "sebastian/lines-of-code": "^1.0.4",
"sebastian/version": "^3.0.1", "sebastian/version": "^3.0.2",
"theseer/tokenizer": "^1.2.0" "theseer/tokenizer": "^1.2.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^9.3" "phpunit/phpunit": "^9.6"
}, },
"suggest": { "suggest": {
"ext-pcov": "PHP extension that provides line coverage", "ext-pcov": "PHP extension that provides line coverage",
@ -589,7 +590,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "9.2-dev" "dev-main": "9.2.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -618,7 +619,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.31" "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.32"
}, },
"funding": [ "funding": [
{ {
@ -626,7 +627,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-03-02T06:37:42+00:00" "time": "2024-08-22T04:23:01+00:00"
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
@ -871,45 +872,45 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "9.6.17", "version": "9.6.20",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "1a156980d78a6666721b7e8e8502fe210b587fcd" "reference": "49d7820565836236411f5dc002d16dd689cde42f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1a156980d78a6666721b7e8e8502fe210b587fcd", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/49d7820565836236411f5dc002d16dd689cde42f",
"reference": "1a156980d78a6666721b7e8e8502fe210b587fcd", "reference": "49d7820565836236411f5dc002d16dd689cde42f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/instantiator": "^1.3.1 || ^2", "doctrine/instantiator": "^1.5.0 || ^2",
"ext-dom": "*", "ext-dom": "*",
"ext-json": "*", "ext-json": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-xml": "*", "ext-xml": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"myclabs/deep-copy": "^1.10.1", "myclabs/deep-copy": "^1.12.0",
"phar-io/manifest": "^2.0.3", "phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.0.2", "phar-io/version": "^3.2.1",
"php": ">=7.3", "php": ">=7.3",
"phpunit/php-code-coverage": "^9.2.28", "phpunit/php-code-coverage": "^9.2.31",
"phpunit/php-file-iterator": "^3.0.5", "phpunit/php-file-iterator": "^3.0.6",
"phpunit/php-invoker": "^3.1.1", "phpunit/php-invoker": "^3.1.1",
"phpunit/php-text-template": "^2.0.3", "phpunit/php-text-template": "^2.0.4",
"phpunit/php-timer": "^5.0.2", "phpunit/php-timer": "^5.0.3",
"sebastian/cli-parser": "^1.0.1", "sebastian/cli-parser": "^1.0.2",
"sebastian/code-unit": "^1.0.6", "sebastian/code-unit": "^1.0.8",
"sebastian/comparator": "^4.0.8", "sebastian/comparator": "^4.0.8",
"sebastian/diff": "^4.0.3", "sebastian/diff": "^4.0.6",
"sebastian/environment": "^5.1.3", "sebastian/environment": "^5.1.5",
"sebastian/exporter": "^4.0.5", "sebastian/exporter": "^4.0.6",
"sebastian/global-state": "^5.0.1", "sebastian/global-state": "^5.0.7",
"sebastian/object-enumerator": "^4.0.3", "sebastian/object-enumerator": "^4.0.4",
"sebastian/resource-operations": "^3.0.3", "sebastian/resource-operations": "^3.0.4",
"sebastian/type": "^3.2", "sebastian/type": "^3.2.1",
"sebastian/version": "^3.0.2" "sebastian/version": "^3.0.2"
}, },
"suggest": { "suggest": {
@ -954,7 +955,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.17" "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.20"
}, },
"funding": [ "funding": [
{ {
@ -970,7 +971,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-02-23T13:14:51+00:00" "time": "2024-07-10T11:45:39+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@ -1937,16 +1938,16 @@
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
"version": "3.9.0", "version": "3.10.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git",
"reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b" "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/d63cee4890a8afaf86a22e51ad4d97c91dd4579b", "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/86e5f5dd9a840c46810ebe5ff1885581c42a3017",
"reference": "d63cee4890a8afaf86a22e51ad4d97c91dd4579b", "reference": "86e5f5dd9a840c46810ebe5ff1885581c42a3017",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2013,7 +2014,7 @@
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2024-02-16T15:06:51+00:00" "time": "2024-07-21T23:26:44+00:00"
}, },
{ {
"name": "theseer/tokenizer", "name": "theseer/tokenizer",

View File

@ -62,7 +62,7 @@ class Status
\Resque\Resque::redis()->set( \Resque\Resque::redis()->set(
'job:' . $id . ':status', 'job:' . $id . ':status',
json_encode($statusPacket), json_encode($statusPacket),
['ex' => (86400 * 2)], ['ex' => \Resque\Redis::DEFAULT_REDIS_TTL],
); );
} }
@ -106,7 +106,7 @@ class Status
\Resque\Resque::redis()->set( \Resque\Resque::redis()->set(
(string)$this, (string)$this,
json_encode($statusPacket), json_encode($statusPacket),
['ex' => (86400 * 2)], ['ex' => \Resque\Redis::DEFAULT_REDIS_TTL],
); );
} }

View File

@ -14,12 +14,14 @@ class Redis
{ {
/** /**
* Redis Client * Redis Client
*
* @var \Credis_Client * @var \Credis_Client
*/ */
private $driver; private $driver;
/** /**
* Redis namespace * Redis namespace
*
* @var string * @var string
*/ */
private static $defaultNamespace = 'resque:'; private static $defaultNamespace = 'resque:';
@ -39,6 +41,11 @@ class Redis
*/ */
public const DEFAULT_DATABASE = 0; public const DEFAULT_DATABASE = 0;
/**
* Default Redis TTL (2 days)
*/
public const DEFAULT_REDIS_TTL = 172800;
/** /**
* @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.
@ -114,6 +121,7 @@ class Redis
if (substr($namespace, -1) !== ':' && $namespace != '') { if (substr($namespace, -1) !== ':' && $namespace != '') {
$namespace .= ':'; $namespace .= ':';
} }
self::$defaultNamespace = $namespace; self::$defaultNamespace = $namespace;
} }

View File

@ -12,7 +12,7 @@ namespace Resque;
class Resque class Resque
{ {
public const VERSION = '2.1.0'; public const VERSION = '2.3.0';
public const DEFAULT_INTERVAL = 5; public const DEFAULT_INTERVAL = 5;

View File

@ -38,7 +38,7 @@ class Stat
$set = Resque::redis()->set( $set = Resque::redis()->set(
'stat:' . $stat, 'stat:' . $stat,
$by, $by,
['ex' => (86400 * 2), 'nx'], ['ex' => Redis::DEFAULT_REDIS_TTL, 'nx'],
); );
// If it already exists, return the incrby value // If it already exists, return the incrby value

View File

@ -83,6 +83,7 @@ class Worker
/** /**
* Return all workers known to Resque as instantiated instances. * Return all workers known to Resque as instantiated instances.
*
* @return array * @return array
*/ */
public static function all(): array public static function all(): array
@ -102,8 +103,10 @@ class Worker
/** /**
* Given a worker ID, check if it is registered/valid. * Given a worker ID, check if it is registered/valid.
* *
* @param string $workerId ID of the worker. * @param string $workerId ID of the worker
* @return boolean True if the worker exists, false if not. *
* @return boolean True if the worker exists, false if not
*
* @throws Resque_RedisException * @throws Resque_RedisException
*/ */
public static function exists($workerId): bool public static function exists($workerId): bool
@ -114,8 +117,10 @@ class Worker
/** /**
* Given a worker ID, find it and return an instantiated worker class for it. * Given a worker ID, find it and return an instantiated worker class for it.
* *
* @param string $workerId The ID of the worker. * @param string $workerId The ID of the worker
* @return bool|Resque_Worker *
* @return Resque_Worker|bool
*
* @throws Resque_RedisException * @throws Resque_RedisException
*/ */
public static function find($workerId) public static function find($workerId)
@ -123,11 +128,13 @@ class Worker
if (false === strpos($workerId, ":") || !self::exists($workerId)) { if (false === strpos($workerId, ":") || !self::exists($workerId)) {
return false; return false;
} }
/** @noinspection PhpUnusedLocalVariableInspection */ /** @noinspection PhpUnusedLocalVariableInspection */
list($hostname, $pid, $queues) = explode(':', $workerId, 3); list($hostname, $pid, $queues) = explode(':', $workerId, 3);
$queues = explode(',', $queues); $queues = explode(',', $queues);
$worker = new self($queues); $worker = new self($queues);
$worker->setId($workerId); $worker->setId($workerId);
return $worker; return $worker;
} }
@ -135,8 +142,10 @@ class Worker
* Set the ID of this worker to a given ID string. * Set the ID of this worker to a given ID string.
* *
* @param string $workerId ID for the worker. * @param string $workerId ID for the worker.
*
* @return void
*/ */
public function setId($workerId) public function setId($workerId): void
{ {
$this->id = $workerId; $this->id = $workerId;
} }
@ -150,9 +159,11 @@ class Worker
* @param int $interval How often to check for new jobs across the queues. * @param int $interval How often to check for new jobs across the queues.
* @param bool $blocking * @param bool $blocking
* *
* @return void
*
* @throws Resque_RedisException * @throws Resque_RedisException
*/ */
public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false) public function work($interval = Resque::DEFAULT_INTERVAL, $blocking = false): void
{ {
$this->updateProcLine('Starting'); $this->updateProcLine('Starting');
$this->startup(); $this->startup();
@ -251,11 +262,13 @@ class Worker
} }
/** /**
* Process a single job. * Process a single job
* *
* @param \Resque\Job\Job $job The job to be processed. * @param \Resque\Job\Job $job The job to be processed
*
* @return void
*/ */
public function perform(\Resque\Job\Job $job) public function perform(\Resque\Job\Job $job): void
{ {
try { try {
Event::trigger('afterFork', $job); Event::trigger('afterFork', $job);
@ -273,7 +286,8 @@ class Worker
/** /**
* @param bool $blocking * @param bool $blocking
* @param int $timeout * @param int $timeout
* @return object|boolean Instance of \Resque\Job\Job if a job is found, false if not. *
* @return object|boolean - Instance of \Resque\Job\Job if a job is found, false if not
*/ */
public function reserve($blocking = false, $timeout = null) public function reserve($blocking = false, $timeout = null)
{ {
@ -304,16 +318,17 @@ class Worker
/** /**
* Return an array containing all of the queues that this worker should use * Return an array containing all of the queues that this worker should use
* when searching for jobs. * when searching for jobs
* *
* If * is found in the list of queues, every queue will be searched in * If * is found in the list of queues, every queue will be searched in
* alphabetic order. (@param boolean $fetch If true, and the queue is set to *, will fetch * alphabetic order. (@param boolean $fetch If true, and the queue is set to *, will fetch
* all queue names from redis. * all queue names from redis
* @return array Array of associated queues.
* @see $fetch)
* *
* @param boolean $fetch
*
* @return array Array of associated queues
*/ */
public function queues($fetch = true) public function queues(bool $fetch = true): array
{ {
if (!in_array('*', $this->queues) || $fetch == false) { if (!in_array('*', $this->queues) || $fetch == false) {
return $this->queues; return $this->queues;
@ -321,13 +336,16 @@ class Worker
$queues = Resque::queues(); $queues = Resque::queues();
sort($queues); sort($queues);
return $queues; return $queues;
} }
/** /**
* Perform necessary actions to start a worker. * Perform necessary actions to start a worker
*
* @return void
*/ */
private function startup() private function startup(): void
{ {
$this->registerSigHandlers(); $this->registerSigHandlers();
$this->pruneDeadWorkers(); $this->pruneDeadWorkers();
@ -340,9 +358,11 @@ class Worker
* the name of the currently running process to indicate the current state * the name of the currently running process to indicate the current state
* of a worker. * of a worker.
* *
* @param string $status The updated process title. * @param string $status The updated process title
*
* @return void
*/ */
private function updateProcLine($status) private function updateProcLine($status): void
{ {
$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') {
@ -359,8 +379,10 @@ class Worker
* INT: Shutdown immediately and stop processing jobs. * INT: Shutdown immediately and stop processing jobs.
* QUIT: Shutdown after the current job finishes processing. * QUIT: Shutdown after the current job finishes processing.
* USR1: Kill the forked child immediately and continue processing jobs. * USR1: Kill the forked child immediately and continue processing jobs.
*
* @return void
*/ */
private function registerSigHandlers() private function registerSigHandlers(): void
{ {
if (!function_exists('pcntl_signal')) { if (!function_exists('pcntl_signal')) {
return; return;
@ -376,9 +398,11 @@ class Worker
} }
/** /**
* Signal handler callback for USR2, pauses processing of new jobs. * Signal handler callback for USR2, pauses processing of new jobs
*
* @return void
*/ */
public function pauseProcessing() public function pauseProcessing(): void
{ {
$this->logger->log(\Psr\Log\LogLevel::NOTICE, 'USR2 received; pausing job processing'); $this->logger->log(\Psr\Log\LogLevel::NOTICE, 'USR2 received; pausing job processing');
$this->paused = true; $this->paused = true;
@ -387,8 +411,10 @@ class Worker
/** /**
* Signal handler callback for CONT, resumes worker allowing it to pick * Signal handler callback for CONT, resumes worker allowing it to pick
* up new jobs. * up new jobs.
*
* @return void
*/ */
public function unPauseProcessing() public function unPauseProcessing(): void
{ {
$this->logger->log(\Psr\Log\LogLevel::NOTICE, 'CONT received; resuming job processing'); $this->logger->log(\Psr\Log\LogLevel::NOTICE, 'CONT received; resuming job processing');
$this->paused = false; $this->paused = false;
@ -397,8 +423,10 @@ class Worker
/** /**
* Schedule a worker for shutdown. Will finish processing the current job * Schedule a worker for shutdown. Will finish processing the current job
* and when the timeout interval is reached, the worker will shut down. * and when the timeout interval is reached, the worker will shut down.
*
* @return void
*/ */
public function shutdown() public function shutdown(): void
{ {
$this->shutdown = true; $this->shutdown = true;
$this->logger->log(\Psr\Log\LogLevel::NOTICE, 'Shutting down'); $this->logger->log(\Psr\Log\LogLevel::NOTICE, 'Shutting down');
@ -407,8 +435,10 @@ class Worker
/** /**
* Force an immediate shutdown of the worker, killing any child jobs * Force an immediate shutdown of the worker, killing any child jobs
* currently running. * currently running.
*
* @return void
*/ */
public function shutdownNow() public function shutdownNow(): void
{ {
$this->shutdown(); $this->shutdown();
$this->killChild(); $this->killChild();
@ -417,8 +447,10 @@ class Worker
/** /**
* Kill a forked child job immediately. The job it is processing will not * Kill a forked child job immediately. The job it is processing will not
* be completed. * be completed.
*
* @return void
*/ */
public function killChild() public function killChild(): void
{ {
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.');
@ -447,8 +479,10 @@ class Worker
* This is a form of garbage collection to handle cases where the * This is a form of garbage collection to handle cases where the
* server may have been killed and the Resque workers did not die gracefully * server may have been killed and the Resque workers did not die gracefully
* and therefore leave state information in Redis. * and therefore leave state information in Redis.
*
* @return void
*/ */
public function pruneDeadWorkers() public function pruneDeadWorkers(): void
{ {
$workerPids = $this->workerPids(); $workerPids = $this->workerPids();
$workers = self::all(); $workers = self::all();
@ -474,7 +508,7 @@ class Worker
* *
* @return array Array of Resque worker process IDs. * @return array Array of Resque worker process IDs.
*/ */
public function workerPids() public function workerPids(): array
{ {
$pids = []; $pids = [];
exec('ps -A -o pid,command | grep [r]esque', $cmdOutput); exec('ps -A -o pid,command | grep [r]esque', $cmdOutput);
@ -496,14 +530,16 @@ class Worker
Resque::redis()->set( Resque::redis()->set(
'worker:' . (string)$this . ':started', 'worker:' . (string)$this . ':started',
date('D M d H:i:s T Y'), date('D M d H:i:s T Y'),
['ex' => (86400 * 2)], ['ex' => Redis::DEFAULT_REDIS_TTL],
); );
} }
/** /**
* Unregister this worker in Redis. (shutdown etc) * Unregister this worker in Redis. (shutdown etc)
*
* @return void
*/ */
public function unregisterWorker() public function unregisterWorker(): void
{ {
if (is_object($this->currentJob)) { if (is_object($this->currentJob)) {
$this->currentJob->fail(new \Resque\Job\DirtyExitException()); $this->currentJob->fail(new \Resque\Job\DirtyExitException());
@ -518,12 +554,15 @@ class Worker
} }
/** /**
* Tell Redis which job we're currently working on. * Tell Redis which job we're currently working on
*
* @param \Resque\Job\Job $job \Resque\Job\Job instance containing the job we're working on
*
* @return void
* *
* @param \Resque\Job\Job $job \Resque\Job\Job instance containing the job we're working on.
* @throws Resque_RedisException * @throws Resque_RedisException
*/ */
public function workingOn(\Resque\Job\Job $job) public function workingOn(\Resque\Job\Job $job): void
{ {
$job->worker = $this; $job->worker = $this;
$this->currentJob = $job; $this->currentJob = $job;
@ -537,15 +576,17 @@ class Worker
Resque::redis()->set( Resque::redis()->set(
'worker:' . $job->worker, 'worker:' . $job->worker,
$data, $data,
['ex' => (86400 * 2)], ['ex' => Redis::DEFAULT_REDIS_TTL],
); );
} }
/** /**
* Notify Redis that we've finished working on a job, clearing the working * Notify Redis that we've finished working on a job, clearing the working
* state and incrementing the job stats. * state and incrementing the job stats
*
* @return void
*/ */
public function doneWorking() public function doneWorking(): void
{ {
$this->currentJob = null; $this->currentJob = null;
Stat::incr('processed'); Stat::incr('processed');
@ -554,28 +595,29 @@ class Worker
} }
/** /**
* Generate a string representation of this worker. * Generate a string representation of this worker
* *
* @return string String identifier for this worker instance. * @return string String identifier for this worker instance
*/ */
public function __toString() public function __toString(): string
{ {
return $this->id; return (string) $this->id;
} }
/** /**
* Return an object describing the job this worker is currently working on. * Return an object describing the job this worker is currently working on
* *
* @return array Array with details of current job. * @return array Array with details of current job
*/ */
public function job(): array public function job(): array
{ {
$job = Resque::redis()->get('worker:' . $this); $job = Resque::redis()->get('worker:' . $this);
return $job ? json_decode($job, true) : []; return $job ? json_decode($job, true) : [];
} }
/** /**
* Get a statistic belonging to this worker. * Get a statistic belonging to this worker
* *
* @param string $stat Statistic to fetch. * @param string $stat Statistic to fetch.
* *
@ -590,8 +632,10 @@ class Worker
* Inject the logging object into the worker * Inject the logging object into the worker
* *
* @param \Psr\Log\LoggerInterface $logger * @param \Psr\Log\LoggerInterface $logger
*
* @return void
*/ */
public function setLogger(\Psr\Log\LoggerInterface $logger) public function setLogger(\Psr\Log\LoggerInterface $logger): void
{ {
$this->logger = $logger; $this->logger = $logger;
} }

View File

@ -17,7 +17,7 @@ class RedisTest extends TestCase
$this->redis->set( $this->redis->set(
'testKey', 'testKey',
24, 24,
['ex' => 3600], ['ex' => \Resque\Redis::DEFAULT_REDIS_TTL],
); );
$val = $this->redis->get("testKey"); $val = $this->redis->get("testKey");