1 | <?php |
||
14 | class CheckerState |
||
15 | { |
||
16 | /** |
||
17 | * The checker. |
||
18 | * |
||
19 | * @var \Pbmedia\ApiHealth\Checkers\Checker |
||
20 | */ |
||
21 | private $checker; |
||
22 | |||
23 | /** |
||
24 | * The cache driver instance. |
||
25 | * |
||
26 | * @var \Illuminate\Contracts\Cache\Repository |
||
27 | */ |
||
28 | private $cache; |
||
29 | |||
30 | public function __construct(Checker $checker) |
||
36 | |||
37 | /** |
||
38 | * Shortcut for creating an instance with the given checker class. |
||
39 | * |
||
40 | * @param string $checkerClass |
||
41 | * @return \Pbmedia\ApiHealth\Storage\CheckerState |
||
42 | */ |
||
43 | public static function make(string $checkerClass) |
||
47 | |||
48 | /** |
||
49 | * Returns the cache key for this checker. |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | private function key(): string |
||
57 | |||
58 | /** |
||
59 | * Returns a boolean wether any data has been stored. |
||
60 | * |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function exists(): bool |
||
67 | |||
68 | /** |
||
69 | * Stores the given data into the cache repository. |
||
70 | * |
||
71 | * @param array $data |
||
72 | * @return null |
||
73 | */ |
||
74 | private function store(array $data) |
||
78 | |||
79 | /** |
||
80 | * Returns all stored data. |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | public function data(): array |
||
88 | |||
89 | /** |
||
90 | * Returns a boolean wether the state is set to failed. |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | public function isFailing(): bool |
||
98 | |||
99 | /** |
||
100 | * Returns a boolean wether the state is set to passes. |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | public function isPassing(): bool |
||
108 | |||
109 | /** |
||
110 | * Determinates if a failed notification should be sent. |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | public function shouldSentFailedNotification(): bool |
||
130 | |||
131 | /** |
||
132 | * Determinates wether the checker is allowed to do another retry. |
||
133 | * |
||
134 | * @return bool |
||
135 | */ |
||
136 | public function retryIsAllowed(): bool |
||
158 | |||
159 | /** |
||
160 | * Set the state to failed with the given exception message. |
||
161 | * |
||
162 | * @param \Pbmedia\ApiHealth\Checkers\CheckerHasFailed $exception |
||
163 | */ |
||
164 | public function setToFailed(CheckerHasFailed $exception) |
||
175 | |||
176 | /** |
||
177 | * Adds the current timestamp to the failed state. |
||
178 | * |
||
179 | * @param \Pbmedia\ApiHealth\Checkers\CheckerHasFailed $exception |
||
180 | */ |
||
181 | public function addFailedTimestamp(CheckerHasFailed $exception) |
||
191 | |||
192 | /** |
||
193 | * Adds the current timestamp to the retry array. |
||
194 | * |
||
195 | * @return null |
||
196 | */ |
||
197 | public function addRetryTimestamp() |
||
205 | |||
206 | /** |
||
207 | * Adds the current timestamp to the array of sent notifications. |
||
208 | * |
||
209 | * @param \Illuminate\Notifications\Notification $notification |
||
210 | * @return null |
||
211 | */ |
||
212 | public function markSentFailedNotification(Notification $notification) |
||
223 | |||
224 | /** |
||
225 | * Set the state to passes. |
||
226 | * @return null |
||
227 | */ |
||
228 | public function setToPassing() |
||
242 | } |
||
243 |