self.finish({
"status" : "OK",
})
-
-
-class BuildersGetNextJobHandler(BuildersBaseHandler):
- def _retry_after(self, seconds):
- # Consider the builder online until the time has passed
- self.builder.online_until = \
- datetime.datetime.utcnow() + datetime.timedelta(seconds=seconds)
-
- # Set the Retry-After header
- self.set_header("Retry-After", "%s" % seconds)
-
- # Send empty response to client
- self.finish()
-
- @tornado.web.authenticated
- def get(self):
- # If the builder is disabled, we don't need to do anything
- # but will ask it to return after 5 min
- if not self.builder.enabled:
- return self._retry_after(300)
-
- # If the builder has too many jobs running,
- # we will tell it to return after 1 min
- if self.builder.too_many_jobs:
- return self._retry_after(60)
-
- # Okay, we are ready for the next job
- job = self.builder.get_next_job()
-
- # If we got no job, we will ask the builder
- # to return after 30 seconds
- if not job:
- return self._retry_after(30)
-
- # If we got a job, we will serialise it
- # and send it to the builder
- with self.db.transaction():
- job.start(builder=self.builder)
-
- ret = {
- "id" : job.uuid,
- "arch" : job.arch,
- "source_url" : job.build.source_download,
- "source_hash_sha512" : job.build.source_hash_sha512,
- "type" : "test" if job.test else "release",
- "config" : job.get_config(),
- }
- self.finish(ret)
-
-
-class BuildersJobsQueueHandler(BuildersBaseHandler):
- @tornado.web.authenticated
- async def get(self):
- self.callback()
-
- def callback(self):
- # Break if the connection has been closed in the mean time.
- if self.connection_closed():
- logging.warning("Connection closed")
- return
-
- with self.db.transaction():
- # Check if there is a job for us.
- job = self.builder.get_next_job()
-
- # Got no job, wait and try again.
- if not job:
- return self.add_timeout(self.heartbeat, self.callback)
-
- # We got a job!
- job.start(builder=self.builder)
-
- ret = {
- "id" : job.uuid,
- "arch" : job.arch,
- "source_url" : job.build.source_download,
- "source_hash_sha512" : job.build.source_hash_sha512,
- "type" : "test" if job.test else "release",
- "config" : job.get_config(),
- }
-
- # Send build information to the builder.
- self.finish(ret)
-
- @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):
- @tornado.web.authenticated
- def post(self, job_uuid, state):
- job = self.backend.jobs.get_by_uuid(job_uuid)
- if not job:
- raise tornado.web.HTTPError(404, "Invalid job id.")
-
- if not job.builder == self.builder:
- raise tornado.web.HTTPError(403, "Altering another builder's build.")
-
- message = self.get_argument("message", None)
-
- # Save information to database.
- with self.db.transaction():
- if state == "running":
- job.running()
- elif state == "failed":
- job.failed(message)
- elif state == "finished":
- job.finished()
- else:
- job.state = state
-
- self.finish("OK")
-
-
-class BuildersJobsBuildrootHandler(BuildersBaseHandler):
- @tornado.web.authenticated
- def post(self, job_uuid):
- job = self.backend.jobs.get_by_uuid(job_uuid)
- if not job:
- raise tornado.web.HTTPError(404, "Invalid job id.")
-
- if not job.builder == self.builder:
- raise tornado.web.HTTPError(403, "Altering another builder's build.")
-
- # Get buildroot.
- buildroot = self.get_argument_json("buildroot", None)
- if buildroot:
- job.save_buildroot(buildroot)
-
- self.finish("OK")
-
-
-class BuildersJobsAddFileHandler(BuildersBaseHandler):
- @tornado.web.authenticated
- def post(self, job_uuid, upload_id):
- type = self.get_argument("type")
- assert type in ("package", "log")
-
- # Fetch job we are working on and check if it is actually ours.
- job = self.backend.jobs.get_by_uuid(job_uuid)
- if not job:
- raise tornado.web.HTTPError(404, "Invalid job id.")
-
- if not job.builder == self.builder:
- raise tornado.web.HTTPError(403, "Altering another builder's job.")
-
- # Fetch uploaded file object and check we uploaded it ourself.
- upload = self.backend.uploads.get_by_uuid(upload_id)
- if not upload:
- raise tornado.web.HTTPError(404, "Invalid upload id.")
-
- if not upload.builder == self.builder:
- raise tornado.web.HTTPError(403, "Using an other host's file.")
-
- try:
- job.add_file(upload.path)
-
- finally:
- # Finally, remove the uploaded file.
- upload.remove()
-
- self.finish("OK")