33namespace ProcessMaker \Models ;
44
55use Log ;
6- use RuntimeException ;
6+ use ProcessMaker \ Exception \ ScriptTimeoutException ;
77
88/**
99 * Execute a docker container binding files to interchange information.
1010 *
1111 */
1212trait ScriptDockerBindingFilesTrait
1313{
14-
1514 private $ temporalFiles = [];
1615 private $ outputFiles = [];
1716
@@ -32,8 +31,13 @@ protected function executeBinding(array $options)
3231 foreach ($ options ['outputs ' ] as $ name => $ guestFile ) {
3332 $ bindings .= $ this ->bindOutput ($ guestFile , $ name );
3433 }
35- $ response = $ this ->runContainer ($ options ['image ' ], $ options ['command ' ],
36- $ options ['parameters ' ], $ bindings , $ options ['timeout ' ]);
34+ $ response = $ this ->runContainer (
35+ $ options ['image ' ],
36+ $ options ['command ' ],
37+ $ options ['parameters ' ],
38+ $ bindings ,
39+ $ options ['timeout ' ]
40+ );
3741 return $ response ;
3842 }
3943
@@ -47,18 +51,23 @@ protected function executeBinding(array $options)
4751 * @param integer $timeout
4852 *
4953 * @return array
50- * @throws RuntimeException
54+ * @throws ScriptTimeoutException
5155 */
5256 private function runContainer ($ image , $ command , $ parameters , $ bindings , $ timeout )
5357 {
5458 $ cmd = '' ;
55-
59+
5660 if ($ timeout > 0 ) {
5761 $ cmd .= "timeout -s 9 $ timeout " ;
5862 }
59-
60- $ cmd .= config ('app.bpm_scripts_docker ' ) . sprintf (' run %s %s %s %s 2>&1 ' ,
61- $ parameters , $ bindings , $ image , $ command );
63+
64+ $ cmd .= config ('app.bpm_scripts_docker ' ) . sprintf (
65+ ' run %s %s %s %s 2>&1 ' ,
66+ $ parameters ,
67+ $ bindings ,
68+ $ image ,
69+ $ command
70+ );
6271
6372 Log::debug ('Running Docker container ' , [
6473 'timeout ' => $ timeout ,
@@ -67,14 +76,13 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
6776
6877 $ line = exec ($ cmd , $ output , $ returnCode );
6978 if ($ returnCode ) {
70-
7179 if ($ returnCode == 137 ) {
7280 Log::error ('Script timed out ' );
7381 } else {
7482 Log::error ('Script threw return code ' . $ returnCode );
7583 }
76-
77- throw new RuntimeException (implode ("\n" , $ output ));
84+
85+ throw new ScriptTimeoutException (implode ("\n" , $ output ));
7886 }
7987 $ outputs = $ this ->getOutputFilesContent ();
8088 $ this ->removeTemporalFiles ();
@@ -91,7 +99,7 @@ private function runContainer($image, $command, $parameters, $bindings, $timeout
9199 */
92100 private function bindFile ($ hostFile , $ guestFile )
93101 {
94- return sprintf (" -v %s:%s " , $ hostFile , $ guestFile );
102+ return sprintf (' -v %s:%s ' , $ hostFile , $ guestFile );
95103 }
96104
97105 /**
0 commit comments