From: Michael Tremer Date: Sun, 22 Oct 2017 17:04:52 +0000 (+0100) Subject: hub: Wrap handing out jobs into a transaction X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=07374debfca31100a7b7c95681653208e1f7c712;p=people%2Fjschlag%2Fpbs.git hub: Wrap handing out jobs into a transaction Signed-off-by: Michael Tremer --- diff --git a/src/hub/handlers.py b/src/hub/handlers.py index e5eecf8..f53a364 100644 --- a/src/hub/handlers.py +++ b/src/hub/handlers.py @@ -515,22 +515,15 @@ class BuildersJobsQueueHandler(BuildersBaseHandler): logging.warning("Connection closed") return - # Check if there is a job for us. - job = self.builder.get_next_job() - - # Got no job, wait and try again. - if not job: - # Check if we have been running for too long. - if self.runtime >= self.max_runtime: - logging.debug("Exceeded max. runtime. Finishing request.") - return self.finish() + with self.db.transaction(): + # Check if there is a job for us. + job = self.builder.get_next_job() - # Try again in a jiffy. - self.add_timeout(self.heartbeat, self.callback) - return + # Got no job, wait and try again. + if not job: + return self.add_timeout(10, self.callback) - try: - # Set job to dispatching state. + # We got a job! job.state = "dispatching" # Set our build host. @@ -547,22 +540,6 @@ class BuildersJobsQueueHandler(BuildersBaseHandler): # Send build information to the builder. self.finish(ret) - except: - # If anything went wrong, we reset the state. - job.state = "pending" - raise - - @property - def heartbeat(self): - return 15 # 15 seconds - - @property - def max_runtime(self): - timeout = self.get_argument_int("timeout", None) - if timeout: - return timeout - self.heartbeat - - return 300 # 5 min class BuildersJobsStateHandler(BuildersBaseHandler):