• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / jobs / 24850441053

23 Apr 2026 05:54PM UTC coverage: 52.404% (-1.5%) from 53.938%
24850441053

push

github

daycry
Fixes

104 of 219 new or added lines in 42 files covered. (47.49%)

14 existing lines in 9 files now uncovered.

1210 of 2309 relevant lines covered (52.4%)

4.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/src/Execution/RetryPolicyFixed.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Queues.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Jobs\Execution;
15

16
use Throwable;
17

18
/**
19
 * Unified retry policy with configurable strategies: none, fixed, exponential.
20
 */
21
class RetryPolicyFixed implements RetryPolicy
22
{
23
    public function __construct(
24
        private int $base = 5,
25
        private readonly string $strategy = 'fixed',
26
        private float $multiplier = 2.0,
27
        private int $max = 300,
28
        private readonly bool $jitter = true,
29
    ) {
30
        $this->base       = max(0, $base);
31✔
31
        $this->multiplier = $multiplier > 0 ? $multiplier : 2.0;
31✔
32
        $this->max        = max(1, $max);
31✔
33
    }
34

35
    public function computeDelay(int $attempt): int
36
    {
37
        if ($attempt <= 1) {
9✔
38
            return 0;
2✔
39
        }
40

41
        return match ($this->strategy) {
9✔
42
            'exponential' => $this->computeExponential($attempt),
5✔
43
            'fixed'       => $this->base,
3✔
44
            default       => 0, // 'none'
9✔
45
        };
9✔
46
    }
47

48
    private function computeExponential(int $attempt): int
49
    {
50
        // attempt=2 => exponent 0
51
        $exponent = $attempt - 2;
5✔
52

53
        // Guard against overflow with large exponents
54
        if ($exponent > 30 || $this->multiplier ** $exponent > PHP_INT_MAX / max(1, $this->base)) {
5✔
NEW
55
            $delay = $this->max;
×
56
        } else {
57
            $delay = (int) round($this->base * ($this->multiplier ** $exponent));
5✔
58
        }
59

60
        $delay = min($delay, $this->max);
5✔
61

62
        if ($this->jitter) {
5✔
63
            $range = max(1, (int) round((float) $delay * 0.15));
2✔
64

65
            try {
66
                $delay = max(1, $delay + random_int(-$range, $range));
2✔
67
            } catch (Throwable) {
×
NEW
68
                log_message('warning', 'RetryPolicyFixed: random_int failed, jitter disabled for this attempt.');
×
69
            }
70
        }
71

72
        return $delay;
5✔
73
    }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc