Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def republish_job(self, buildreq):
if (isinstance(buildreq, BuildRequest)) :
routing_key = pybit.get_build_route_name(buildreq.get_dist(),
buildreq.get_arch(),
buildreq.get_suite(),
buildreq.get_format())
try:
msg = jsonpickle.encode(buildreq)
self.message_chan.basic_publish(amqp.Message(msg),
exchange=pybit.exchange_name,
routing_key=routing_key,
mandatory=True)
except amqp.AMQPConnectionException as e:
logging.debug("Couldn't connect to channel. traceback: %s" % e)
def wait(self):
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
build_req = jsonpickle.encode(build_request_obj)
self.db.log_buildRequest(build_request_obj)
#print "SENDING REQUEST WITH DATA", str(build_req)
msg = amqp.Message(build_req)
msg.properties["delivery_mode"] = 2
routing_key = pybit.get_build_route_name(new_job.packageinstance.get_distribution_name(),
new_job.packageinstance.get_arch_name(),
new_job.packageinstance.get_suite_name(),
new_job.packageinstance.get_format_name())
build_queue = pybit.get_build_queue_name(new_job.packageinstance.get_distribution_name(),
new_job.packageinstance.get_arch_name(),
new_job.packageinstance.get_suite_name(),
new_job.packageinstance.get_format_name())
self.add_message_queue(build_queue, routing_key, chan)
chan.basic_publish(msg,exchange=pybit.exchange_name,routing_key=routing_key,mandatory=True)
#self.log.debug("\n____________SENDING %s ____________TO____________ %s", build_req, routing_key)
self.log.debug("SENDING BUILD REQUEST FOR JOB ID %i %s %s %s %s %s %s",
new_job.id,
new_job.packageinstance.get_distribution_name(),
new_job.packageinstance.get_package_version(),
new_job.packageinstance.get_distribution_name(),
new_job.packageinstance.get_arch_name(),
new_job.packageinstance.get_suite_name(),
new_job.packageinstance.get_format_name())
else :
self.log.warn("FAILED TO ADD JOB")
response.status = "404 - failed to add job."
return False
master_flag = False
else :
self.log.warn("PACKAGE INSTANCE ERROR")
def connect(self):
try:
self.conn = amqp.Connection(host=self.conn_info.host,
userid=self.conn_info.userid, password=self.conn_info.password,
virtual_host=self.conn_info.vhost, insist=False)
self.command_chan = self.conn.channel()
self.message_chan = self.conn.channel()
self.message_chan.basic_qos(0,1,False)
self.command_chan.exchange_declare(exchange=pybit.exchange_name, type="direct", durable=True, auto_delete=False)
except socket.error as e:
logging.debug ("Couldn't connect rabbitmq server with: %s" % repr(self.conn_info))
return False
for suite, info in self.listen_list.items():
logging.debug("Creating queue with name:" + info['queue'])
try:
self.message_chan.queue_declare(queue=info['queue'], durable=True,
exclusive=False, auto_delete=False)
self.message_chan.queue_bind(queue=info['queue'],
exchange=pybit.exchange_name, routing_key=info['route'])
except amqp.exceptions.AMQPChannelException :
logging.debug ("Unable to declare or bind to message channel.")
return False
def republish_job(self, buildreq):
if isinstance(buildreq, BuildRequest):
routing_key = pybit.get_build_route_name(buildreq.get_dist(), buildreq.get_arch(),
buildreq.get_suite(), buildreq.get_format())
try:
msg = jsonpickle.encode(buildreq)
self.message_chan.basic_publish(amqp.Message(msg), exchange=pybit.exchange_name,
routing_key=routing_key, mandatory=True)
except amqp.AMQPConnectionException as e:
logging.debug("Couldn't connect to channel. traceback: %s" % e)
logging.debug("Creating queue with name:" + info['queue'])
try:
self.message_chan.queue_declare(queue=info['queue'], durable=True,
exclusive=False, auto_delete=False)
self.message_chan.queue_bind(queue=info['queue'],
exchange=pybit.exchange_name, routing_key=info['route'])
except amqp.exceptions.AMQPChannelException:
logging.debug("Unable to declare or bind to message channel.")
return False
logging.debug("Creating private command queue with name:" + self.conn_info.client_name)
try:
self.command_chan.queue_declare(queue=self.conn_info.client_name,
durable=False, exclusive=True, auto_delete=True)
self.command_chan.queue_bind(queue=self.conn_info.client_name,
exchange=pybit.exchange_name, routing_key=self.conn_info.client_name)
except amqp.exceptions.AMQPChannelException:
logging.debug("Unable to declare or bind to command channel %s. Does this client already exist?"
% (self.conn_info.client_name, ))
return False
return True