Skip to content

Commit 2db8906

Browse files
committed
2.6.2 (2026-02-07)
- Update packages - Remove setproctitle in favour of cli_set_process_title - Add DISABLE_STATS env var to reduce redis load
1 parent c542be0 commit 2db8906

10 files changed

Lines changed: 159 additions & 32 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ jobs:
3131
--health-retries 5
3232
steps:
3333
- uses: actions/checkout@v3
34+
3435
- name: Install composer
3536
run: apt-get update -yq && apt-get install git wget procps unzip -y && pecl install -o -f redis && rm -rf /tmp/pear && docker-php-ext-enable redis && wget https://getcomposer.org/composer.phar && php composer.phar install --dev
37+
3638
- name: Run PHP ${{ matrix.php_version }}} Unit Tests
3739
run: php vendor/bin/phpunit --configuration phpunit.xml

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.6.2 (2026-02-07)
2+
- Update packages
3+
- Remove setproctitle in favour of cli_set_process_title
4+
- Add DISABLE_STATS env var to reduce redis load
5+
16
# 2.6.1 (2025-12-01)
27
- Readd PHP 8.1 support
38

bin/resque

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ if (!empty($LOGGING)) {
5959

6060
// Bootstrap file
6161
$APP_INCLUDE = getenv('APP_INCLUDE');
62-
if ($APP_INCLUDE) {
62+
if (!empty($APP_INCLUDE)) {
6363
if (!file_exists($APP_INCLUDE)) {
6464
die('APP_INCLUDE (' . $APP_INCLUDE . ") does not exist.\n");
6565
}
@@ -73,8 +73,14 @@ if (!isset($logger) || !is_object($logger)) {
7373
$logger = new \Resque\Log($logLevel);
7474
}
7575

76+
// Disable stats collection
77+
$DISABLE_STATS = getenv('DISABLE_STATS') !== false;
78+
if ($DISABLE_STATS) {
79+
\Resque\Stat::setDisableStats(true);
80+
}
81+
7682
// Determines if blocking or not
77-
$BLOCKING = getenv('BLOCKING') !== FALSE;
83+
$BLOCKING = getenv('BLOCKING') !== false;
7884

7985
// Interval to check for jobs
8086
$interval = 5;

composer.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resque/Job/JobInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,14 @@ interface JobInterface
88
* @return bool
99
*/
1010
public function perform();
11+
12+
/**
13+
* @return void
14+
*/
15+
public function setUp(): void;
16+
17+
/**
18+
* @return void
19+
*/
20+
public function tearDown(): void;
1121
}

src/Resque/Resque.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class Resque
1414
{
15-
public const VERSION = '2.6.1';
15+
public const VERSION = '2.6.2';
1616

1717
public const DEFAULT_INTERVAL = 5;
1818

src/Resque/Stat.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212

1313
class Stat
1414
{
15+
/**
16+
* @var boolean Whether to disable stats collection.
17+
*/
18+
protected static $disableStats = false;
19+
20+
/**
21+
* Set whether to disable stats collection.
22+
*
23+
* @param bool $disableStats Whether to disable stats collection.
24+
*
25+
* @return void
26+
*/
27+
public static function setDisableStats(bool $disableStats): void
28+
{
29+
self::$disableStats = $disableStats;
30+
}
31+
1532
/**
1633
* Get the value of the supplied statistic counter for the specified statistic.
1734
*
@@ -21,6 +38,10 @@ class Stat
2138
*/
2239
public static function get(string $stat): int
2340
{
41+
if (self::$disableStats) {
42+
return 0;
43+
}
44+
2445
return (int)Resque::redis()->get('stat:' . $stat);
2546
}
2647

@@ -34,6 +55,10 @@ public static function get(string $stat): int
3455
*/
3556
public static function incr(string $stat, int $by = 1): bool
3657
{
58+
if (self::$disableStats) {
59+
return true;
60+
}
61+
3762
// Make sure we set a TTL by default
3863
$set = Resque::redis()->set(
3964
'stat:' . $stat,
@@ -59,6 +84,10 @@ public static function incr(string $stat, int $by = 1): bool
5984
*/
6085
public static function decr(string $stat, int $by = 1): bool
6186
{
87+
if (self::$disableStats) {
88+
return true;
89+
}
90+
6291
return (bool)Resque::redis()->decrby('stat:' . $stat, $by);
6392
}
6493

@@ -71,6 +100,10 @@ public static function decr(string $stat, int $by = 1): bool
71100
*/
72101
public static function clear(string $stat): bool
73102
{
103+
if (self::$disableStats) {
104+
return true;
105+
}
106+
74107
return (bool)Resque::redis()->del('stat:' . $stat);
75108
}
76109
}

src/Resque/Worker.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,9 @@ private function startup(): void
304304
*
305305
* @return void
306306
*/
307-
private function updateProcLine($status): void
307+
private function updateProcLine(string $status): void
308308
{
309-
$processTitle = 'resque-' . Resque::VERSION . ': ' . $status;
310-
if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
311-
cli_set_process_title($processTitle);
312-
} elseif (function_exists('setproctitle')) {
313-
setproctitle($processTitle);
314-
}
309+
cli_set_process_title('resque-' . Resque::VERSION . ': ' . $status);
315310
}
316311

317312
/**

tests/Resque/Tests/JobTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,20 @@ public function perform()
409409
{
410410
return true;
411411
}
412+
413+
/**
414+
* @return void
415+
*/
416+
public function setUp(): void
417+
{
418+
}
419+
420+
/**
421+
* @return void
422+
*/
423+
public function tearDown(): void
424+
{
425+
}
412426
}
413427

414428
class Some_Stub_Factory implements \Resque\Job\FactoryInterface

tests/Resque/Tests/StatTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,66 @@ public function testGetUnknownStatReturns0()
5050
{
5151
$this->assertEquals(0, \Resque\Stat::get('test_get_unknown'));
5252
}
53+
54+
// Tests with DISABLE_STATS=true
55+
56+
public function testStatIncrNoOpWhenDisabled()
57+
{
58+
\Resque\Stat::setDisableStats(true);
59+
$this->assertTrue(\Resque\Stat::incr('test_incr_disabled'));
60+
$this->assertTrue(\Resque\Stat::incr('test_incr_disabled'));
61+
$this->assertEmpty($this->redis->get('resque:stat:test_incr_disabled'));
62+
\Resque\Stat::setDisableStats(false);
63+
}
64+
65+
public function testStatIncrByXNoOpWhenDisabled()
66+
{
67+
\Resque\Stat::setDisableStats(true);
68+
$this->assertTrue(\Resque\Stat::incr('test_incrX_disabled', 10));
69+
$this->assertTrue(\Resque\Stat::incr('test_incrX_disabled', 11));
70+
$this->assertEmpty($this->redis->get('resque:stat:test_incrX_disabled'));
71+
\Resque\Stat::setDisableStats(false);
72+
}
73+
74+
public function testStatDecrNoOpWhenDisabled()
75+
{
76+
\Resque\Stat::incr('test_decr_disabled', 22);
77+
\Resque\Stat::setDisableStats(true);
78+
$this->assertTrue(\Resque\Stat::decr('test_decr_disabled'));
79+
$this->assertEquals(22, $this->redis->get('resque:stat:test_decr_disabled'));
80+
\Resque\Stat::setDisableStats(false);
81+
}
82+
83+
public function testStatDecrByXNoOpWhenDisabled()
84+
{
85+
\Resque\Stat::incr('test_decrX_disabled', 22);
86+
\Resque\Stat::setDisableStats(true);
87+
$this->assertTrue(\Resque\Stat::decr('test_decrX_disabled', 11));
88+
$this->assertEquals(22, $this->redis->get('resque:stat:test_decrX_disabled'));
89+
\Resque\Stat::setDisableStats(false);
90+
}
91+
92+
public function testGetStatReturns0WhenDisabled()
93+
{
94+
\Resque\Stat::incr('test_get_disabled', 100);
95+
\Resque\Stat::setDisableStats(true);
96+
$this->assertEquals(0, \Resque\Stat::get('test_get_disabled'));
97+
\Resque\Stat::setDisableStats(false);
98+
}
99+
100+
public function testGetUnknownStatReturns0WhenDisabled()
101+
{
102+
\Resque\Stat::setDisableStats(true);
103+
$this->assertEquals(0, \Resque\Stat::get('test_get_unknown_disabled'));
104+
\Resque\Stat::setDisableStats(false);
105+
}
106+
107+
public function testClearStatNoOpWhenDisabled()
108+
{
109+
\Resque\Stat::incr('test_clear_disabled', 50);
110+
\Resque\Stat::setDisableStats(true);
111+
$this->assertTrue(\Resque\Stat::clear('test_clear_disabled'));
112+
\Resque\Stat::setDisableStats(false);
113+
$this->assertEquals(50, $this->redis->get('resque:stat:test_clear_disabled'));
114+
}
53115
}

0 commit comments

Comments
 (0)