RetryableTrait::canRetry()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
namespace App\Queue;
3
4
use Yii;
5
6
trait RetryableTrait
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11
    public function getTtr()
12
    {
13
        return 60;
14
    }
15
16
    /**
17
     * Gets maximum attempt times, default to 3.
18
     *
19
     * @return int maximum attempt times.
20
     */
21
    public function getMaxAttemptTimes(): int
22
    {
23
        return 3;
24
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function canRetry($attempt, $error)
30
    {
31
        if ($error instanceof JobPreventedException) {
32
            Yii::warning(self::class . ' was prevented to execute', __METHOD__);
33
            return false;
34
        }
35
36
        return $attempt < $this->getMaxAttemptTimes();
37
    }
38
}
39