Completed
Push — master ( 6d900e...8f4d90 )
by Nicolas
01:39
created
client_example/ClientCommander.php 1 patch
Braces   +50 added lines, -41 removed lines patch added patch discarded remove patch
@@ -38,8 +38,7 @@  discard block
 block discarded – undo
38 38
         $decodedClient = json_decode($clientInfo);
39 39
         
40 40
         $CpeClientSdk->start_job($decodedClient, $content);
41
-    }
42
-    catch (Exception $e) {
41
+    } catch (Exception $e) {
43 42
         print("[ERROR] " . $e->getMessage() . "\n");
44 43
     }
45 44
 }
@@ -68,42 +67,51 @@  discard block
 block discarded – undo
68 67
     global $argv;
69 68
         
70 69
     // Handle input parameters
71
-    if (!($options = getopt("c:k::s::r::hd")))
72
-        usage();
73
-    if (isset($options['h']))
74
-        usage();
70
+    if (!($options = getopt("c:k::s::r::hd"))) {
71
+            usage();
72
+    }
73
+    if (isset($options['h'])) {
74
+            usage();
75
+    }
75 76
     
76
-    if (isset($options['d']))
77
-        $debug = true;
77
+    if (isset($options['d'])) {
78
+            $debug = true;
79
+    }
78 80
   
79 81
     if (isset($options['c']))
80 82
     {
81 83
         $clientConfFile = $options['c'];
82
-        if (!file_exists($clientConfFile))
83
-            throw new Exception("The client config file is not valid!");
84
-        if (!($clientInfo = file_get_contents($clientConfFile)))
85
-            throw new Exception("Unable to read the file");
86
-    }
87
-    else
88
-        throw new Exception("Please provide the client config file!");
89
-
90
-    if (isset($options['k']))
91
-        $key = $options['k'];
92
-    else
93
-        $key = getenv("AWS_ACCESS_KEY_ID");
84
+        if (!file_exists($clientConfFile)) {
85
+                    throw new Exception("The client config file is not valid!");
86
+        }
87
+        if (!($clientInfo = file_get_contents($clientConfFile))) {
88
+                    throw new Exception("Unable to read the file");
89
+        }
90
+    } else {
91
+            throw new Exception("Please provide the client config file!");
92
+    }
93
+
94
+    if (isset($options['k'])) {
95
+            $key = $options['k'];
96
+    } else {
97
+            $key = getenv("AWS_ACCESS_KEY_ID");
98
+    }
94 99
     
95
-    if (isset($options['s']))
96
-        $secret = $options['s'];
97
-    else
98
-        $secret = getenv("AWS_SECRET_KEY");
99
-
100
-    if (isset($options['r']))
101
-        $region = $options['r'];
102
-    else 
103
-        $region = getenv("AWS_DEFAULT_REGION");
104
-    if (!$region)
105
-        throw new Exception("Please provide your AWS region as parameter or using AWS_DEFAULT_REGION env var !");
106
-}
100
+    if (isset($options['s'])) {
101
+            $secret = $options['s'];
102
+    } else {
103
+            $secret = getenv("AWS_SECRET_KEY");
104
+    }
105
+
106
+    if (isset($options['r'])) {
107
+            $region = $options['r'];
108
+    } else {
109
+            $region = getenv("AWS_DEFAULT_REGION");
110
+    }
111
+    if (!$region) {
112
+            throw new Exception("Please provide your AWS region as parameter or using AWS_DEFAULT_REGION env var !");
113
+    }
114
+    }
107 115
 
108 116
     function usage()
109 117
     {
@@ -123,8 +131,7 @@  discard block
 block discarded – undo
123 131
 
124 132
 try {
125 133
     check_input_parameters();
126
-} 
127
-catch (Exception $e) {
134
+} catch (Exception $e) {
128 135
     print "[ERROR] " . $e->getMessage() . "\n";
129 136
     exit(2);
130 137
 }
@@ -147,14 +154,16 @@  discard block
 block discarded – undo
147 154
 {
148 155
     // Prompt (<3 php)
149 156
     $line = readline("Command [enter]: ");
150
-    if (!$line)
151
-        continue;
157
+    if (!$line) {
158
+            continue;
159
+    }
152 160
     readline_add_history($line);
153 161
 
154 162
     // Process user input
155 163
     $args = explode(" ", $line);
156
-    if (!isset($commandMap[$args[0]]))
157
-        print "[ERROR] Command not found!\n";
158
-    else 
159
-        $commandMap[$args[0]]($args);
160
-}
161 164
\ No newline at end of file
165
+    if (!isset($commandMap[$args[0]])) {
166
+            print "[ERROR] Command not found!\n";
167
+    } else {
168
+            $commandMap[$args[0]]($args);
169
+    }
170
+    }
162 171
\ No newline at end of file
Please login to merge, or discard this patch.
pollers/src/InputPoller.php 1 patch
Braces   +29 added lines, -21 removed lines patch added patch discarded remove patch
@@ -95,13 +95,14 @@  discard block
 block discarded – undo
