Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
args = (self.current_request, self.conn_info)
self.process = multiprocessing.Process(target=self.format_handler.upload, args=args)
self.process.start()
elif self.state == "IDLE":
overall_success = self.overall_success
current_msg = self.current_msg
current_req = self.current_request
subprocess_message = self.subprocess_message
self._clean_current()
if current_msg is not None:
self.message_chan.basic_ack(current_msg.delivery_tag)
if overall_success is True:
self.set_status(ClientMessage.done, current_req)
elif overall_success is False:
if subprocess_message == 'build-dep-wait':
self.set_status(ClientMessage.blocked, current_req)
self.republish_job(current_req)
else:
self.set_status(ClientMessage.failed, current_req)
elif self.state == "FATAL_ERROR":
current_req = self.current_request
current_msg = self.current_msg
self._clean_current()
self.message_chan.basic_ack(current_msg.delivery_tag)
self.set_status(ClientMessage.failed, current_req)
self.republish_job(current_req)
logging.debug("Moved from %s to %s" % (self.old_state, self.state))
else:
logging.debug("Unhandled state: %s" % new_state)
def move_state(self, new_state):
if (new_state in self.state_table):
#FIXME: we can stack state handling in here.
self.old_state = self.state
self.state = new_state
if self.state == "CHECKOUT":
args = (self.current_request,self.conn_info)
self.process = multiprocessing.Process(target=self.vcs_handler.fetch_source,args=args)
self.process.start()
self.set_status(ClientMessage.building,None,self.conn_info.client_name)
elif self.state == "BUILD":
# mark this as the moment that the build starts
self.current_request.stamp_request()
args = (self.current_request,self.conn_info)
if self.current_request.job.packageinstance.master == True:
self.process = multiprocessing.Process(target=self.format_handler.build_master, args=args)
else:
self.process = multiprocessing.Process(target=self.format_handler.build_slave, args=args)
self.process.start()
elif self.state == "CLEAN":
args = (self.current_request,self.conn_info)
self.process = multiprocessing.Process(target=self.vcs_handler.clean_source, args=args)
self.process.start()
elif self.state == "UPLOAD":
args = (self.current_request,self.conn_info)
self.process = multiprocessing.Process(target=self.format_handler.upload, args=args)
args = (self.current_request,self.conn_info)
self.process = multiprocessing.Process(target=self.format_handler.upload, args=args)
self.process.start()
elif self.state == "IDLE":
overall_success = self.overall_success
current_msg = self.current_msg
current_req = self.current_request
subprocess_message = self.subprocess_message
self._clean_current()
if current_msg is not None :
self.message_chan.basic_ack(current_msg.delivery_tag)
if overall_success == True:
self.set_status(ClientMessage.done, current_req)
elif overall_success == False:
if subprocess_message == 'build-dep-wait':
self.set_status(ClientMessage.blocked, current_req)
self.republish_job(current_req)
else:
self.set_status(ClientMessage.failed, current_req)
elif self.state == "FATAL_ERROR":
current_req = self.current_request
current_msg = self.current_msg
self._clean_current()
self.message_chan.basic_ack(current_msg.delivery_tag)
self.set_status(ClientMessage.failed, current_req)
self.republish_job(current_req)
logging.debug ("Moved from %s to %s" % (self.old_state, self.state))
else:
logging.debug ("Unhandled state: %s" % (new_state))
if current_msg is not None:
self.message_chan.basic_ack(current_msg.delivery_tag)
if overall_success is True:
self.set_status(ClientMessage.done, current_req)
elif overall_success is False:
if subprocess_message == 'build-dep-wait':
self.set_status(ClientMessage.blocked, current_req)
self.republish_job(current_req)
else:
self.set_status(ClientMessage.failed, current_req)
elif self.state == "FATAL_ERROR":
current_req = self.current_request
current_msg = self.current_msg
self._clean_current()
self.message_chan.basic_ack(current_msg.delivery_tag)
self.set_status(ClientMessage.failed, current_req)
self.republish_job(current_req)
logging.debug("Moved from %s to %s" % (self.old_state, self.state))
else:
logging.debug("Unhandled state: %s" % new_state)
def command_handler(self, msg):
cmd_req = jsonpickle.decode(msg.body)
if (not isinstance(cmd_req, TaskComplete) and
not isinstance(cmd_req, CommandRequest)):
logging.debug ("Can't handle message type.")
self.command_chan.basic_ack(msg.delivery_tag)
elif isinstance(cmd_req, CommandRequest) :
if isinstance(cmd_req, CancelRequest) :
logging.debug ("Received CANCEL request for jobid:", cmd_req.get_job_id())
self.set_status(ClientMessage.cancelled, cmd_req)
if (self.current_request and
self.current_request.get_job_id() == cmd_req.get_job_id() and
self.process is not None) :
self.process.terminate()
self.process.join()
self.process = None
self.move_state("IDLE")
else:
logging.debug("Ignoring cancel request as no current request or id doesn't match.")
else :
logging.debug ("Received COMMAND request for jobid:", cmd_req.get_job_id())
else:
self.state_table[self.state](msg, cmd_req)
def move_state(self, new_state):
if new_state in self.state_table:
#FIXME: we can stack state handling in here.
self.old_state = self.state
self.state = new_state
if self.state == "CHECKOUT":
args = (self.current_request, self.conn_info)
self.process = multiprocessing.Process(target=self.vcs_handler.fetch_source, args=args)
self.process.start()
self.set_status(ClientMessage.building, None, self.conn_info.client_name)
elif self.state == "BUILD":
# mark this as the moment that the build starts
self.current_request.stamp_request()
args = (self.current_request, self.conn_info)
if self.current_request.job.packageinstance.master is True:
self.process = multiprocessing.Process(target=self.format_handler.build_master, args=args)
else:
self.process = multiprocessing.Process(target=self.format_handler.build_slave, args=args)
self.process.start()
elif self.state == "CLEAN":
args = (self.current_request, self.conn_info)
self.process = multiprocessing.Process(target=self.vcs_handler.clean_source, args=args)
self.process.start()
elif self.state == "UPLOAD":
args = (self.current_request, self.conn_info)
self.process = multiprocessing.Process(target=self.format_handler.upload, args=args)
self.process = multiprocessing.Process(target=self.vcs_handler.clean_source, args=args)
self.process.start()
elif self.state == "UPLOAD":
args = (self.current_request, self.conn_info)
self.process = multiprocessing.Process(target=self.format_handler.upload, args=args)
self.process.start()
elif self.state == "IDLE":
overall_success = self.overall_success
current_msg = self.current_msg
current_req = self.current_request
subprocess_message = self.subprocess_message
self._clean_current()
if current_msg is not None:
self.message_chan.basic_ack(current_msg.delivery_tag)
if overall_success is True:
self.set_status(ClientMessage.done, current_req)
elif overall_success is False:
if subprocess_message == 'build-dep-wait':
self.set_status(ClientMessage.blocked, current_req)
self.republish_job(current_req)
else:
self.set_status(ClientMessage.failed, current_req)
elif self.state == "FATAL_ERROR":
current_req = self.current_request
current_msg = self.current_msg
self._clean_current()
self.message_chan.basic_ack(current_msg.delivery_tag)
self.set_status(ClientMessage.failed, current_req)
self.republish_job(current_req)
logging.debug("Moved from %s to %s" % (self.old_state, self.state))
else: