@@ -12,13 +12,13 @@ |
||
| 12 | 12 | final class Events |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - const MAIN_LOOP_STARTING = 'mainLoop.starting'; |
|
| 16 | - const INSTANCE_STATUS_UPDATES = 'status.instanceUpdates'; |
|
| 15 | + const MAIN_LOOP_STARTING = 'mainLoop.starting'; |
|
| 16 | + const INSTANCE_STATUS_UPDATES = 'status.instanceUpdates'; |
|
| 17 | 17 | |
| 18 | - const INSTANCE_SEEN = 'persistence.instanceSeen'; |
|
| 19 | - const CONNECTION_SEEN = 'persistence.connectionSeen'; |
|
| 20 | - const INPUT_SEEN = 'persistence.inputSeen'; |
|
| 21 | - const SUBSCRIPTION_SEEN = 'persistence.subscriptionSeen'; |
|
| 22 | - const SUBSCRIPTION_STATE_CHANGE = 'persistence.subscriptionStateChange'; |
|
| 18 | + const INSTANCE_SEEN = 'persistence.instanceSeen'; |
|
| 19 | + const CONNECTION_SEEN = 'persistence.connectionSeen'; |
|
| 20 | + const INPUT_SEEN = 'persistence.inputSeen'; |
|
| 21 | + const SUBSCRIPTION_SEEN = 'persistence.subscriptionSeen'; |
|
| 22 | + const SUBSCRIPTION_STATE_CHANGE = 'persistence.subscriptionStateChange'; |
|
| 23 | 23 | |
| 24 | 24 | } |
@@ -72,8 +72,9 @@ discard block |
||
| 72 | 72 | { |
| 73 | 73 | $instance = $event->getInstance(); |
| 74 | 74 | |
| 75 | - if ($this->hasInstance($instance)) |
|
| 76 | - return; |
|
| 75 | + if ($this->hasInstance($instance)) { |
|
| 76 | + return; |
|
| 77 | + } |
|
| 77 | 78 | |
| 78 | 79 | $instanceModel = new Database\Instance(); |
| 79 | 80 | $instanceModel->setPrimaryKey($instance->getHostname()); |
@@ -104,8 +105,9 @@ discard block |
||
| 104 | 105 | $instanceName = $event->getInstance(); |
| 105 | 106 | $connectionStatus = $event->getConnection(); |
| 106 | 107 | |
| 107 | - if ($this->hasConnection($instanceName, $connectionStatus)) |
|
| 108 | - return; |
|
| 108 | + if ($this->hasConnection($instanceName, $connectionStatus)) { |
|
| 109 | + return; |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | $user = null; |
| 111 | 113 | |
@@ -177,8 +179,9 @@ discard block |
||
| 177 | 179 | $status = $event->getSubscription(); |
| 178 | 180 | |
| 179 | 181 | // Ignore certain subscriptions |
| 180 | - if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) |
|
| 181 | - return; |
|
| 182 | + if (in_array($status->getType(), [SubscriptionStatus::TYPE_EPGGRAB, SubscriptionStatus::TYPE_SERVICE_OR_MUX])) { |
|
| 183 | + return; |
|
| 184 | + } |
|
| 182 | 185 | |
| 183 | 186 | // Determine the username to store for the subscription |
| 184 | 187 | $username = $status->username; |
@@ -198,8 +201,9 @@ discard block |
||
| 198 | 201 | $this->onChannelSeen($instanceName, $status->channel); |
| 199 | 202 | $channel = ChannelQuery::create()->filterByInstance($instance)->filterByName($status->channel)->findOne(); |
| 200 | 203 | |
| 201 | - if ($this->hasSubscription($instance, $user, $channel, $status)) |
|
| 202 | - return; |
|
| 204 | + if ($this->hasSubscription($instance, $user, $channel, $status)) { |
|
| 205 | + return; |
|
| 206 | + } |
|
| 203 | 207 | |
| 204 | 208 | // Try to determine which input is used by the subscription |
| 205 | 209 | $input = InputQuery::create()->filterBySubscriptionStatus($instanceName, $status)->findOne(); |
@@ -238,8 +242,9 @@ discard block |
||
| 238 | 242 | $stateChange = $event->getStateChange(); |
| 239 | 243 | |
| 240 | 244 | // We only need to persist subscription stops |
| 241 | - if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED) |
|
| 242 | - return; |
|
| 245 | + if ($stateChange->getState() === StateChange::STATE_SUBSCRIPTION_STARTED) { |
|
| 246 | + return; |
|
| 247 | + } |
|
| 243 | 248 | |
| 244 | 249 | // Find the latest matching subscription |
| 245 | 250 | $subscription = SubscriptionQuery::create()->filterByInstanceName($instanceName) |
@@ -280,8 +285,9 @@ discard block |
||
| 280 | 285 | */ |
| 281 | 286 | private function onUserSeen($instanceName, $userName) |
| 282 | 287 | { |
| 283 | - if ($this->hasUser($instanceName, $userName)) |
|
| 284 | - return; |
|
| 288 | + if ($this->hasUser($instanceName, $userName)) { |
|
| 289 | + return; |
|
| 290 | + } |
|
| 285 | 291 | |
| 286 | 292 | $user = new User(); |
| 287 | 293 | $user->setInstanceName($instanceName)->setName($userName); |
@@ -302,8 +308,9 @@ discard block |
||
| 302 | 308 | */ |
| 303 | 309 | private function onChannelSeen($instanceName, $channelName) |
| 304 | 310 | { |
| 305 | - if ($this->hasChannel($instanceName, $channelName)) |
|
| 306 | - return; |
|
| 311 | + if ($this->hasChannel($instanceName, $channelName)) { |
|
| 312 | + return; |
|
| 313 | + } |
|
| 307 | 314 | |
| 308 | 315 | $channel = new Channel(); |
| 309 | 316 | $channel->setInstanceName($instanceName)->setName($channelName); |
@@ -80,8 +80,9 @@ discard block |
||
| 80 | 80 | $this->_instances = new \SplObjectStorage(); |
| 81 | 81 | |
| 82 | 82 | // Attach a state to each instance |
| 83 | - foreach ($this->_configuration->getInstances() as $instance) |
|
| 84 | - $this->_instances->attach($instance, new InstanceState()); |
|
| 83 | + foreach ($this->_configuration->getInstances() as $instance) { |
|
| 84 | + $this->_instances->attach($instance, new InstanceState()); |
|
| 85 | + } |
|
| 85 | 86 | |
| 86 | 87 | // Create manager instances |
| 87 | 88 | $this->_persistenceManager = new PersistenceManager($logger); |
@@ -109,8 +110,9 @@ discard block |
||
| 109 | 110 | [Events::SUBSCRIPTION_STATE_CHANGE, $this->_persistenceManager, 'onSubscriptionStateChange'], |
| 110 | 111 | ]; |
| 111 | 112 | |
| 112 | - foreach ($eventDefinitions as $eventDefinition) |
|
| 113 | - $this->_eventDispatcher->addListener($eventDefinition[0], [$eventDefinition[1], $eventDefinition[2]]); |
|
| 113 | + foreach ($eventDefinitions as $eventDefinition) { |
|
| 114 | + $this->_eventDispatcher->addListener($eventDefinition[0], [$eventDefinition[1], $eventDefinition[2]]); |
|
| 115 | + } |
|
| 114 | 116 | } |
| 115 | 117 | |
| 116 | 118 | |
@@ -192,8 +194,9 @@ discard block |
||
| 192 | 194 | } |
| 193 | 195 | |
| 194 | 196 | // Persist inputs |
| 195 | - foreach ($instanceStatus->getInputs() as $input) |
|
| 196 | - $this->_eventDispatcher->dispatch(Events::INPUT_SEEN, new InputSeenEvent($instanceName, $input)); |
|
| 197 | + foreach ($instanceStatus->getInputs() as $input) { |
|
| 198 | + $this->_eventDispatcher->dispatch(Events::INPUT_SEEN, new InputSeenEvent($instanceName, $input)); |
|
| 199 | + } |
|
| 197 | 200 | |
| 198 | 201 | // Persist running subscriptions |
| 199 | 202 | foreach ($instanceStatus->getSubscriptions() as $subscription) |
@@ -255,8 +258,7 @@ discard block |
||
| 255 | 258 | |
| 256 | 259 | $instanceState->setReachability(InstanceState::REACHABLE); |
| 257 | 260 | } |
| 258 | - } |
|
| 259 | - catch (\Exception $e) |
|
| 261 | + } catch (\Exception $e) |
|
| 260 | 262 | { |
| 261 | 263 | // Mark the instance as unreachable |
| 262 | 264 | $message = 'Instance {instanceName} not reachable, will wait for {cycles} cycles before retrying. |
@@ -270,8 +272,7 @@ discard block |
||
| 270 | 272 | |
| 271 | 273 | $instanceState->setReachability(InstanceState::UNREACHABLE); |
| 272 | 274 | } |
| 273 | - } |
|
| 274 | - else |
|
| 275 | + } else |
|
| 275 | 276 | { |
| 276 | 277 | // Wait for some cycles and then mark unreachable instances as maybe reachable |
| 277 | 278 | if ($instanceState->getRetryCount() === self::UNREACHABLE_CYCLES_UNTIL_RETRY - 1) |
@@ -282,9 +283,9 @@ discard block |
||
| 282 | 283 | $this->_logger->info('Retrying instance {instanceName} during next cycle', [ |
| 283 | 284 | 'instanceName' => $instanceName, |
| 284 | 285 | ]); |
| 286 | + } else { |
|
| 287 | + $instanceState->incrementRetryCount(); |
|
| 285 | 288 | } |
| 286 | - else |
|
| 287 | - $instanceState->incrementRetryCount(); |
|
| 288 | 289 | } |
| 289 | 290 | } |
| 290 | 291 | |