@@ -181,32 +181,36 @@ private function uploadResultFiles($task, $output)
181181 self ::TMP_PATH_OPEN_FAIL );
182182 }
183183
184- // Upload all resulting files sitting in $outputFilesPath to S3
185- while ($ entry = readdir ($ handle )) {
186- if ($ entry == ". " || $ entry == ".. " ) {
187- continue ;
188- }
184+ try {
185+ // Upload all resulting files sitting in $outputFilesPath to S3
186+ while ($ entry = readdir ($ handle )) {
187+ if ($ entry == ". " || $ entry == ".. " ) {
188+ continue ;
189+ }
190+
191+ // Destination path on S3. Sanitizing
192+ $ s3Location = $ output ->{'output_file_info ' }['dirname ' ]."/ $ entry " ;
193+ $ s3Location = str_replace ("// " , "/ " , $ s3Location );
194+
195+ // Send to S3. We reference the callback s3_put_processing_callback
196+ // The callback ping back SWF so we stay alive
197+ $ s3Output = $ this ->s3Utils ->put_file_into_s3 (
198+ $ s3Bucket ,
199+ $ s3Location ,
200+ "$ this ->outputFilesPath / $ entry " ,
201+ $ options ,
202+ array ($ this , "activityHeartbeat " ),
203+ null
204+ );
205+ // We delete the TMP file once uploaded
206+ unlink ("$ this ->outputFilesPath / $ entry " );
189207
190- // Destination path on S3. Sanitizing
191- $ s3Location = $ output ->{'output_file_info ' }['dirname ' ]."/ $ entry " ;
192- $ s3Location = str_replace ("// " , "/ " , $ s3Location );
193-
194- // Send to S3. We reference the callback s3_put_processing_callback
195- // The callback ping back SWF so we stay alive
196- $ s3Output = $ this ->s3Utils ->put_file_into_s3 (
197- $ s3Bucket ,
198- $ s3Location ,
199- "$ this ->outputFilesPath / $ entry " ,
200- $ options ,
201- array ($ this , "activityHeartbeat " ),
202- null
203- );
204- // We delete the TMP file once uploaded
205- unlink ("$ this ->outputFilesPath / $ entry " );
206-
207- $ this ->cpeLogger ->logOut ("INFO " , basename (__FILE__ ),
208- $ s3Output ['msg ' ],
209- $ this ->logKey );
208+ $ this ->cpeLogger ->logOut ("INFO " , basename (__FILE__ ),
209+ $ s3Output ['msg ' ],
210+ $ this ->logKey );
211+ }
212+ } finally {
213+ closedir ($ handle );
210214 }
211215 }
212216
0 commit comments