diff --git a/CHANGELOG.md b/CHANGELOG.md index b56b18c..9ba2db8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 3.1.0 (2026-05-20) +- Reduce redis calls across php-resque +- Reduce N+1 issues in queue lookup loop +- Remove status logic. Unusable at scale. (Removed 4th param in enqueue/create) + # 3.0.0 (2026-05-04) - Update PHP to >=8.3 - Update packages diff --git a/HOWITWORKS.md b/HOWITWORKS.md index 66fbbfa..b0c2394 100644 --- a/HOWITWORKS.md +++ b/HOWITWORKS.md @@ -13,15 +13,9 @@ What happens when you call `Resque::enqueue()`? 3. `\Resque\Job::create()` generates a job ID (a "token" in most of the docs) 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 -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 +5. `\Resque\Job::create()` returns control to `Resque::enqueue()`, with the job ID as a return value -8. `Resque::enqueue()` triggers the `afterEnqueue` event, then returns control +6. `Resque::enqueue()` triggers the `afterEnqueue` event, then returns control to your application, again with the job ID as its return value ## Workers At Work ## @@ -72,8 +66,7 @@ How do the workers process the queues? 2. `\Resque\Worker::work()` calls `\Resque\Worker->workingOn()` with the new `\Resque\Job` object as its argument 3. `\Resque\Worker->workingOn()` does some reference assignments to help keep - track of the worker/job relationship, then updates the job status from - `WAITING` to `RUNNING` + track of the worker/job relationship 4. `\Resque\Worker->workingOn()` stores the new `\Resque\Job` object's payload in a Redis key associated to the worker itself (this is to prevent the job from being lost indefinitely, but does rely on that PID never being @@ -87,18 +80,17 @@ How do the workers process the queues? 2. If the exit status is not 0, the worker calls `\Resque\Job->fail()` with 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 + 4. `\Resque\Job->fail()` calls `\Resque\Failure::create()` with the job 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 + 5. `\Resque\Failure::create()` creates a new object of whatever type has been set as the `\Resque\Failure` "backend" handler; by default, this is 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 + 6. `\Resque\Job->fail()` increments two failure counters in Redis: one for a total count, and one for the worker - 8. `\Resque\Job->fail()` returns control to the worker (still in + 7. `\Resque\Job->fail()` returns control to the worker (still in `\Resque\Worker::work()`) without a value * Job 1. The job calls `\Resque\Worker->perform()` with the `\Resque\Job` as its @@ -138,8 +130,7 @@ How do the workers process the queues? `\Resque\Worker->perform()`; any other situation returns the value `TRUE` along with control, instead 17. The `try...catch` block in `\Resque\Worker->perform()` ends - 18. `\Resque\Worker->perform()` updates the job status from `RUNNING` to - `COMPLETE`, then returns control, with no value, to the worker (again + 18. `\Resque\Worker->perform()` returns control, with no value, to the worker (again still in `\Resque\Worker::work()`) 19. `\Resque\Worker::work()` calls `exit(0)` to terminate the job process cleanly diff --git a/README.md b/README.md index d05ae2b..537be49 100644 --- a/README.md +++ b/README.md @@ -153,42 +153,6 @@ If no jobs are given, this method will dequeue all jobs matching the provided qu Resque::dequeue('default'); ``` -### Tracking Job Statuses ### - -php-resque has the ability to perform basic status tracking of a queued -job. The status information will allow you to check if a job is in the -queue, is currently being run, has finished, or has failed. - -To track the status of a job, pass `true` as the fourth argument to -`Resque::enqueue`. A token used for tracking the job status will be -returned: - -```php -$token = Resque::enqueue('default', '\App\MyJobClass', $args, true); -echo $token; -``` - -To fetch the status of a job: - -```php -$status = new \Resque\Job_Status($token); -echo $status->get(); // Outputs the status -``` - -Job statuses are defined as constants in the `\Resque\Job_Status` class. -Valid statuses include: - -* `\Resque\Job_Status::STATUS_WAITING` - Job is still queued -* `\Resque\Job_Status::STATUS_RUNNING` - Job is currently running -* `\Resque\Job_Status::STATUS_FAILED` - Job has failed -* `\Resque\Job_Status::STATUS_COMPLETE` - Job is complete -* `false` - Failed to fetch the status - is the token valid? - -Statuses are available for up to 24 hours after a job has completed -or failed, and are then automatically expired. A status can also -forcefully be expired by calling the `stop()` method on a status -class. - ## Workers ## Workers work in the exact same way as the Ruby workers. For complete diff --git a/composer.lock b/composer.lock index bbed7cc..f46b7fd 100644 --- a/composer.lock +++ b/composer.lock @@ -688,16 +688,16 @@ }, { "name": "phpunit/phpunit", - "version": "12.5.24", + "version": "12.5.25", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046" + "reference": "792c2980442dfce319226b88fa845b8b6de3b333" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d75dd30597caa80e72fad2ef7904601a30ef1046", - "reference": "d75dd30597caa80e72fad2ef7904601a30ef1046", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/792c2980442dfce319226b88fa845b8b6de3b333", + "reference": "792c2980442dfce319226b88fa845b8b6de3b333", "shasum": "" }, "require": { @@ -766,7 +766,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.24" + "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.25" }, "funding": [ { @@ -774,27 +774,27 @@ "type": "other" } ], - "time": "2026-05-01T04:21:04+00:00" + "time": "2026-05-13T03:56:57+00:00" }, { "name": "sebastian/cli-parser", - "version": "4.2.0", + "version": "4.2.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/cli-parser.git", - "reference": "90f41072d220e5c40df6e8635f5dafba2d9d4d04" + "reference": "7d05781b13f7dec9043a629a21d086ed74582a15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/90f41072d220e5c40df6e8635f5dafba2d9d4d04", - "reference": "90f41072d220e5c40df6e8635f5dafba2d9d4d04", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/7d05781b13f7dec9043a629a21d086ed74582a15", + "reference": "7d05781b13f7dec9043a629a21d086ed74582a15", "shasum": "" }, "require": { "php": ">=8.3" }, "require-dev": { - "phpunit/phpunit": "^12.0" + "phpunit/phpunit": "^12.5.25" }, "type": "library", "extra": { @@ -823,7 +823,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/cli-parser/issues", "security": "https://github.com/sebastianbergmann/cli-parser/security/policy", - "source": "https://github.com/sebastianbergmann/cli-parser/tree/4.2.0" + "source": "https://github.com/sebastianbergmann/cli-parser/tree/4.2.1" }, "funding": [ { @@ -843,7 +843,7 @@ "type": "tidelift" } ], - "time": "2025-09-14T09:36:45+00:00" + "time": "2026-05-17T05:29:34+00:00" }, { "name": "sebastian/comparator", @@ -1140,25 +1140,25 @@ }, { "name": "sebastian/exporter", - "version": "7.0.2", + "version": "7.0.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "016951ae10980765e4e7aee491eb288c64e505b7" + "reference": "c5e21b5de653ce0a769fb36f5cdfcb5e7a32cf23" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/016951ae10980765e4e7aee491eb288c64e505b7", - "reference": "016951ae10980765e4e7aee491eb288c64e505b7", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c5e21b5de653ce0a769fb36f5cdfcb5e7a32cf23", + "reference": "c5e21b5de653ce0a769fb36f5cdfcb5e7a32cf23", "shasum": "" }, "require": { "ext-mbstring": "*", "php": ">=8.3", - "sebastian/recursion-context": "^7.0" + "sebastian/recursion-context": "^7.0.1" }, "require-dev": { - "phpunit/phpunit": "^12.0" + "phpunit/phpunit": "^12.5.25" }, "type": "library", "extra": { @@ -1206,7 +1206,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/exporter/issues", "security": "https://github.com/sebastianbergmann/exporter/security/policy", - "source": "https://github.com/sebastianbergmann/exporter/tree/7.0.2" + "source": "https://github.com/sebastianbergmann/exporter/tree/7.0.3" }, "funding": [ { @@ -1226,7 +1226,7 @@ "type": "tidelift" } ], - "time": "2025-09-24T06:16:11+00:00" + "time": "2026-05-20T04:37:17+00:00" }, { "name": "sebastian/global-state", @@ -1304,24 +1304,24 @@ }, { "name": "sebastian/lines-of-code", - "version": "4.0.0", + "version": "4.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/lines-of-code.git", - "reference": "97ffee3bcfb5805568d6af7f0f893678fc076d2f" + "reference": "d543b8ef219dcd8da262cbb958639a96bedba10e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/97ffee3bcfb5805568d6af7f0f893678fc076d2f", - "reference": "97ffee3bcfb5805568d6af7f0f893678fc076d2f", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d543b8ef219dcd8da262cbb958639a96bedba10e", + "reference": "d543b8ef219dcd8da262cbb958639a96bedba10e", "shasum": "" }, "require": { - "nikic/php-parser": "^5.0", + "nikic/php-parser": "^5.7.0", "php": ">=8.3" }, "require-dev": { - "phpunit/phpunit": "^12.0" + "phpunit/phpunit": "^12.5.25" }, "type": "library", "extra": { @@ -1350,15 +1350,27 @@ "support": { "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", - "source": "https://github.com/sebastianbergmann/lines-of-code/tree/4.0.0" + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/4.0.1" }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" + }, + { + "url": "https://liberapay.com/sebastianbergmann", + "type": "liberapay" + }, + { + "url": "https://thanks.dev/u/gh/sebastianbergmann", + "type": "thanks_dev" + }, + { + "url": "https://tidelift.com/funding/github/packagist/sebastian/lines-of-code", + "type": "tidelift" } ], - "time": "2025-02-07T04:57:28+00:00" + "time": "2026-05-19T16:22:07+00:00" }, { "name": "sebastian/object-enumerator", @@ -1552,23 +1564,23 @@ }, { "name": "sebastian/type", - "version": "6.0.3", + "version": "6.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/type.git", - "reference": "e549163b9760b8f71f191651d22acf32d56d6d4d" + "reference": "82ff822c2edc46724be9f7411d3163021f602773" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/e549163b9760b8f71f191651d22acf32d56d6d4d", - "reference": "e549163b9760b8f71f191651d22acf32d56d6d4d", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/82ff822c2edc46724be9f7411d3163021f602773", + "reference": "82ff822c2edc46724be9f7411d3163021f602773", "shasum": "" }, "require": { "php": ">=8.3" }, "require-dev": { - "phpunit/phpunit": "^12.0" + "phpunit/phpunit": "^12.5.25" }, "type": "library", "extra": { @@ -1597,7 +1609,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/type/issues", "security": "https://github.com/sebastianbergmann/type/security/policy", - "source": "https://github.com/sebastianbergmann/type/tree/6.0.3" + "source": "https://github.com/sebastianbergmann/type/tree/6.0.4" }, "funding": [ { @@ -1617,7 +1629,7 @@ "type": "tidelift" } ], - "time": "2025-08-09T06:57:12+00:00" + "time": "2026-05-20T06:45:45+00:00" }, { "name": "sebastian/version", diff --git a/examples/queue.php b/examples/queue.php index 7564afc..ef86141 100644 --- a/examples/queue.php +++ b/examples/queue.php @@ -21,9 +21,9 @@ ], ]; if (empty($argv[2])) { - $jobId = \Resque\Resque::enqueue('default', $argv[1], $args, true); + $jobId = \Resque\Resque::enqueue('default', $argv[1], $args); } else { - $jobId = \Resque\Resque::enqueue($argv[1], $argv[2], $args, true); + $jobId = \Resque\Resque::enqueue($argv[1], $argv[2], $args); } echo "Queued job " . $jobId . "\n\n"; diff --git a/src/Resque/Job/Factory.php b/src/Resque/Job/Factory.php index 9ee0b74..b2ba6d6 100644 --- a/src/Resque/Job/Factory.php +++ b/src/Resque/Job/Factory.php @@ -20,7 +20,7 @@ class Factory implements FactoryInterface * Create job factory * * @param $className - * @param array $args + * @param $args * @param $queue * * @return \Resque\Job\JobInterface diff --git a/src/Resque/Job/FactoryInterface.php b/src/Resque/Job/FactoryInterface.php index a44d6ac..a44cd55 100644 --- a/src/Resque/Job/FactoryInterface.php +++ b/src/Resque/Job/FactoryInterface.php @@ -13,7 +13,7 @@ interface FactoryInterface { /** * @param $className - * @param array $args + * @param $args * @param $queue * * @return \Resque\Job\JobInterface diff --git a/src/Resque/Job/Job.php b/src/Resque/Job/Job.php index 8249559..1dae3f7 100755 --- a/src/Resque/Job/Job.php +++ b/src/Resque/Job/Job.php @@ -55,14 +55,13 @@ public function __construct($queue, $payload) * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. - * @param boolean $monitor Set to true to be able to monitor the status of a job. * @param string $id Unique identifier for tracking the job. Generated if not supplied. * * @return string * * @throws \InvalidArgumentException */ - public static function create($queue, $class, $args = null, $monitor = false, $id = null): string + public static function create($queue, $class, $args = null, $id = null): string { if (is_null($id)) { $id = \Resque\Resque::generateJobId(); @@ -80,10 +79,6 @@ public static function create($queue, $class, $args = null, $monitor = false, $i 'queue_time' => microtime(true), ]); - if ($monitor) { - Status::create($id); - } - return $id; } @@ -124,35 +119,6 @@ public static function reserveBlocking(array $queues, $timeout = null): ?Job 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. - * - * @return bool - */ - public function updateStatus($status): bool - { - if (empty($this->payload['id'])) { - return false; - } - - $statusInstance = new Status($this->payload['id']); - $statusInstance->update($status); - return true; - } - - /** - * Return the status of the current job. - * - * @return int The status of the job as one of the \Resque\Job\Status constants. - */ - public function getStatus() - { - $status = new Status($this->payload['id']); - return $status->get(); - } - /** * Get the arguments supplied to this job. * @@ -228,7 +194,6 @@ public function fail($exception) 'job' => $this, ]); - $this->updateStatus(Status::STATUS_FAILED); \Resque\Failure\Failure::create( $this->payload, $exception, @@ -246,13 +211,7 @@ public function fail($exception) */ public function recreate() { - $status = new Status($this->payload['id']); - $monitor = false; - if ($status->isTracking()) { - $monitor = true; - } - - return self::create($this->queue, $this->payload['class'], $this->getArguments(), $monitor); + return self::create($this->queue, $this->payload['class'], $this->getArguments()); } /** diff --git a/src/Resque/Job/Status.php b/src/Resque/Job/Status.php deleted file mode 100644 index 6387c2a..0000000 --- a/src/Resque/Job/Status.php +++ /dev/null @@ -1,152 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php - */ - -class Status -{ - 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. - */ - private $id; - - /** - * @var mixed Cache variable if the status of this job is being monitored or not. - * True/false when checked at least once or null if not checked yet. - */ - private $isTracking = null; - - /** - * @var array Array of statuses that are considered final/complete. - */ - private static $completeStatuses = [ - self::STATUS_FAILED, - self::STATUS_COMPLETE - ]; - - /** - * Setup a new instance of the job monitor class for the supplied job ID. - * - * @param string $id The ID of the job to manage the status for. - */ - public function __construct($id) - { - $this->id = $id; - } - - /** - * Create a new status monitor item for the supplied job ID. Will create - * all necessary keys in Redis to monitor the status of a job. - * - * @param string $id The ID of the job to monitor the status of. - */ - public static function create($id) - { - $statusPacket = [ - 'status' => self::STATUS_WAITING, - 'updated' => time(), - 'started' => time(), - ]; - \Resque\Resque::redis()->set( - 'job:' . $id . ':status', - json_encode($statusPacket), - ['ex' => \Resque\Redis::DEFAULT_REDIS_TTL], - ); - } - - /** - * Check if we're actually checking the status of the loaded job status - * instance. - * - * @return boolean True if the status is being monitored, false if not. - */ - public function isTracking(): bool - { - if ($this->isTracking === false) { - return false; - } - - if (!\Resque\Resque::redis()->exists((string)$this)) { - $this->isTracking = false; - return false; - } - - $this->isTracking = true; - return true; - } - - /** - * 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) - */ - public function update($status) - { - if (!$this->isTracking()) { - return; - } - - $statusPacket = [ - 'status' => $status, - 'updated' => time(), - ]; - - \Resque\Resque::redis()->set( - (string)$this, - json_encode($statusPacket), - ['ex' => \Resque\Redis::DEFAULT_REDIS_TTL], - ); - } - - /** - * 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. - */ - public function get() - { - if (!$this->isTracking()) { - return false; - } - - $statusPacket = json_decode(\Resque\Resque::redis()->get((string)$this), true); - if (!$statusPacket) { - return false; - } - - return $statusPacket['status']; - } - - /** - * Stop tracking the status of a job. - * - * @return void - */ - public function stop(): void - { - \Resque\Resque::redis()->del((string)$this); - } - - /** - * Generate a string representation of this object. - * - * @return string String representation of the current job status class. - */ - public function __toString(): string - { - return 'job:' . $this->id . ':status'; - } -} diff --git a/src/Resque/Resque.php b/src/Resque/Resque.php index b69ed8e..d700795 100644 --- a/src/Resque/Resque.php +++ b/src/Resque/Resque.php @@ -12,7 +12,7 @@ class Resque { - public const VERSION = '3.0.0'; + public const VERSION = '3.1.0'; public const DEFAULT_INTERVAL = 5; @@ -102,26 +102,26 @@ public static function fork() * Push a job to the end of a specific queue. If the queue does not * exist, then create it as well. * - * @param string $queue The name of the queue to add the job to. - * @param array $item Job description as an array to be JSON encoded. + * @param string $queue The name of the queue to add the job to + * @param array $item Job description as an array to be JSON encoded * * @return bool */ - public static function push($queue, $item): bool + public static function push(string $queue, array $item): bool { $encodedItem = json_encode($item); if ($encodedItem === false) { return false; } - self::redis()->sadd('queues', $queue); + $redis = self::redis(); + $redis->multi(); + $redis->sadd('queues', $queue); + $redis->rpush('queue:' . $queue, $encodedItem); + $result = $redis->exec(); - $length = self::redis()->rpush('queue:' . $queue, $encodedItem); - if ($length < 1) { - return false; - } - - return true; + // Return true if the job was pushed to the queue, otherwise false + return !(!is_array($result) || count($result) < 2 || (int)$result[1] < 1); } /** @@ -226,11 +226,10 @@ public static function size($queue): int * @param string $queue The name of the queue to place the job in. * @param string $class The name of the class that contains the code to execute the job. * @param array $args Any optional arguments that should be passed when the job is executed. - * @param boolean $trackStatus Set to true to be able to monitor the status of a job. * * @return string|boolean Job ID when the job was created, false if creation was cancelled due to beforeEnqueue */ - public static function enqueue($queue, $class, $args = null, $trackStatus = false) + public static function enqueue($queue, $class, $args = null) { $id = Resque::generateJobId(); $hookParams = [ @@ -245,7 +244,7 @@ public static function enqueue($queue, $class, $args = null, $trackStatus = fals return false; } - \Resque\Job\Job::create($queue, $class, $args, $trackStatus, $id); + \Resque\Job\Job::create($queue, $class, $args, $id); \Resque\Event::trigger('afterEnqueue', $hookParams); return $id; diff --git a/src/Resque/Worker.php b/src/Resque/Worker.php index accc0b0..82acdad 100644 --- a/src/Resque/Worker.php +++ b/src/Resque/Worker.php @@ -26,6 +26,21 @@ class Worker */ private $queues = []; + /** + * @var array|null Cached wildcard queue list to reduce repeated Redis calls. + */ + private $cachedQueues = null; + + /** + * @var float Timestamp of the wildcard queue cache refresh. + */ + private $cachedQueuesAt = 0.0; + + /** + * Refresh wildcard queue list after this many seconds. + */ + private const WILDCARD_QUEUE_CACHE_TTL = 5.0; + /** * @var string The hostname of this worker. */ @@ -222,7 +237,6 @@ public function perform(\Resque\Job\Job $job): void return; } - $job->updateStatus(\Resque\Job\Status::STATUS_COMPLETE); $this->logger->log(\Psr\Log\LogLevel::NOTICE, '{job} has finished', ['job' => $job]); } @@ -277,10 +291,20 @@ public function queues(bool $fetch = true): array return $this->queues; } + // Cache queues to prevent excess redis calls + if ( + is_array($this->cachedQueues) + && (microtime(true) - $this->cachedQueuesAt) < self::WILDCARD_QUEUE_CACHE_TTL + ) { + return $this->cachedQueues; + } + $queues = Resque::queues(); sort($queues); + $this->cachedQueues = $queues; + $this->cachedQueuesAt = microtime(true); - return $queues; + return $this->cachedQueues; } /** @@ -455,7 +479,6 @@ public function workingOn(\Resque\Job\Job $job): void { $job->worker = $this; $this->currentJob = $job; - $job->updateStatus(\Resque\Job\Status::STATUS_RUNNING); $data = json_encode([ 'queue' => $job->queue, 'run_at' => date('D M d H:i:s T Y'), diff --git a/tests/Resque/Tests/JobStatusTest.php b/tests/Resque/Tests/JobStatusTest.php deleted file mode 100644 index a7185cc..0000000 --- a/tests/Resque/Tests/JobStatusTest.php +++ /dev/null @@ -1,110 +0,0 @@ - - * @license http://www.opensource.org/licenses/mit-license.php - */ - -class JobStatusTest extends TestCase -{ - /** - * @var \Resque\Worker - */ - protected $worker; - - public function setUp(): void - { - parent::setUp(); - - // Register a worker to test with - $this->worker = new \Resque\Worker('jobs'); - $this->worker->setLogger(new \Resque\Log()); - } - - public function testJobStatusCanBeTracked() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, true); - $status = new \Resque\Job\Status($token); - $this->assertTrue($status->isTracking()); - } - - public function testJobStatusIsReturnedViaJobInstance() - { - \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, true); - $job = \Resque\Job\Job::reserve('jobs'); - $this->assertEquals(\Resque\Job\Status::STATUS_WAITING, $job->getStatus()); - } - - public function testQueuedJobReturnsQueuedStatus() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, true); - $status = new \Resque\Job\Status($token); - $this->assertEquals(\Resque\Job\Status::STATUS_WAITING, $status->get()); - } - - public function testRunningJobReturnsRunningStatus() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\FailingJob', null, true); - $job = $this->worker->reserve(); - $this->worker->workingOn($job); - $status = new \Resque\Job\Status($token); - $this->assertEquals(\Resque\Job\Status::STATUS_RUNNING, $status->get()); - } - - public function testFailedJobReturnsFailedStatus() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\FailingJob', null, true); - $this->worker->work(0); - $status = new \Resque\Job\Status($token); - $this->assertEquals(\Resque\Job\Status::STATUS_FAILED, $status->get()); - } - - public function testCompletedJobReturnsCompletedStatus() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, true); - $this->worker->work(0); - $status = new \Resque\Job\Status($token); - $this->assertEquals(\Resque\Job\Status::STATUS_COMPLETE, $status->get()); - } - - public function testStatusIsNotTrackedWhenToldNotTo() - { - $token = \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, false); - $status = new \Resque\Job\Status($token); - $this->assertFalse($status->isTracking()); - } - - public function testStatusTrackingCanBeStopped() - { - \Resque\Job\Status::create('test'); - $status = new \Resque\Job\Status('test'); - $this->assertEquals(\Resque\Job\Status::STATUS_WAITING, $status->get()); - $status->stop(); - $this->assertFalse($status->get()); - } - - public function testRecreatedJobWithTrackingStillTracksStatus() - { - $originalToken = \Resque\Resque::enqueue('jobs', '\Resque\Test\TestJob', null, true); - $job = $this->worker->reserve(); - - // Mark this job as being worked on to ensure that the new status is still - // waiting. - $this->worker->workingOn($job); - - // Now recreate it - $newToken = $job->recreate(); - - // Make sure we've got a new job returned - $this->assertNotEquals($originalToken, $newToken); - - // Now check the status of the new job - $newJob = \Resque\Job\Job::reserve('jobs'); - $this->assertEquals(\Resque\Job\Status::STATUS_WAITING, $newJob->getStatus()); - } -} \ No newline at end of file diff --git a/tests/Resque/Tests/JobTest.php b/tests/Resque/Tests/JobTest.php index 0e3655d..59e9941 100644 --- a/tests/Resque/Tests/JobTest.php +++ b/tests/Resque/Tests/JobTest.php @@ -425,8 +425,9 @@ class Some_Stub_Factory implements \Resque\Job\FactoryInterface /** * @param $className - * @param array $args + * @param $args * @param $queue + * * @return \Resque\Job\JobInterface */ public function create($className, $args, $queue)