1 | <?php |
||
2 | |||
3 | namespace ProtoneMedia\ApiHealth\Checkers; |
||
4 | |||
5 | use Illuminate\Console\Scheduling\CacheEventMutex; |
||
6 | use Illuminate\Console\Scheduling\Event; |
||
7 | use Illuminate\Console\Scheduling\EventMutex; |
||
8 | |||
9 | trait IsScheduled |
||
10 | { |
||
11 | /** |
||
12 | * Event object that is used to manages the frequency. |
||
13 | * |
||
14 | * @var \Illuminate\Console\Scheduling\Event |
||
15 | */ |
||
16 | private $event; |
||
17 | |||
18 | /** |
||
19 | * Returns the EventMutex bound to the container or creates a new instance. |
||
20 | * |
||
21 | * @return \Illuminate\Console\Scheduling\EventMutex |
||
22 | */ |
||
23 | private function eventMutex(): EventMutex |
||
24 | { |
||
25 | if (app()->bound(EventMutex::class)) { |
||
26 | return app()->make(EventMutex::class); |
||
27 | } |
||
28 | |||
29 | return app()->make(CacheEventMutex::class); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Returns the Event that is used to manages the frequency. |
||
34 | * |
||
35 | * @return \Illuminate\Console\Scheduling\Event |
||
36 | */ |
||
37 | private function event(): Event |
||
38 | { |
||
39 | if (!$this->event) { |
||
40 | $this->event = new Event($this->eventMutex(), ''); |
||
41 | } |
||
42 | |||
43 | return $this->event; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Determine if the checker is due to run based on the current date. |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | public function isDue(): bool |
||
52 | { |
||
53 | $this->schedule($this->event()); |
||
54 | |||
55 | return $this->event->isDue(app()); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Defines the checker's schedule. |
||
60 | * |
||
61 | * @param \Illuminate\Console\Scheduling\Event $event |
||
62 | * @return void |
||
63 | */ |
||
64 | public function schedule(Event $event) |
||
65 | { |
||
66 | $event->everyMinute(); |
||
67 | } |
||
68 | } |
||
69 |