@@ -84,9 +84,10 @@ discard block |
||
| 84 | 84 | // If a msg is received, we pass it to 'handle_input' for processing |
| 85 | 85 | public function poll_SQS_queues() |
| 86 | 86 | { |
| 87 | - if (!isset($this->config->{'clients'})) |
|
| 88 | - throw new CpeSdk\CpeException("Clients configuration invalid. Check the config file or your parameters.", |
|
| 87 | + if (!isset($this->config->{'clients'})) { |
|
| 88 | + throw new CpeSdk\CpeException("Clients configuration invalid. Check the config file or your parameters.", |
|
| 89 | 89 | self::INVALID_CONFIG); |
| 90 | + } |
|
| 90 | 91 | |
| 91 | 92 | // For all clients in config files |
| 92 | 93 | // We poll from queues |
@@ -100,13 +101,14 @@ discard block |
||
| 100 | 101 | try { |
| 101 | 102 | if ($msg = $this->cpeSqsListener->receive_message($queue, 10)) |
| 102 | 103 | { |
| 103 | - if (!($decoded = json_decode($msg['Body']))) |
|
| 104 | - $this->cpeLogger->log_out( |
|
| 104 | + if (!($decoded = json_decode($msg['Body']))) { |
|
| 105 | + $this->cpeLogger->log_out( |
|
| 105 | 106 | "ERROR", |
| 106 | 107 | basename(__FILE__), |
| 107 | 108 | "JSON data invalid in queue: '$queue'"); |
| 108 | - else |
|
| 109 | - $this->handle_message($decoded); |
|
| 109 | + } else { |
|
| 110 | + $this->handle_message($decoded); |
|
| 111 | + } |
|
| 110 | 112 | } |
| 111 | 113 | } catch (CpeSdk\CpeException $e) { |
| 112 | 114 | $this->cpeLogger->log_out( |
@@ -121,8 +123,9 @@ discard block |
||
| 121 | 123 | } |
| 122 | 124 | |
| 123 | 125 | // Message polled. Valid or not, we delete it from SQS |
| 124 | - if ($msg) |
|
| 125 | - $this->cpeSqsListener->delete_message($queue, $msg); |
|
| 126 | + if ($msg) { |
|
| 127 | + $this->cpeSqsListener->delete_message($queue, $msg); |
|
| 128 | + } |
|
| 126 | 129 | } |
| 127 | 130 | } |
| 128 | 131 | |
@@ -147,12 +150,13 @@ discard block |
||
| 147 | 150 | basename(__FILE__), |
| 148 | 151 | "Received message '" . $message->{"type"} . "'" |
| 149 | 152 | ); |
| 150 | - if ($this->debug) |
|
| 151 | - $this->cpeLogger->log_out( |
|
| 153 | + if ($this->debug) { |
|
| 154 | + $this->cpeLogger->log_out( |
|
| 152 | 155 | "DEBUG", |
| 153 | 156 | basename(__FILE__), |
| 154 | 157 | "Details:\n" . json_encode($message, JSON_PRETTY_PRINT) |
| 155 | 158 | ); |
| 159 | + } |
|
| 156 | 160 | |
| 157 | 161 | // We call the callback function that handles this message |
| 158 | 162 | $this->{$this->typesMap[$message->{"type"}]}($message); |
@@ -166,12 +170,13 @@ discard block |
||
| 166 | 170 | // Start a new workflow in SWF to initiate new transcoding job |
| 167 | 171 | private function start_job($message) |
| 168 | 172 | { |
| 169 | - if ($this->debug) |
|
| 170 | - $this->cpeLogger->log_out( |
|
| 173 | + if ($this->debug) { |
|
| 174 | + $this->cpeLogger->log_out( |
|
| 171 | 175 | "DEBUG", |
| 172 | 176 | basename(__FILE__), |
| 173 | 177 | "Starting new workflow!" |
| 174 | 178 | ); |
| 179 | + } |
|
| 175 | 180 | |
| 176 | 181 | // Workflow info |
| 177 | 182 | $workflowType = array( |
@@ -223,13 +228,15 @@ discard block |
||
| 223 | 228 | !isset($message->{"time"}) || $message->{"time"} == "" || |
| 224 | 229 | !isset($message->{"jobId"}) || $message->{"jobId"} == "" || |
| 225 | 230 | !isset($message->{"type"}) || $message->{"type"} == "" || |
| 226 | - !isset($message->{"data"}) || $message->{"data"} == "") |
|
| 227 | - throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!", |
|
| 231 | + !isset($message->{"data"}) || $message->{"data"} == "") { |
|
| 232 | + throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!", |
|
| 228 | 233 | self::INVALID_JSON); |
| 234 | + } |
|
| 229 | 235 | |
| 230 | - if (!isset($message->{'data'}->{'workflow'})) |
|
| 231 | - throw new CpeSdk\CpeException("Input doesn't contain any workflow information. You must provide the workflow you want to send this job to!", |
|
| 236 | + if (!isset($message->{'data'}->{'workflow'})) { |
|
| 237 | + throw new CpeSdk\CpeException("Input doesn't contain any workflow information. You must provide the workflow you want to send this job to!", |
|
| 232 | 238 | self::INVALID_JSON); |
| 239 | + } |
|
| 233 | 240 | } |
| 234 | 241 | } |
| 235 | 242 | |
@@ -260,11 +267,13 @@ discard block |
||
| 260 | 267 | // Handle input parameters |
| 261 | 268 | $options = getopt("c:l:hdn:"); |
| 262 | 269 | |
| 263 | - if (isset($options['h'])) |
|
| 264 | - usage($defaultConfigFile); |
|
| 270 | + if (isset($options['h'])) { |
|
| 271 | + usage($defaultConfigFile); |
|
| 272 | + } |
|
| 265 | 273 | |
| 266 | - if (isset($options['d'])) |
|
| 267 | - $debug = true; |
|
| 274 | + if (isset($options['d'])) { |
|
| 275 | + $debug = true; |
|
| 276 | + } |
|
| 268 | 277 | |
| 269 | 278 | $logPath = null; |
| 270 | 279 | if (isset($options['l'])) |
@@ -319,8 +328,7 @@ discard block |
||
| 319 | 328 | // Create InputPoller object |
| 320 | 329 | try { |
| 321 | 330 | $inputPoller = new InputPoller($config); |
| 322 | -} |
|
| 323 | -catch (CpeSdk\CpeException $e) { |
|
| 331 | +} catch (CpeSdk\CpeException $e) { |
|
| 324 | 332 | echo $e->getMessage(); |
| 325 | 333 | $cpeLogger->log_out( |
| 326 | 334 | "FATAL", |
@@ -331,5 +339,6 @@ discard block |
||
| 331 | 339 | } |
| 332 | 340 | |
| 333 | 341 | // Start polling loop to get incoming commands from SQS input queues |
| 334 | -while (42) |
|
| 342 | +while (42) { |
|
| 335 | 343 | $inputPoller->poll_SQS_queues(); |
| 344 | +} |
|