1 | <?php |
||
12 | class Executor |
||
13 | { |
||
14 | /** |
||
15 | * The checker. |
||
16 | * |
||
17 | * @var \Pbmedia\ApiHealth\Checkers\Checker |
||
18 | */ |
||
19 | private $checker; |
||
20 | |||
21 | /** |
||
22 | * The state of the checker. |
||
23 | * |
||
24 | * @var \Pbmedia\ApiHealth\Storage\CheckerState |
||
25 | */ |
||
26 | private $state; |
||
27 | |||
28 | /** |
||
29 | * The caught exception if the checker fails. |
||
30 | * |
||
31 | * @var \Pbmedia\ApiHealth\Checkers\CheckerHasFailed |
||
32 | */ |
||
33 | private $exception; |
||
34 | |||
35 | /** |
||
36 | * Boolean wether the checker has failed of not. |
||
37 | * |
||
38 | * @var bool |
||
39 | */ |
||
40 | private $failed; |
||
41 | |||
42 | /** |
||
43 | * Creates an instance with the given checker |
||
44 | * |
||
45 | * @param \Pbmedia\ApiHealth\Checkers\Checker $checker |
||
46 | */ |
||
47 | public function __construct(Checker $checker) |
||
52 | |||
53 | /** |
||
54 | * Shortcut for creating an instance for a checker class. |
||
55 | * |
||
56 | * @param string $checkerClass |
||
57 | * @return \Pbmedia\ApiHealth\Checkers\Executor |
||
58 | */ |
||
59 | public static function make(string $checkerClass) |
||
63 | |||
64 | /** |
||
65 | * Returns a boolean wether the checker passes. |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function passes(): bool |
||
77 | |||
78 | /** |
||
79 | * Returns a boolean wether the checker fails. |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function fails(): bool |
||
87 | |||
88 | /** |
||
89 | * Returns the checker. |
||
90 | * |
||
91 | * @return \Pbmedia\ApiHealth\Checkers\Checker |
||
92 | */ |
||
93 | public function getChecker(): Checker |
||
97 | |||
98 | /** |
||
99 | * Returns the caught exception. |
||
100 | * |
||
101 | * @return \Pbmedia\ApiHealth\Checkers\CheckerHasFailed |
||
102 | */ |
||
103 | public function getException(): CheckerHasFailed |
||
107 | |||
108 | /** |
||
109 | * Runs the checker, stores the state and lets events take |
||
110 | * care of sending the notifications. |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function handle() |
||
133 | |||
134 | /** |
||
135 | * Handler for whenever the checker fails. Stores the state or adds a timestamp |
||
136 | * to the state if the checker previously failed. |
||
137 | * |
||
138 | * @return null |
||
139 | */ |
||
140 | private function handleFailedChecker() |
||
148 | |||
149 | /** |
||
150 | * Adds a retry timestamp to the state of checker or dispaches |
||
151 | * the retry job. |
||
152 | * |
||
153 | * @return null |
||
154 | */ |
||
155 | private function handleAllowedRetry() |
||
177 | |||
178 | /** |
||
179 | * Sets the default connection, delay and queue |
||
180 | * on the retry job. |
||
181 | * |
||
182 | * @param mixed $job |
||
183 | * @param array $config |
||
184 | */ |
||
185 | private function configureRetryJobDefaults($job, array $config) |
||
199 | |||
200 | /** |
||
201 | * Adds a callback before the retry job is executed which |
||
202 | * will add a retry timestamp on the checker's state. |
||
203 | * |
||
204 | * @param string $job |
||
205 | */ |
||
206 | private function addCallbackBeforeRetryCheckerJob(string $job) |
||
220 | } |
||
221 |