diff --git a/helpers.inc.php b/helpers.inc.php index c35ad7f..12ce470 100644 --- a/helpers.inc.php +++ b/helpers.inc.php @@ -924,20 +924,23 @@ function run_background_proc($bin, array $args = array(), $redirect_out = '', $r } } -function run_background_gamectl_workers(string $task, array $worker_args) : array +function run_background_gamectl_workers(string $task, array $worker_args, ?string $tmp_dir = null) : array { global $GAME_ROOT; $results = array(); $workers = array(); + if($tmp_dir === null) + $tmp_dir = $GAME_ROOT . "/build/tmp"; + foreach($worker_args as $idx => $args) { $uid = uniqid(); - $in_file = $GAME_ROOT . "/build/tmp/in_$uid.work"; - $out_file = $GAME_ROOT . "/build/tmp/out_$uid.work"; - $log_file = $GAME_ROOT . "/build/tmp/log_$uid.work"; - $err_file = $GAME_ROOT . "/build/tmp/err_$uid.work"; + $in_file = $tmp_dir . "/in_$uid.work"; + $out_file = $tmp_dir . "/out_$uid.work"; + $log_file = $tmp_dir . "/log_$uid.work"; + $err_file = $tmp_dir . "/err_$uid.work"; $workers[] = array($in_file, $out_file, $log_file, $err_file); @@ -986,7 +989,16 @@ function run_background_gamectl_workers(string $task, array $worker_args) : arra throw new Exception("Error in worker $idx:\n" . file_get_contents($err_file)); if(is_file($out_file)) - $results[$idx] = @unserialize(ensure_read($out_file)); + { + try + { + $results[$idx] = unserialize(ensure_read($out_file)); + } + catch(Exception $e) + { + $results[$idx] = false; + } + } } } } @@ -995,10 +1007,14 @@ function run_background_gamectl_workers(string $task, array $worker_args) : arra foreach($workers as $item) { list($in_file, $out_file, $log_file, $err_file) = $item; - @ensure_rm($in_file); - @ensure_rm($out_file); - @ensure_rm($log_file); - @ensure_rm($err_file); + try + { + ensure_rm($in_file); + ensure_rm($out_file); + ensure_rm($log_file); + ensure_rm($err_file); + } + catch(Exception $e) {} } }