diff options
author | 2011-07-08 18:26:05 +0100 | |
---|---|---|
committer | 2011-07-08 18:26:05 +0100 | |
commit | 240a321b053dfd244b696ab2b456e1c264c9456a (patch) | |
tree | c89bcae15c0c265573df89813143d47c59b81b30 /daemon.php | |
parent | Added basic Gearman worker/client (diff) | |
download | gentoaster-240a321b053dfd244b696ab2b456e1c264c9456a.tar.gz gentoaster-240a321b053dfd244b696ab2b456e1c264c9456a.tar.bz2 gentoaster-240a321b053dfd244b696ab2b456e1c264c9456a.zip |
Added more robust error handling (we're not going to zombie onwards now when things fail)
Return codes and messages are now making it into a database, and job handles are mapped to handle hashes to prevent job hijacking
Diffstat (limited to 'daemon.php')
-rw-r--r-- | daemon.php | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -16,24 +16,37 @@ $worker->addFunction("invoke_image_build", "image_build"); while ($worker->work()); + function update_result($handle, $returncode, $result) { + $result = trim($result); + echo "A job finished with return code ".$returncode.": ".$result."\n"; + $db = mysql_connect("localhost","gentoaster",""); + if(!$db) die("Could not connect to database ".mysql_error()); + mysql_select_db("gentoaster"); + mysql_query("UPDATE builds SET result = '".mysql_real_escape_string($result)."', returncode = '".$returncode."' WHERE handle = '".mysql_real_escape_string($handle)."'"); + return serialize(array($returncode, $result)); + } + function image_build($job) { global $configurations_path, $gentoaster_path, $tool_name, $progress_magic; - echo "Got job ID ".$job->handle(). "(".md5($job->handle()).")\n"; + $handle = $job->handle(); + $handlehash = md5($handle); + + echo "Processing job handle hash ".$handlehash."\n"; $configuration_string = $job->workload(); $configuration_array = parse_ini_string($configuration_string); - if($configuration_array !== FALSE) { + if($configuration_array !== FALSE && isset($configuration_array["BUILD_ID"])) { $build_id = $configuration_array["BUILD_ID"]; $build_path = $configurations_path."/".$build_id; - mkdir($build_path); + @mkdir($build_path, 0777, true); if(is_writable($build_path)) { chdir($build_path); file_put_contents("config.ini", $configuration_string); $tool_args = "--config config.ini --cachedkernel"; - $process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args, "r"); + $process_handle = popen($gentoaster_path."/".$tool_name." ".$tool_args." 2>&1", "r"); $nonstatus_output = ""; @@ -47,14 +60,14 @@ } } - pclose($process_handle); + $returncode = pclose($process_handle); - return $nonstatus_output; + return update_result($handle, $returncode, $nonstatus_output); } else { - echo "Configured build path is not writable"; + return update_result($handle, -2, "Configured build path is not writable"); } } else { - echo "Configuration string is not valid"; + return update_result($handle, -3, "Configuration string is not valid"); } } |