95 95
             try {
96 96
                 if ($msg = $this->cpeSqsListener->receive_message($queue, 10))
97 97
                 {
98
-                    if (!($decoded = json_decode($msg['Body'])))
99
-                        $this->cpeLogger->log_out(
98
+                    if (!($decoded = json_decode($msg['Body']))) {
99
+                                            $this->cpeLogger->log_out(
100 100
                             "ERROR", 
101 101
                             basename(__FILE__), 
102 102
                             "JSON data invalid in queue: '$queue'");
103
-                    else                    
104
-                        $this->handle_message($decoded);
103
+                    } else {
104
+                                            $this->handle_message($decoded);
105
+                    }
105 106
                 }
106 107
             } catch (CpeSdk\CpeException $e) {
107 108
                 $this->cpeLogger->log_out(
@@ -116,8 +117,9 @@  discard block
 block discarded – undo
116 117
             }
117 118
             
118 119
             // Message polled. Valid or not, we delete it from SQS
119
-            if ($msg)
120
-                $this->cpeSqsListener->delete_message($queue, $msg);
120
+            if ($msg) {
121
+                            $this->cpeSqsListener->delete_message($queue, $msg);
122
+            }
121 123
         }
122 124
     }
123 125
 
@@ -142,12 +144,13 @@  discard block
 block discarded – undo
142 144
             basename(__FILE__), 
143 145
             "Received message '" . $message->{"type"}  . "'"
144 146
         );
145
-        if ($this->debug)
146
-            $this->cpeLogger->log_out(
147
+        if ($this->debug) {
148
+                    $this->cpeLogger->log_out(
147 149
                 "DEBUG", 
148 150
                 basename(__FILE__), 
149 151
                 "Details:\n" . json_encode($message, JSON_PRETTY_PRINT)
150 152
             );
153
+        }
151 154
 
152 155
         // We call the callback function that handles this message  
153 156
         $this->{$this->typesMap[$message->{"type"}]}($message);
@@ -161,12 +164,13 @@  discard block
 block discarded – undo
161 164
     // Start a new workflow in SWF to initiate new transcoding job
162 165
     private function start_job($message)
163 166
     {
164
-        if ($this->debug)
165
-            $this->cpeLogger->log_out(
167
+        if ($this->debug) {
168
+                    $this->cpeLogger->log_out(
166 169
                 "DEBUG",
167 170
                 basename(__FILE__),
168 171
                 "Starting new workflow!"
169 172
             );
173
+        }
170 174
         
171 175
         // Workflow info
172 176
         $workflowType = array(
@@ -218,13 +222,15 @@  discard block
 block discarded – undo
218 222
             !isset($message->{"time"})   || $message->{"time"} == "" || 
219 223
             !isset($message->{"jobId"})  || $message->{"jobId"} == "" || 
220 224
             !isset($message->{"type"})   || $message->{"type"} == "" || 
221
-            !isset($message->{"data"})   || $message->{"data"} == "")
222
-            throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
225
+            !isset($message->{"data"})   || $message->{"data"} == "") {
226
+                    throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
223 227
                 self::INVALID_JSON);
228
+        }
224 229
         
225
-        if (!isset($message->{'data'}->{'workflow'}))
226
-            throw new CpeSdk\CpeException("Input doesn't contain any workflow information. You must provide the workflow you want to send this job to!",
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!",
227 232
                 self::INVALID_JSON);
233
+        }
228 234
     }
229 235
 }
230 236
 
@@ -255,11 +261,13 @@  discard block
 block discarded – undo
255 261
     // Handle input parameters
256 262
     $options = getopt("c:l:hdn:");
257 263
 
258
-    if (isset($options['h']))
259
-        usage($defaultConfigFile);
264
+    if (isset($options['h'])) {
265
+            usage($defaultConfigFile);
266
+    }
260 267
     
261
-    if (isset($options['d']))
262
-        $debug = true;
268
+    if (isset($options['d'])) {
269
+            $debug = true;
270
+    }
263 271
     
264 272
     $logPath = null;
265 273
     if (isset($options['l']))
@@ -314,8 +322,7 @@  discard block
 block discarded – undo
314 322
 // Create InputPoller object
