Completed
Push — master ( 72bd53...6289d3 )
by Nicolas
01:58
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.
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.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
  * Such as: Start a new workflow
12 12
  **/
13 13
 
14
-require __DIR__ . "/vendor/autoload.php";
14
+require __DIR__."/vendor/autoload.php";
15 15
 
16 16
 function start_job($args)
17 17
 {
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $CpeClientSdk->start_job($decodedClient, $content);
43 43
     }
44 44
     catch (Exception $e) {
45
-        print("[ERROR] " . $e->getMessage() . "\n");
45
+        print("[ERROR] ".$e->getMessage()."\n");
46 46
     }
47 47
 }
48 48
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
     {
112 112
         global $help;
113 113
     
114
-        echo("Usage: php ". basename(__FILE__) . " -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
114
+        echo("Usage: php ".basename(__FILE__)." -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
115 115
         echo("-h: Print this help\n");
116 116
         echo("-d: Debug mode\n");
117 117
         echo("-c: configFile\n");
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
     check_input_parameters();
128 128
 } 
129 129
 catch (Exception $e) {
130
-    print "[ERROR] " . $e->getMessage() . "\n";
130
+    print "[ERROR] ".$e->getMessage()."\n";
131 131
     exit(2);
132 132
 }
133 133
 
Please login to merge, or discard this patch.
client_example/ClientPoller.php 2 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   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * Using the CpeClientSdk you can easily listen to the SQS
10 10
  */
11 11
 
12
-require __DIR__ . "/vendor/autoload.php";
12
+require __DIR__."/vendor/autoload.php";
13 13
 
14 14
 function poll_SQS_queues($CpeClientSdk, $decodedClient)
15 15
 {
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
             }
25 25
         }
26 26
     } catch (Exception $e) {
27
-        print("[ERROR] " . $e->getMessage() . "\n");
27
+        print("[ERROR] ".$e->getMessage()."\n");
28 28
     }
29 29
                     
30 30
     // Message polled. We delete it from SQS
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 
54 54
 function usage()
