Completed
Push — master ( 8f4d90...0c490c )
by Nicolas
03:54
created
client_example/ClientCommander.php 4 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
     $CpeClientSdk = new SA\CpeClientSdk($key, $secret, $region, $debug);
135 135
 } catch (Exception $e) {
136 136
     exit($e->getMessage());
137
-  }
137
+    }
138 138
 
139 139
 // Commands mapping
140 140
 $commandMap = [
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,7 +109,7 @@
 block discarded – undo
109 109
     {
110 110
         global $help;
111 111
     
112
-        echo("Usage: php ". basename(__FILE__) . " -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
112
+        echo("Usage: php " . basename(__FILE__) . " -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
113 113
         echo("-h: Print this help\n");
114 114
         echo("-d: Debug mode\n");
115 115
         echo("-c: configFile\n");
Please login to merge, or discard this 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.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
 Commands:
56 56
 start_job <filepath>: Start a new job. Pass a JSON file containing the instruction (see: input_samples folder)
57 57
 
58
-EOF;
58
+eof;
59 59
 
60 60
     
61 61
 function check_input_parameters()
Please login to merge, or discard this patch.
pollers/src/InputPoller.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
                 $this->cpeLogger->log_out(
108 108
                     "ERROR", 
109 109
                     basename(__FILE__), 
110
-                    $e->getMessage().print_r($msg, true));
110
+                    $e->getMessage() . print_r($msg, true));
111 111
             } catch (\Exception $e) {
112 112
                 $this->cpeLogger->log_out(
113 113
                     "ERROR", 
114 114
                     basename(__FILE__), 
115
-                    $e->getMessage().print_r($msg, true));
115
+                    $e->getMessage() . print_r($msg, true));
116 116
             }
117 117
             
118 118
             // Message polled. Valid or not, we delete it from SQS
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
         $this->cpeLogger->log_out(
141 141
             "INFO", 
142 142
             basename(__FILE__), 
143
-            "Received message '" . $message->{"type"}  . "'"
143
+            "Received message '" . $message->{"type"} . "'"
144 144
         );
145 145
         if ($this->debug)
146 146
             $this->cpeLogger->log_out(
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
             $this->cpeLogger->log_out(
190 190
                 "INFO",
191 191
                 basename(__FILE__),
192
-                "New workflow submitted to SWF: ".$workflowRunId->get('runId'));
192
+                "New workflow submitted to SWF: " . $workflowRunId->get('runId'));
193 193
 
194 194
             // Send WORKFLOW_SCHEDULED message back to client
195 195
             $this->cpeSqsWriter->workflow_scheduled($workflowType, $workflowRunId->get('runId'), $workflowId, $message);
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
     private function validate_message($message)
216 216
     {
217 217
         if (!isset($message) || 
218
-            !isset($message->{"time"})   || $message->{"time"} == "" || 
219
-            !isset($message->{"jobId"})  || $message->{"jobId"} == "" || 
220
-            !isset($message->{"type"})   || $message->{"type"} == "" || 
221
-            !isset($message->{"data"})   || $message->{"data"} == "")
218
+            !isset($message->{"time"}) || $message->{"time"} == "" || 
219
+            !isset($message->{"jobId"}) || $message->{"jobId"} == "" || 
220
+            !isset($message->{"type"}) || $message->{"type"} == "" || 
221
+            !isset($message->{"data"}) || $message->{"data"} == "")
222 222
             throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
223 223
                 self::INVALID_JSON);
224 224
         
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
 function usage($defaultConfigFile)
240 240
 {
241
-    echo("Usage: php ". basename(__FILE__) . " [-h] [-d] [-n <client_name>] [-l <log path>] -c <config_file path>\n");
241
+    echo("Usage: php " . basename(__FILE__) . " [-h] [-d] [-n <client_name>] [-l <log path>] -c <config_file path>\n");
242 242
     echo("-h: Print this help\n");
243 243
     echo("-d: Debug mode\n");
244 244
     echo("-l <log_path>: Location where logs will be dumped in (folder).\n");
@@ -289,9 +289,9 @@  discard block
 block discarded – undo
289 289
 
290 290
     if (isset($options['n']))
291 291
     {
292
-        $config->clients = [(object)[
292
+        $config->clients = [(object) [
293 293
             'name' => $options['n'],
294
-            'queues' => (object)[
294
+            'queues' => (object) [
295 295
                 'input' => getenv('INPUT_QUEUE'),
296 296
                 'output' => getenv('OUTPUT_QUEUE'),
297 297
             ],
Please login to merge, or discard this patch.
Braces   +32 added lines, -23 removed lines patch added patch discarded remove patch
@@ -84,9 +84,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
+}
Please login to merge, or discard this patch.
pollers/src/ActivityPoller.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
         // Poll from all the taskList registered for each activities 
91 91
         if ($this->debug)
92 92
             $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
93
-                "Polling activity taskList '" . $this->taskList  . "' ... ");
93
+                "Polling activity taskList '" . $this->taskList . "' ... ");
94 94
             
95 95
         try {
96 96
             // Call SWF and poll for incoming tasks
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
                 if (!file_exists($activityToHandle->{"file"}))
192 192
                 {
193 193
                     $this->cpeLogger->log_out("ERROR", basename(__FILE__),
194
-                        "The code file '".$activityToHandle->{"file"}."' for activity: name=" 
194
+                        "The code file '" . $activityToHandle->{"file"} . "' for activity: name=" 
195 195
                         . $activityToHandle->{"name"} . ",version=" 
196
-                        . $activityToHandle->{"version"}." doesn't exists! Check if the file is accessible and if the path is correct in your config file.");
196
+                        . $activityToHandle->{"version"} . " doesn't exists! Check if the file is accessible and if the path is correct in your config file.");
197 197
                     return false;
198 198
                 }
199 199
                 
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         $this->cpeLogger->log_out("ERROR", basename(__FILE__),
228 228
             "No Activity handler was found for: name=" 
229 229
             . $this->activityName . ",version=" 
230
-            . $this->activityVersion.". Check your config file and ensure your 'activity' name AND 'version' is there.");    
230
+            . $this->activityVersion . ". Check your config file and ensure your 'activity' name AND 'version' is there.");    
231 231
         return false;
232 232
     }
233 233
 }
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 // Usage
246 246
 function usage($defaultConfigFile)
247 247
 {
248
-    echo("Usage: php ". basename(__FILE__) . " -D <domain> -T <task_list> -A <activity_name> -V <activity_version> [-h] [-d] [-c <config_file path>] [-l <log path>]\n");
248
+    echo("Usage: php " . basename(__FILE__) . " -D <domain> -T <task_list> -A <activity_name> -V <activity_version> [-h] [-d] [-c <config_file path>] [-l <log path>]\n");
249 249
     echo("-h: Print this help\n");
250 250
     echo("-d: Debug mode\n");
251 251
     echo("-c <config_file path>: Optional parameter to override the default configuration file: '$defaultConfigFile'.\n");
Please login to merge, or discard this 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.
client_example/ClientPoller.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
     $CpeClientSdk = new SA\CpeClientSdk($key, $secret, $region, $debug);
135 135
 } catch (Exception $e) {
136 136
     exit($e->getMessage());
137
-  }
137
+    }
138 138
 
139 139
 // Commands mapping
140 140
 $commandMap = [
Please login to merge, or discard this patch.