Skip to content

Commit 02169af

Browse files
author
Алексей Тихомиров
committed
fix: disable backoff in retry test to fix CI failure
- Added setUseBackoff() method to Worker for controlling exponential backoff - Disabled backoff in 'задача с несколькими попытками при ошибке' test - Reset useBackoff to true in Worker::reset() method The test was failing because after each retry, the job was delayed by exponential backoff (2^attempts seconds), making it unavailable for immediate processing in the test.
1 parent a73ce7b commit 02169af

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/Worker.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Worker
2424

2525
protected int $memoryLimit = 128;
2626

27+
protected bool $useBackoff = true;
28+
2729
protected ?LogStorage $logger = null;
2830

2931
public function __construct(
@@ -118,11 +120,23 @@ protected function handleJobException(JobInterface $job, string $queue, Throwabl
118120
*/
119121
protected function calculateBackoff(JobInterface $job): int
120122
{
123+
if (! $this->useBackoff) {
124+
return 0;
125+
}
126+
121127
$attempts = $job->getAttempts();
122128

123129
return min(2 ** $attempts, 3600); // Max 1 hour
124130
}
125131

132+
/**
133+
* Enable or disable exponential backoff for retries.
134+
*/
135+
public function setUseBackoff(bool $useBackoff): void
136+
{
137+
$this->useBackoff = $useBackoff;
138+
}
139+
126140
/**
127141
* Check if we should stop the worker.
128142
*/
@@ -187,6 +201,7 @@ public function reset(): void
187201
$this->jobsProcessed = 0;
188202
$this->maxJobs = 0;
189203
$this->maxTime = 0;
204+
$this->useBackoff = true;
190205
$this->startTime = time();
191206
}
192207

tests/Feature/QueueIntegrationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
WPQueue::dispatch($job);
8888

8989
$worker = WPQueue::worker();
90+
$worker->setUseBackoff(false); // Отключаем backoff для теста
9091

9192
// Попытка 1
9293
$worker->runNextJob('default');

0 commit comments

Comments
 (0)