Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def put_job(self,packageinstance,buildclient):
try:
if buildclient:
buildclient_id = remove_nasties(buildclient.id)
else:
buildclient_id = None
cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("INSERT INTO job (packageinstance_id,buildclient_id) VALUES (%s, %s) RETURNING id",(remove_nasties(packageinstance.id),(buildclient_id)))
res = cur.fetchall()
job_id = res[0]['id']
if job_id is not None:
cur.execute("INSERT INTO jobstatus (job_id, status_id) VALUES (%s, (SELECT id FROM status WHERE status.name=%s))",
(remove_nasties(job_id), remove_nasties(ClientMessage.waiting)))
self.conn.commit()
else:
self.conn.rollback()
job = Job(job_id,packageinstance,buildclient)
cur.close()
return job
except psycopg2.Error as e:
self.conn.rollback()
raise Exception("Error adding job. Database error code: " + str(e.pgcode) + " - Details: " + str(e.pgerror))
return None
contacted or None if the job doesn't exist
"""
if request is None:
request = self.current_request
if request is not None:
job_status_get_url = "http://%s/job/%s/status" % (request.web_host, request.get_job_id())
r = requests.get(job_status_get_url)
if r.status_code == 200 and r.headers['content-type'] == 'application/json':
status_list = jsonpickle.decode(r.content)
if (len(status_list) > 0):
return status_list[-1].status
elif r.status_code == 404:
return None
else:
return ClientMessage.waiting
contacted or None if the job doesn't exist
"""
if request is None:
request = self.current_request
if request is not None:
job_status_get_url = "http://%s/job/%s/status" % (request.web_host, request.get_job_id())
r = requests.get(job_status_get_url)
if r.status_code == 200 and r.headers['content-type'] == 'application/json':
status_list = jsonpickle.decode(r.content)
if len(status_list) > 0:
return status_list[-1].status
elif r.status_code == 404:
return None
else:
return ClientMessage.waiting
def idle_handler(self, msg, decoded):
if isinstance(decoded, BuildRequest):
self.current_msg = msg
self.current_request = decoded
try:
status = self.get_status()
if (status == ClientMessage.waiting or
status == ClientMessage.blocked):
self.vcs_handler = self.handlers[self.current_request.transport.method]
if (self.vcs_handler is None):
self.overall_success = False
self.move_state("IDLE")
return
self.move_state("CHECKOUT")
elif status == None:
self.move_state("IDLE")
elif status == ClientMessage.cancelled:
logging.debug ("jobid: %s has been cancelled. Acking." % self.current_request.get_job_id())
self.move_state("IDLE")
except Exception as requests.exceptions.ConnectionError:
self.overall_success = False
self.move_state("IDLE")
def idle_handler(self, msg, decoded):
if isinstance(decoded, BuildRequest):
self.current_msg = msg
self.current_request = decoded
try:
status = self.get_status()
if (status == ClientMessage.waiting or
status == ClientMessage.blocked):
self.vcs_handler = self.handlers[self.current_request.transport.method]
if self.vcs_handler is None:
self.overall_success = False
self.move_state("IDLE")
return
self.move_state("CHECKOUT")
elif status is None:
self.move_state("IDLE")
elif status == ClientMessage.cancelled:
logging.debug("jobid: %s has been cancelled. Acking." % self.current_request.get_job_id())
self.move_state("IDLE")
except Exception as requests.exceptions.ConnectionError:
self.overall_success = False
self.move_state("IDLE")