diff options
Diffstat (limited to 'backend/backend.php')
-rwxr-xr-x | backend/backend.php | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/backend/backend.php b/backend/backend.php index cde76f0..2ee7357 100755 --- a/backend/backend.php +++ b/backend/backend.php @@ -56,7 +56,7 @@ while (true) { $build->status='build/running'; $build->write(); log_msg('Starting build id='.$build->id); - $success=null; + $file=null; try { $opts=$build->get_buildopts(); $module=$opts['backend_module']; @@ -67,7 +67,7 @@ while (true) { // TODO check that build_proc exists $workdir=WORK.'/build-'.$build->id; fatal(log_status('Creating work directory '.$workdir, mkdir($workdir, 0700))); - $success=$build_proc($build, $opts, $workdir); + $file=$build_proc($build, $opts, $workdir); if (!$conf['debug']) { execute_command('Delete work directory', 'rm -rf "'.$workdir.'"'); } @@ -79,16 +79,46 @@ while (true) { } $build->finish=time(); log_msg('Finished with build id='.$build->id); - if (isset($success)) { + if (isset($file)) { log_msg("Completed build successfully"); - $build->status='finished/success'; + if ($conf['split_setup']) { + $build->status='finished/uploading'; + $build->write(); + $key=randstring(30); + $opt=new sql_buildopt($build->id, 'uploadkey', $key); + $opt->write(); + $c=curl_init($conf['frontend_location'].'/backend/upload_image'); + curl_setopt($c, CURLOPT_POST, 1); + curl_setopt($c, CURLOPT_POSTFIELDS, array( + 'build' => $build->id, + 'key' => $key, + 'file' => "@$file" + )); + curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); + $result=curl_exec($c); + if ($conf['debug'] && is_string($result)) { + debug($result); + } + if ($result === false || strpos($result, 'Upload successful') === false) { + $build->status='finished/failed: upload failed'.($result === false?' - '.curl_error($c):''); + } else { + debug("Transferred $file... unlinking it"); + unlink($file); + $build->status='finished/success'; + } + } else { + $build->status='finished/success'; + $base=basename($file); + $ext=substr($base, substr($base, strpos($base, '.'))); + rename($file, COMPLETED.'/build-'.$build->id.$ext); + } xhtmlemail('"'.$owner->name.'" <'.$owner->email.'>', null, $conf['title'].' build finished', 'Your build has completed successfully. You can find more information and download the completed image at <a href="'.url('logs/'.$build->id).'">'.url('logs/'.$build->id).'</a>'); } $build->write(); unset($build); } -// log_msg('Sleeping...', false); + // log_msg('Sleeping...', false); sleep(5); -// log_msg("done"); + // log_msg("done"); } ?> |