1 | <?php |
||
9 | class Executor |
||
10 | { |
||
11 | /** |
||
12 | * The checker. |
||
13 | * |
||
14 | * @var \ProtoneMedia\ApiHealth\Checkers\Checker |
||
15 | */ |
||
16 | private $checker; |
||
17 | |||
18 | /** |
||
19 | * The state of the checker. |
||
20 | * |
||
21 | * @var \ProtoneMedia\ApiHealth\Storage\CheckerState |
||
22 | */ |
||
23 | private $state; |
||
24 | |||
25 | /** |
||
26 | * The caught exception if the checker fails. |
||
27 | * |
||
28 | * @var \ProtoneMedia\ApiHealth\Checkers\CheckerHasFailed |
||
29 | */ |
||
30 | private $exception; |
||
31 | |||
32 | /** |
||
33 | * Boolean wether the checker has failed of not. |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | private $failed; |
||
38 | |||
39 | /** |
||
40 | * Creates an instance with the given checker |
||
41 | * |
||
42 | * @param \ProtoneMedia\ApiHealth\Checkers\Checker $checker |
||
43 | */ |
||
44 | public function __construct(Checker $checker) |
||
49 | |||
50 | /** |
||
51 | * Shortcut for creating an instance for a checker class. |
||
52 | * |
||
53 | * @param string $checkerClass |
||
54 | * @return \ProtoneMedia\ApiHealth\Checkers\Executor |
||
55 | */ |
||
56 | public static function make(string $checkerClass) |
||
60 | |||
61 | /** |
||
62 | * Returns a boolean wether the checker passes. |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function passes(): bool |
||
72 | |||
73 | /** |
||
74 | * Returns a boolean wether the checker fails. |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function fails(): bool |
||
82 | |||
83 | /** |
||
84 | * Returns the checker. |
||
85 | * |
||
86 | * @return \ProtoneMedia\ApiHealth\Checkers\Checker |
||
87 | */ |
||
88 | public function getChecker(): Checker |
||
92 | |||
93 | /** |
||
94 | * Returns the caught exception. |
||
95 | * |
||
96 | * @return \ProtoneMedia\ApiHealth\Checkers\CheckerHasFailed |
||
97 | */ |
||
98 | public function getException(): CheckerHasFailed |
||
102 | |||
103 | /** |
||
104 | * Runs the checker, stores the state and lets events take |
||
105 | * care of sending the notifications. |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function handle() |
||
128 | |||
129 | /** |
||
130 | * Handler for whenever the checker fails. Stores the state or adds a timestamp |
||
131 | * to the state if the checker previously failed. |
||
132 | * |
||
133 | * @return null |
||
134 | */ |
||
135 | private function handleFailedChecker() |
||
143 | |||
144 | /** |
||
145 | * Adds a retry timestamp to the state of checker or dispaches |
||
146 | * the retry job. |
||
147 | * |
||
148 | * @return null |
||
149 | */ |
||
150 | private function handleAllowedRetry() |
||
170 | |||
171 | /** |
||
172 | * Sets the default connection, delay and queue |
||
173 | * on the retry job. |
||
174 | * |
||
175 | * @param mixed $job |
||
176 | * @param array $config |
||
177 | */ |
||
178 | private function configureRetryJobDefaults($job, array $config) |
||
192 | } |
||
193 |