示例#1
0
  def handle_delivery(self, channel, method, header, body):
    """Message received callback."""
    global producer

    message = pickle.loads(body)
    p = message["package"]
    arch = message["arch"]
    branch = message["branch"]
    buildid = message["buildid"]
    torrents = message["torrents"]
    reply_to = message["reply_to"]
    self.buildname = "{0}/{1}/{2}".format(arch, branch, buildid)

    if buildid in ready:
      util.log("Building {0} for build {1}".format(p.name, self.buildname))
      channel.basic_ack(delivery_tag=method.delivery_tag)
    else:
      time.sleep(5)
      channel.basic_reject(delivery_tag=method.delivery_tag)
      util.log("Setting up build {0}".format(self.buildname))
      ts = torrent.TorrentSession()
      for t in torrents:
        t.dest="." # XXX - Temporary while I'm testing locally.
        ts.add(t)
        while not ts.all_seeding():
          ts.status()
          time.sleep(1)
      util.debug("Finished downloading components.")
      ts.terminate()
      producer.notify(reply_to)
      ready.append(buildid)
示例#2
0
 def start(self):
   self.consumer.start()
   util.debug("Waiting for DispatcherConsumer to be ready...")
   while not self.consumer.queue:
     time.sleep(1)
   self.producer.reply_to = self.consumer.queue
   self.producer.start()
   util.debug("Waiting for DispatcherProducer to be ready...")
   while not self.producer.channel:
     time.sleep(1)
示例#3
0
  def setup(self):
    """Set up AgentConsumer."""
    self.arch = platform.machine()
    self.hostname = socket.gethostname()

    self.channel = self.connection.channel()
    self.channel.queue_declare(queue=self.arch, durable=True, exclusive=False, auto_delete=False)
    self.channel.basic_qos(prefetch_count=1)
    self.channel.basic_consume(self.handle_delivery, queue=self.arch)
    util.debug("AgentConsumer is all set!")
    util.debug("AgentConsumer listening on queue {0}...".format(self.arch))
示例#4
0
 def stop(self):
   util.debug("Stopping Dispatcher...")
   self.consumer.stop()
   self.producer.stop()
示例#5
0
 def setup(self):
   # Declare channel and queue.
   self.channel = self.connection.channel()
   self.channel.queue_declare(queue=self.arch, durable=True, exclusive=False, auto_delete=False)
   util.debug("DispatcherProducer is all set!")
示例#6
0
 def setup(self):
   self.channel = self.connection.channel()
   result = self.channel.queue_declare(durable=True, exclusive=True, auto_delete=True)
   self.queue = result.method.queue
   self.channel.basic_consume(self.handle_delivery, queue=self.queue)
   util.debug("DispatcherConsumer is all set!")
示例#7
0
 def setup(self):
   """Set up AgentProducer."""
   self.channel = self.connection.channel()
   self.channel.add_on_return_callback(self.notify_return)
   util.debug("AgentProducer is all set!")