@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @return $this |
| 58 | 58 | */ |
| 59 | 59 | public function on(string $event, callable $fn) { |
| 60 | - if(!array_key_exists($event, $this->listeners)) { |
|
| 60 | + if (!array_key_exists($event, $this->listeners)) { |
|
| 61 | 61 | $this->listeners[$event] = []; |
| 62 | 62 | } |
| 63 | 63 | $this->listeners[$event][] = $fn; |
@@ -70,8 +70,8 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function run(DateTimeInterface $now = null): int { |
| 72 | 72 | $dt = $now ?? date_create_immutable(); |
| 73 | - return $this->attributeRepository->lockAndIterateServices($dt, function (Service $service) { |
|
| 74 | - if(!array_key_exists($service->getKey(), $this->services)) { |
|
| 73 | + return $this->attributeRepository->lockAndIterateServices($dt, function(Service $service) { |
|
| 74 | + if (!array_key_exists($service->getKey(), $this->services)) { |
|
| 75 | 75 | return; |
| 76 | 76 | } |
| 77 | 77 | $eventParams = ['serviceName' => $service->getKey()]; |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $this->fireEvent('service-start', $eventParams); |
| 80 | 80 | $serviceData = $this->services[$service->getKey()]; |
| 81 | 81 | $this->attributeRepository->setLastTryDate($service->getKey(), date_create_immutable()); |
| 82 | - if($this->methodInvoker !== null) { |
|
| 82 | + if ($this->methodInvoker !== null) { |
|
| 83 | 83 | $result = $this->methodInvoker->invoke($serviceData->fn, $eventParams); |
| 84 | 84 | } else { |
| 85 | 85 | $result = call_user_func($serviceData->fn, $service); |
@@ -87,13 +87,13 @@ discard block |
||
| 87 | 87 | $this->attributeRepository->setLastRunDate($service->getKey(), date_create_immutable()); |
| 88 | 88 | $nextRunDate = IntervalParser::getNext($serviceData->interval); |
| 89 | 89 | $this->attributeRepository->setNextRunDate($serviceData->key, $nextRunDate); |
| 90 | - if($result !== false) { |
|
| 90 | + if ($result !== false) { |
|
| 91 | 91 | $this->fireEvent('service-success', $eventParams); |
| 92 | 92 | } |
| 93 | 93 | } catch (Throwable $e) { |
| 94 | 94 | $eventParams['exception'] = $e; |
| 95 | 95 | $this->fireEvent('service-failure', $eventParams); |
| 96 | - if($this->logger !== null) { |
|
| 96 | + if ($this->logger !== null) { |
|
| 97 | 97 | $this->logger->critical("{$service}: {$e->getMessage()}", ['exception' => $e]); |
| 98 | 98 | } else { |
| 99 | 99 | throw new RuntimeException("{$service}: {$e->getMessage()}", (int) $e->getCode(), $e); |
@@ -107,10 +107,10 @@ discard block |
||
| 107 | 107 | * @param array $params |
| 108 | 108 | */ |
| 109 | 109 | private function fireEvent(string $event, array $params) { |
| 110 | - if(array_key_exists($event, $this->listeners)) { |
|
| 110 | + if (array_key_exists($event, $this->listeners)) { |
|
| 111 | 111 | try { |
| 112 | - foreach($this->listeners[$event] as $listener) { |
|
| 113 | - if($this->methodInvoker !== null) { |
|
| 112 | + foreach ($this->listeners[$event] as $listener) { |
|
| 113 | + if ($this->methodInvoker !== null) { |
|
| 114 | 114 | $this->methodInvoker->invoke($listener, $params); |
| 115 | 115 | } else { |
| 116 | 116 | call_user_func($listener, $params['serviceName'] ?? null); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | } catch (Exception $e) { |
| 120 | 120 | // Supress exceptions emitted by events |
| 121 | - if($this->logger !== null) { |
|
| 121 | + if ($this->logger !== null) { |
|
| 122 | 122 | $this->logger->critical($e->getMessage(), array('exception' => $e)); |
| 123 | 123 | } |
| 124 | 124 | } |