315 323
 try {
316 324
     $inputPoller = new InputPoller($config);
317
-}
318
-catch (CpeSdk\CpeException $e) {
325
+} catch (CpeSdk\CpeException $e) {
319 326
     echo $e->getMessage();
320 327
     $cpeLogger->log_out(
321 328
         "FATAL", 
@@ -326,5 +333,6 @@  discard block
 block discarded – undo
326 333
 }
327 334
 
328 335
 // Start polling loop to get incoming commands from SQS input queues
329
-while (42)
336
+while (42) {
330 337
     $inputPoller->poll_SQS_queues();
338
+}
Please login to merge, or discard this patch.
pollers/src/ActivityPoller.php 1 patch
Braces   +27 added lines, -19 removed lines patch added patch discarded remove patch
@@ -78,8 +78,9 @@  discard block
 block discarded – undo
78 78
         $this->cpeSwfHandler   = new CpeSdk\Swf\CpeSwfHandler($this->debug);
79 79
         
80 80
         // Check and load activities to handle
81
-        if (!$this->register_activities())
82
-            die("No activity class registered! Check the logs (/var/tmp/logs/cpe/). Exiting ...\n");
81
+        if (!$this->register_activities()) {
82
+                    die("No activity class registered! Check the logs (/var/tmp/logs/cpe/). Exiting ...\n");
83
+        }
83 84
     }
84 85
     
85 86
     // We poll for new activities
@@ -88,9 +89,10 @@  discard block
 block discarded – undo
88 89
     public function poll_for_activities()
89 90
     {
90 91
         // Poll from all the taskList registered for each activities 
91
-        if ($this->debug)
92
-            $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
92
+        if ($this->debug) {
93
+                    $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
93 94
                 "Polling activity taskList '" . $this->taskList  . "' ... ");
95
+        }
94 96
             
95 97
         try {
96 98
             // Call SWF and poll for incoming tasks
@@ -114,8 +116,9 @@  discard block
 block discarded – undo
114 116
     {
115 117
         // Get activityType and WorkflowExecution info
116 118
         if (!($activityType      = $activityTask->get("activityType")) ||
117
-            !($workflowExecution = $activityTask->get("workflowExecution")))
118
-            return false;
119
+            !($workflowExecution = $activityTask->get("workflowExecution"))) {
120
+                    return false;
121
+        }
119 122
         
120 123
         $this->cpeLogger->log_out("INFO",
121 124
             basename(__FILE__),
@@ -142,16 +145,18 @@  discard block
 block discarded – undo
142 145
             // Perform input validation
143 146
             $this->activityHandler->do_input_validation();
144 147
 
145
-            if ($this->debug)
146
-                $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
148
+            if ($this->debug) {
149
+                            $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
147 150
                     "Activity input:\n" . print_r($this->activityHandler->input, true));
151
+            }
148 152
         
149 153
             // Run activity task
150 154
             $result = $this->activityHandler->do_activity($activityTask);
151 155
 
152
-            if ($this->debug && $result)
153
-                $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
156
+            if ($this->debug && $result) {
157
+                            $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
154 158
                     "Activity output:\n" . print_r($result, true));
159
+            }
155 160
         
156 161
         } catch (CpeSdk\CpeException $e) {
157 162
             $reason  = $e->ref;
@@ -270,15 +275,18 @@  discard block
 block discarded – undo
270 275
     global $activityVersion;
271 276
     
272 277
     // Handle input parameters
273
-    if (!($options = getopt("D:T:A:V:c:l:hd")))
274
-        usage($defaultConfigFile);
278
+    if (!($options = getopt("D:T:A:V:c:l:hd"))) {
279
+            usage($defaultConfigFile);
280
+    }
275 281
     
276
-    if (!count($options) || isset($options['h']))
277
-        usage($defaultConfigFile);
282
+    if (!count($options) || isset($options['h'])) {
283
+            usage($defaultConfigFile);
284
+    }
278 285
 
279 286
     // Debug
280
-    if (isset($options['d']))
281
-        $debug = true;
287
+    if (isset($options['d'])) {
288
+            $debug = true;
289
+    }
282 290
 
283 291
     // Domain
284 292
     if (!isset($options['D']))
@@ -348,8 +356,7 @@  discard block
 block discarded – undo
348 356
 // Instantiate ActivityPoller
349 357
 try {
350 358
     $activityPoller = new ActivityPoller($config);
351
-} 
352
-catch (CpeSdk\CpeException $e) {
359
+} catch (CpeSdk\CpeException $e) {
353 360
     $cpeLogger->log_out("FATAL",
354 361
         basename(__FILE__), $e->getMessage());
355 362
     exit(1);
@@ -358,6 +365,7 @@  discard block
 block discarded – undo
358 365
 $cpeLogger->log_out("INFO", basename(__FILE__), "Starting activity tasks polling");
359 366
 
360 367
 // Start polling loop
361
-while (42)
368
+while (42) {
362 369
     $activityPoller->poll_for_activities();
370
+}
363 371
 
Please login to merge, or discard this patch.