55 55
 {
56
-    echo("Usage: php " . basename(__FILE__) . " -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
56
+    echo("Usage: php ".basename(__FILE__)." -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n");
57 57
     echo("-h: Print this help\n");
58 58
     echo("-d: Debug mode\n");
59 59
     echo("-c: configFile\n");
Please login to merge, or discard this patch.
pollers/src/InputPoller.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
  * It opens the JSON input and starts a execute a callback corresponding to the command
35 35
  */
36 36
 
37
-require_once __DIR__ . "/../vendor/autoload.php";
37
+require_once __DIR__."/../vendor/autoload.php";
38 38
 
39 39
 use Aws\Swf\Exception;
40 40
 use SA\CpeSdk;
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
         foreach ($this->config->{'clients'} as $client)
96 96
         {
97 97
             $msg = null;
98
-            $this->cpeLogger->log_out("DEBUG", __DIR__, "Polling from client: " . print_r($client, true));
98
+            $this->cpeLogger->log_out("DEBUG", __DIR__, "Polling from client: ".print_r($client, true));
99 99
             
100 100
             // Long Polling messages from client input queue
101 101
             $queue = $client->{'queues'}->{'input'};
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
             $this->cpeLogger->log_out(
140 140
                 "ERROR", 
141 141
                 basename(__FILE__), 
142
-                "Command '" . $message->{"type"} . "' is unknown! Ignoring ..."
142
+                "Command '".$message->{"type"}."' is unknown! Ignoring ..."
143 143
             );
144 144
             return;
145 145
         }
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
         $this->cpeLogger->log_out(
148 148
             "INFO", 
149 149
             basename(__FILE__), 
150
-            "Received message '" . $message->{"type"}  . "'"
150
+            "Received message '".$message->{"type"}."'"
151 151
         );
152 152
         if ($this->debug)
153 153
             $this->cpeLogger->log_out(
154 154
                 "DEBUG", 
155 155
                 basename(__FILE__), 
156
-                "Details:\n" . json_encode($message, JSON_PRETTY_PRINT)
156
+                "Details:\n".json_encode($message, JSON_PRETTY_PRINT)
157 157
             );
158 158
 
159 159
         // We call the callback function that handles this message  
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
     private function validate_message($message)
227 227
     {
228 228
         if (!isset($message) || 
229
-            !isset($message->{"time"})   || $message->{"time"} == "" || 
230
-            !isset($message->{"jobId"})  || $message->{"jobId"} == "" || 
231
-            !isset($message->{"type"})   || $message->{"type"} == "" || 
232
-            !isset($message->{"data"})   || $message->{"data"} == "")
229
+            !isset($message->{"time"}) || $message->{"time"} == "" || 
230
+            !isset($message->{"jobId"}) || $message->{"jobId"} == "" || 
231
+            !isset($message->{"type"}) || $message->{"type"} == "" || 
232
+            !isset($message->{"data"}) || $message->{"data"} == "")
233 233
             throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
234 234
                 self::INVALID_JSON);
235 235
         
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 function usage($defaultConfigFile)
251 251
 {
252 252
     echo("# Description\nThe InputPoller connects your client applications to your stack. It handles communication over the two SQS channels you created for your client application.\n\n");
253
-    echo("Usage: php ". basename(__FILE__) . " [-h] [-d] -n <client_name> [-l <log path>]\n");
253
+    echo("Usage: php ".basename(__FILE__)." [-h] [-d] -n <client_name> [-l <log path>]\n");
254 254
     echo("-h: Print this help\n");
255 255
     echo("-d: Debug mode\n");
256 256
     echo("-l <log_path>: Location where logs will be dumped in (folder).\n");
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
     $cpeLogger = new CpeSdk\CpeLogger($logPath, $options['n'], $debug);
288 288
         
289 289
     $config = new \stdClass;
290
-    $config->clients = [(object)[
290
+    $config->clients = [(object) [
291 291
             'name' => $options['n'],
292
-            'queues' => (object)[
292
+            'queues' => (object) [
293 293
                 'input' => getenv('INPUT_QUEUE'),
294 294
                 'output' => getenv('OUTPUT_QUEUE'),
295 295
             ],
Please login to merge, or discard this patch.
Braces   +35 added lines, -25 removed lines patch added patch discarded remove patch
@@ -86,9 +86,10 @@  discard block
 block discarded – undo
86 86
     // If a msg is received, we pass it to 'handle_input' for processing
87 87
     public function poll_SQS_queues()
88 88
     {
89
-        if (!isset($this->config->{'clients'}))
90
-            throw new CpeSdk\CpeException("Clients configuration invalid. Check the config file or your parameters.",
89
+        if (!isset($this->config->{'clients'})) {
90
+                    throw new CpeSdk\CpeException("Clients configuration invalid. Check the config file or your parameters.",
91 91
                 self::INVALID_CONFIG);
92
+        }
92 93
         
93 94
         // For all clients in config files
94 95
         // We poll from queues
@@ -102,13 +103,14 @@  discard block
 block discarded – undo
102 103
             try {
103 104
                 if ($msg = $this->cpeSqsListener->receive_message($queue, 10))
104 105
                 {
105
-                    if (!($decoded = json_decode($msg['Body'])))
106
-                        $this->cpeLogger->log_out(
106
+                    if (!($decoded = json_decode($msg['Body']))) {
107
+                                            $this->cpeLogger->log_out(
107 108
                             "ERROR", 
108 109
                             basename(__FILE__), 
109 110
                             "JSON data invalid in queue: '$queue'");
110
-                    else                    
111
-                        $this->handle_message($decoded);
111
+                    } else {
112
+                                            $this->handle_message($decoded);
113
+                    }
112 114
                 }
113 115
             } catch (CpeSdk\CpeException $e) {
114 116
                 $this->cpeLogger->log_out(
@@ -123,8 +125,9 @@  discard block
 block discarded – undo
123 125
             }
124 126
             
125 127
             // Message polled. Valid or not, we delete it from SQS
126
-            if ($msg)
127
-                $this->cpeSqsListener->delete_message($queue, $msg);
128
+            if ($msg) {
129
+                            $this->cpeSqsListener->delete_message($queue, $msg);
130
+            }
128 131
         }
129 132
     }
130 133
 
@@ -149,12 +152,13 @@  discard block
 block discarded – undo
149 152
             basename(__FILE__), 
150 153
             "Received message '" . $message->{"type"}  . "'"
151 154
         );
152
-        if ($this->debug)
153
-            $this->cpeLogger->log_out(
155
+        if ($this->debug) {
156
+                    $this->cpeLogger->log_out(
154 157
                 "DEBUG", 
155 158
                 basename(__FILE__), 
156 159
                 "Details:\n" . json_encode($message, JSON_PRETTY_PRINT)
157 160
             );
161
+        }
158 162
 
159 163
         // We call the callback function that handles this message  
160 164
         $this->{$this->typesMap[$message->{"type"}]}($message);
@@ -168,12 +172,13 @@  discard block
 block discarded – undo
168 172
     // Start a new workflow in SWF to initiate new transcoding job
169 173
     private function start_job($message)
170 174
     {
171
-        if ($this->debug)
172
-            $this->cpeLogger->log_out(
175
+        if ($this->debug) {
176
+                    $this->cpeLogger->log_out(
173 177
                 "DEBUG",
174 178
                 basename(__FILE__),
175 179
                 "Starting new workflow!"
176 180
             );
181
+        }
177 182
         
178 183
         // Workflow info
179 184
         $workflowType = array(
@@ -192,9 +197,10 @@  discard block
 block discarded – undo
192 197
                 "taskList"     => array("name" => $message->{'data'}->{'workflow'}->{'taskList'}),
193 198
                 "input"        => json_encode($message->{'data'})
194 199
             );
195
-            if (isset($message->{'data'}->{'workflow'}->{'executionStartToCloseTimeout'})) 
196
-                $payload["executionStartToCloseTimeout"] =
200
+            if (isset($message->{'data'}->{'workflow'}->{'executionStartToCloseTimeout'})) {
201
+                            $payload["executionStartToCloseTimeout"] =
197 202
                     $message->{'data'}->{'workflow'}->{'executionStartToCloseTimeout'};
203
+            }
198 204
             $workflowRunId = $this->cpeSwfHandler->swf->startWorkflowExecution($payload);
199 205
 
200 206
             $this->cpeLogger->log_out(
@@ -229,13 +235,15 @@  discard block
 block discarded – undo
229 235
             !isset($message->{"time"})   || $message->{"time"} == "" || 
230 236
             !isset($message->{"jobId"})  || $message->{"jobId"} == "" || 
231 237
             !isset($message->{"type"})   || $message->{"type"} == "" || 
232
-            !isset($message->{"data"})   || $message->{"data"} == "")
233
-            throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
238
+            !isset($message->{"data"})   || $message->{"data"} == "") {
239
+                    throw new CpeSdk\CpeException("'time', 'type', 'jobId' or 'data' fields missing in JSON message file!",
234 240
                 self::INVALID_JSON);
241
+        }
235 242
         
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!",
243
+        if (!isset($message->{'data'}->{'workflow'})) {
244
+                    throw new CpeSdk\CpeException("Input doesn't contain any workflow information. You must provide the workflow you want to send this job to!",
238 245
                 self::INVALID_JSON);
246
+        }
239 247
     }
240 248
 }
241 249
 
@@ -266,11 +274,13 @@  discard block
 block discarded – undo
266 274
     // Handle input parameters
267 275
     $options = getopt("l:hdn:");
268 276
 
269
-    if (isset($options['h']))
270
-        usage();
277
+    if (isset($options['h'])) {
278
+            usage();
279
+    }
271 280
     
272
-    if (isset($options['d'])) 
273
-        $debug = true;
281
+    if (isset($options['d'])) {
282
+            $debug = true;
283
+    }
274 284
         
275 285
     $logPath = null;
276 286
     if (isset($options['l']))
@@ -308,8 +318,7 @@  discard block
 block discarded – undo
308 318
 // Create InputPoller object
309 319
 try {
310 320
     $inputPoller = new InputPoller($config);
311
-}
312
-catch (CpeSdk\CpeException $e) {
321
+} catch (CpeSdk\CpeException $e) {
313 322
     echo $e->getMessage();
314 323
     $cpeLogger->log_out(
315 324
         "FATAL", 
@@ -323,5 +332,6 @@  discard block
 block discarded – undo
323 332
 print "Start polling ...\n";
324 333
 
325 334
 // Start polling loop to get incoming commands from SQS input queues
326
-while (42)
335
+while (42) {
327 336
     $inputPoller->poll_SQS_queues();
337
+}
Please login to merge, or discard this patch.
pollers/src/ActivityPoller.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
  * It will process tasks only coming in the TaskList
37 37
  */
38 38
 
39
-require_once __DIR__ . "/../vendor/autoload.php";
39
+require_once __DIR__."/../vendor/autoload.php";
40 40
 
41 41
 use Aws\Swf\Exception;
42 42
 use SA\CpeSdk;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         // Poll from all the taskList registered for each activities 
101 101
         if ($this->debug)
102 102
             $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
103
-                "Polling activity taskList '" . $this->taskList  . "' ... ");
103
+                "Polling activity taskList '".$this->taskList."' ... ");
104 104
             
105 105
         try {
106 106
             // Call SWF and poll for incoming tasks
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
             $this->process_activity_task($activityTask);
114 114
         } catch (CpeSdk\CpeException $e) {
115 115
             $this->cpeLogger->log_out("ERROR", basename(__FILE__),
116
-                "Unable to poll activity tasks! " . $e->getMessage());
116
+                "Unable to poll activity tasks! ".$e->getMessage());
117 117
         }
118 118
         
119 119
         return true;
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
         $this->cpeLogger->log_out("INFO",
131 131
             basename(__FILE__),
132 132
             "Starting activity: name=" 
133
-            . $activityType['name'] . ",version=" . $activityType['version'],
133
+            . $activityType['name'].",version=".$activityType['version'],
134 134
             $workflowExecution['workflowId']);
135 135
 
136 136
         // Has activity handler object been instantiated ?
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
 
155 155
             if ($this->debug)
156 156
                 $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
157
-                    "Activity input:\n" . print_r($this->activityHandler->input, true));
157
+                    "Activity input:\n".print_r($this->activityHandler->input, true));
158 158
         
159 159
             // Run activity task
160 160
             $result = $this->activityHandler->do_activity($activityTask);
161 161
 
162 162
             if ($this->debug && $result)
163 163
                 $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
164
-                    "Activity output:\n" . print_r($result, true));
164
+                    "Activity output:\n".print_r($result, true));
165 165
         
166 166
         } catch (CpeSdk\CpeException $e) {
167 167
             $reason  = $e->ref;
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
                 {
203 203
                     $this->cpeLogger->log_out("ERROR", basename(__FILE__),
204 204
                         "The code file '".$activityToHandle->{"file"}."' for activity: name=" 
205
-                        . $activityToHandle->{"name"} . ",version=" 
205
+                        . $activityToHandle->{"name"}.",version=" 
206 206
                         . $activityToHandle->{"version"}." doesn't exists! Check if the file is accessible and if the path is correct in your config file.");
207 207
                     return false;
208 208
                 }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
                 
233 233
                 $this->cpeLogger->log_out("INFO", basename(__FILE__),
234 234
                     "Activity handler registered: name=" 
235
-                    . $activityToHandle->{"name"} . ",version=" 
235
+                    . $activityToHandle->{"name"}.",version=" 
236 236
                     . $activityToHandle->{"version"});
237 237
 
238 238
                 return true;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         
242 242
         $this->cpeLogger->log_out("ERROR", basename(__FILE__),
243 243
             "No Activity handler was found for: name=" 
244
-            . $this->activityName . ",version=" 
244
+            . $this->activityName.",version=" 
245 245
             . $this->activityVersion.". Check your config file and ensure your 'activity' name AND 'version' is there.");    
246 246
         return false;
247 247
     }
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 // Usage
263 263
 function usage($defaultConfigFile)
264 264
 {
265
-    echo("Usage: php ". basename(__FILE__) . " -D <domain> -A <activity_name> -V <activity_version> [-T <task_list>] [-h] [-d] [-c <config_file path>] [-l <log path>]\n");
265
+    echo("Usage: php ".basename(__FILE__)." -D <domain> -A <activity_name> -V <activity_version> [-T <task_list>] [-h] [-d] [-c <config_file path>] [-l <log path>]\n");
266 266
     echo("-h: Print this help\n");
267 267
     echo("-d: Debug mode\n");
268 268
     echo("-c <config_file path>: Optional parameter to override the default configuration file: '$defaultConfigFile'.\n");
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
         $cpeLogger->log_out(
343 343
             "INFO",
344 344
             basename(__FILE__),
345
-            "Config file: '" . $options['c'] . "'");
345
+            "Config file: '".$options['c']."'");
346 346
         $defaultConfigFile = $options['c'];
347 347
     }
348 348
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 
369 369
 // Get config file
370 370
 $defaultConfigFile =
371
-    realpath(dirname(__FILE__)) . "/../config/cpeConfig.json";
371
+    realpath(dirname(__FILE__))."/../config/cpeConfig.json";
372 372
 $config = check_input_parameters($defaultConfigFile);
373 373
 
374 374
 // Instantiate ActivityPoller
Please login to merge, or discard this patch.
Braces   +40 added lines, -29 removed lines patch added patch discarded remove patch
@@ -98,9 +98,10 @@  discard block
 block discarded – undo
98 98
     public function poll_for_activities()
99 99
     {
100 100
         // Poll from all the taskList registered for each activities 
101
-        if ($this->debug)
102
-            $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
101
+        if ($this->debug) {
102
+                    $this->cpeLogger->log_out("DEBUG", basename(__FILE__),
103 103
                 "Polling activity taskList '" . $this->taskList  . "' ... ");
104
+        }
104 105
             
105 106
         try {
106 107
             // Call SWF and poll for incoming tasks
@@ -124,8 +125,9 @@  discard block
 block discarded – undo
124 125
     {
125 126
         // Get activityType and WorkflowExecution info
126 127
         if (!($activityType      = $activityTask->get("activityType")) ||
127
-            !($workflowExecution = $activityTask->get("workflowExecution")))
128
-            return false;
128
+            !($workflowExecution = $activityTask->get("workflowExecution"))) {
129
+                    return false;
130
+        }
129 131
         
130 132
         $this->cpeLogger->log_out("INFO",
131 133
             basename(__FILE__),
@@ -152,16 +154,18 @@  discard block
 block discarded – undo
152 154
             // Perform input validation
153 155
             $this->activityHandler->do_input_validation();
154 156
 
155
-            if ($this->debug)
156
-                $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
157
+            if ($this->debug) {
158
+                            $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
157 159
                     "Activity input:\n" . print_r($this->activityHandler->input, true));
160
+            }
158 161
         
159 162
             // Run activity task
160 163
             $result = $this->activityHandler->do_activity($activityTask);
161 164
 
162
-            if ($this->debug && $result)
163
-                $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
165
+            if ($this->debug && $result) {
166
+                            $this->cpeLogger->log_out("DEBUG", basename(__FILE__), 
164 167
                     "Activity output:\n" . print_r($result, true));
168
+            }
165 169
         
166 170
         } catch (CpeSdk\CpeException $e) {
167 171
             $reason  = $e->ref;
@@ -216,26 +220,31 @@  discard block
 block discarded – undo
216 220
                 // Instantiate the Activity class that will process Tasks
217 221
 
218 222
                 if (!isset($this->cpeLogger) ||
219
-                    !$this->cpeLogger)
220
-                    print "EMPTY !!!\n";
223
+                    !$this->cpeLogger) {
224
+                                    print "EMPTY !!!\n";
225
+                }
221 226
 
222 227
                 $params = [
223 228
                     "domain"  => $this->domain,
224 229
                     "name"    => $activityToHandle->{"name"},
225 230
                     "version" => $activityToHandle->{"version"}
226 231
                 ];
227
-                if (isset($activityToHandle->{"defaultTaskStartToCloseTimeout"}))
228
-                    $params["defaultTaskStartToCloseTimeout"] =
232
+                if (isset($activityToHandle->{"defaultTaskStartToCloseTimeout"})) {
233
+                                    $params["defaultTaskStartToCloseTimeout"] =
229 234
                         $activityToHandle->{"defaultTaskStartToCloseTimeout"};
230
-                if (isset($activityToHandle->{"defaultTaskHeartbeatTimeout"}))
231
-                    $params["defaultTaskHeartbeatTimeout"] =
235
+                }
236
+                if (isset($activityToHandle->{"defaultTaskHeartbeatTimeout"})) {
237
+                                    $params["defaultTaskHeartbeatTimeout"] =
232 238
                         $activityToHandle->{"defaultTaskHeartbeatTimeout"};
233
-                if (isset($activityToHandle->{"defaultTaskScheduleToStartTimeout"}))
234
-                    $params["defaultTaskScheduleToStartTimeout"] =
239
+                }
240
+                if (isset($activityToHandle->{"defaultTaskScheduleToStartTimeout"})) {
241
+                                    $params["defaultTaskScheduleToStartTimeout"] =
235 242
                         $activityToHandle->{"defaultTaskScheduleToStartTimeout"};
236
-                if (isset($activityToHandle->{"defaultTaskScheduleToCloseTimeout"}))
237
-                    $params["defaultTaskScheduleToCloseTimeout"] =
243
+                }
244
+                if (isset($activityToHandle->{"defaultTaskScheduleToCloseTimeout"})) {
245
+                                    $params["defaultTaskScheduleToCloseTimeout"] =
238 246
                         $activityToHandle->{"defaultTaskScheduleToCloseTimeout"};
247
+                }
239 248
                 
240 249
                 $this->activityHandler = 
241 250
                     new $activityToHandle->{"class"}(
@@ -301,15 +310,18 @@  discard block
 block discarded – undo
301 310
     global $activityVersion;
302 311
     
303 312
     // Handle input parameters
304
-    if (!($options = getopt("D:T:A:V:c:l:hd")))
305
-        usage($defaultConfigFile);
313
+    if (!($options = getopt("D:T:A:V:c:l:hd"))) {
314
+            usage($defaultConfigFile);
315
+    }
306 316
     
307
-    if (!count($options) || isset($options['h']))
308
-        usage($defaultConfigFile);
317
+    if (!count($options) || isset($options['h'])) {
318
+            usage($defaultConfigFile);
319
+    }
309 320
 
310 321
     // Debug
311
-    if (isset($options['d']))
312
-        $debug = true;
322
+    if (isset($options['d'])) {
323
+            $debug = true;
324
+    }
313 325
 
314 326
     // Domain
315 327
     if (!isset($options['D']))
@@ -367,8 +379,7 @@  discard block
 block discarded – undo
367 379
             print "\n[CONFIG ISSUE]\nConfiguration file '$defaultConfigFile' invalid or non-existant.\n\n[EASY FIX]\nGo to the directory mentioned in the error above and rename the template file 'cpeConfigTemplate.json' to 'cpeConfig.json'. Configure your Activities. As example you have Activities for CloudTranscode already setup in the template. You can declare your Activities and start executing tasks in an SWF workflow.\n";
368 380
             exit(1);
369 381
         }
370
-    }
371
-    catch (Exception $e) {
382
+    } catch (Exception $e) {
372 383
         print $e;
373 384
     }
374 385
             
@@ -388,8 +399,7 @@  discard block
 block discarded – undo
388 399
 // Instantiate ActivityPoller
389 400
 try {
390 401
     $activityPoller = new ActivityPoller($config);
391
-} 
392
-catch (CpeSdk\CpeException $e) {
402
+} catch (CpeSdk\CpeException $e) {
393 403
     $cpeLogger->log_out("FATAL",
394 404
         basename(__FILE__), $e->getMessage());
395 405
     exit(1);
@@ -398,6 +408,7 @@  discard block
 block discarded – undo
398 408
 $cpeLogger->log_out("INFO", basename(__FILE__), "Starting activity tasks polling");
399 409
 
400 410
 // Start polling loop
401
-while (42)
411
+while (42) {
402 412
     $activityPoller->poll_for_activities();
413
+}
403 414
 
Please login to merge, or discard this patch.