@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function store($key, $timeout, array $data = []) { |
64 | 64 | $key = trim(strtolower($key)); |
65 | - if(!in_array($key, $this->services)) { |
|
65 | + if (!in_array($key, $this->services)) { |
|
66 | 66 | $this->services[] = $key; |
67 | 67 | } else { |
68 | 68 | throw new RuntimeException("Duplicate service: {$key}"); |
69 | 69 | } |
70 | 70 | |
71 | - if($this->has($key)) { |
|
71 | + if ($this->has($key)) { |
|
72 | 72 | $this->updateService->execute(['key' => $key, 'timeout' => $timeout]); |
73 | 73 | } else { |
74 | 74 | $this->insertService->execute(['key' => $key, 'timeout' => $timeout, 'try' => '2000-01-01 00:00:00', 'run' => '2000-01-01 00:00:00']); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $this->pdo->exec('START TRANSACTION'); |
88 | 88 | try { |
89 | 89 | $services = $this->fetchServices(); |
90 | - foreach($services as $service) { |
|
90 | + foreach ($services as $service) { |
|
91 | 91 | $this->updateTryDate->execute(['key' => $service['service_key']]); |
92 | 92 | $fn($service); |
93 | 93 | $this->updateRunDate->execute(['key' => $service['service_key']]); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | } |
96 | 96 | $this->pdo->exec('COMMIT'); |
97 | 97 | return $count; |
98 | - } catch(Throwable $e) { |
|
98 | + } catch (Throwable $e) { |
|
99 | 99 | $this->pdo->exec('ROLLBACK'); |
100 | 100 | throw $e; |
101 | 101 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $this->selectServices->execute(); |
109 | 109 | try { |
110 | 110 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); |
111 | - foreach($services as $service) { |
|
111 | + foreach ($services as $service) { |
|
112 | 112 | yield new Service($service['service_key']); |
113 | 113 | } |
114 | 114 | } finally { |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function store($key, $timeout, array $data = []) { |
67 | 67 | $key = trim(strtolower($key)); |
68 | - if(!in_array($key, $this->services)) { |
|
68 | + if (!in_array($key, $this->services)) { |
|
69 | 69 | $this->services[] = $key; |
70 | 70 | } else { |
71 | 71 | throw new RuntimeException("Duplicate service: {$key}"); |
72 | 72 | } |
73 | 73 | |
74 | - if($this->has($key)) { |
|
74 | + if ($this->has($key)) { |
|
75 | 75 | $this->updateService->execute(['key' => $key, 'timeout' => $timeout]); |
76 | 76 | } else { |
77 | 77 | $this->insertService->execute(['key' => $key, 'timeout' => $timeout, 'try' => '2000-01-01 00:00:00', 'run' => '2000-01-01 00:00:00']); |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->pdo->exec('BEGIN EXCLUSIVE TRANSACTION'); |
91 | 91 | try { |
92 | 92 | $services = $this->fetchServices(); |
93 | - foreach($services as $service) { |
|
93 | + foreach ($services as $service) { |
|
94 | 94 | $this->updateTryDate->execute(['key' => $service->getKey()]); |
95 | 95 | $fn($service); |
96 | 96 | $this->updateRunDate->execute(['key' => $service->getKey()]); |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | } |
99 | 99 | $this->pdo->exec('COMMIT'); |
100 | 100 | return $count; |
101 | - } catch(Throwable $e) { |
|
101 | + } catch (Throwable $e) { |
|
102 | 102 | $this->pdo->exec('ROLLBACK'); |
103 | 103 | throw $e; |
104 | 104 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $this->selectServices->execute(); |
112 | 112 | try { |
113 | 113 | $services = $this->selectServices->fetchAll(PDO::FETCH_ASSOC); |
114 | - foreach($services as $service) { |
|
114 | + foreach ($services as $service) { |
|
115 | 115 | yield new Service($service['service_key']); |
116 | 116 | } |
117 | 117 | } finally { |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * @return $this |
57 | 57 | */ |
58 | 58 | public function on($event, $fn) { |
59 | - if(!array_key_exists($event, $this->listeners)) { |
|
59 | + if (!array_key_exists($event, $this->listeners)) { |
|
60 | 60 | $this->listeners[$event] = array(); |
61 | 61 | } |
62 | 62 | $this->listeners[$event][] = $fn; |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | * @return int Number of successfully executed services |
68 | 68 | */ |
69 | 69 | public function run() { |
70 | - return $this->attributeRepository->lockAndIterateServices(function (Service $service) { |
|
71 | - if(!array_key_exists($service->getKey(), $this->services)) { |
|
70 | + return $this->attributeRepository->lockAndIterateServices(function(Service $service) { |
|
71 | + if (!array_key_exists($service->getKey(), $this->services)) { |
|
72 | 72 | return; |
73 | 73 | } |
74 | - if(array_key_exists($service->getKey(), $this->standardTimeouts)) { |
|
74 | + if (array_key_exists($service->getKey(), $this->standardTimeouts)) { |
|
75 | 75 | $standardTimeout = $this->standardTimeouts[$service->getKey()]; |
76 | 76 | } else { |
77 | 77 | $standardTimeout = 0; |
@@ -82,18 +82,18 @@ discard block |
||
82 | 82 | ]; |
83 | 83 | try { |
84 | 84 | $this->fireEvent('service-start', $eventParams); |
85 | - if($this->methodInvoker !== null) { |
|
85 | + if ($this->methodInvoker !== null) { |
|
86 | 86 | $result = $this->methodInvoker->invoke($this->services[$service->getKey()], $eventParams); |
87 | 87 | } else { |
88 | 88 | $result = call_user_func($this->services[$service->getKey()], $service); |
89 | 89 | } |
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,14 +107,14 @@ discard block |
||
107 | 107 | * @param array $params |
108 | 108 | */ |
109 | 109 | private function fireEvent($event, $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) { |
|
112 | + foreach ($this->listeners[$event] as $listener) { |
|
113 | 113 | $this->methodInvoker->invoke($listener, $params); |
114 | 114 | } |
115 | 115 | } catch (Exception $e) { |
116 | 116 | // Supress exceptions emitted by events |
117 | - if($this->logger !== null) { |
|
117 | + if ($this->logger !== null) { |
|
118 | 118 | $this->logger->critical($e->getMessage(), array('exception' => $e)); |
119 | 119 | } |
120 | 120 | } |