How to use the pybit.models.CancelRequest function in pybit

To help you get started, we’ve selected a few pybit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nicholasdavidson / pybit / pybitclient / __init__.py View on Github external
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: %s" % 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):
                    #We have to sigint because it's completely unsafe to sigkill an sbuild process.
                    os.kill(self.process.pid, signal.SIGINT)
                    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)
github nicholasdavidson / pybit / pybitweb / controller.py View on Github external
def process_cancel(self, job, chan):
        job_status_history = self.db.get_job_statuses(job.id)
        last_status = job_status_history[-1].status
        build_client = job_status_history[-1].buildclient
        if (len(job_status_history) > 0) and (last_status == "Building") and (build_client != None) :
            cancel_req = jsonpickle.encode(CancelRequest(job,"%s:%s" % (self.settings['web']['hostname'], self.settings['web']['port'])))
            msg = amqp.Message(cancel_req)
            msg.properties["delivery_mode"] = 2
            self.log.debug("UNFINISHED JOB ID %i, STATUS: %s, SENDING CANCEL REQUEST TO: %s", job.id, last_status, build_client)
            chan.basic_publish(msg,exchange=pybit.exchange_name,routing_key=build_client)
        else :
            self.log.debug("UNFINISHED JOB ID %i, STATUS: %s, UPDATE STATUS TO 'Cancelled'", job.id, last_status)
            self.db.put_job_status(job.id, "Cancelled", build_client)
        return
github nicholasdavidson / pybit / pybitclient / __init__.py View on Github external
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)