except ValueError as e: logging.error("Received invalid JSON: %s." % body) return handle_builder_event(received_obj) logging.info("Destination: %s" % headers.get("destination")) # Acknowledge that the message has been processed self.message_received = True try: logging.debug("Attempting to connect using new communication module") stomp = getNewStompConnection("", MyListener()) logging.info("Connection established using new communication module") stomp.subscribe(destination=TOPICS["events"], id=uuid.uuid4().hex, ack="client") logging.info("Subscribed to destination %s" % TOPICS["events"]) stomp.subscribe(destination="/topic/keepalive", id=uuid.uuid4().hex, ack="auto") logging.info("Subscribed to %s" % "/topic/keepalive") except Exception as e: logging.error("main() Could not connect to ActiveMQ: %s." % e) raise def main_loop(): logging.info("Waiting to do work. ") while True: time.sleep(15) if __name__ == "__main__":
try: stompBroker = "broker.bioconductor.org" stompBrokerPort = 61613 logMsg("Attempting to connect to stomp broker '%s:%s'" % (stompBroker, stompBrokerPort)) stomp = stomp.Connection([(stompBroker, stompBrokerPort)]) stomp.set_listener("", MyListener()) stomp.start() # optional connect keyword args "username" and "password" like so: # stomp.connect(username="******", password="******") stomp.connect() # clientid=uuid.uuid4().hex) logMsg("Connected to stomp broker '%s:%s'" % (stompBroker, stompBrokerPort)) chan = "/topic/buildjobs" stomp.subscribe(destination=chan, id=uuid.uuid4().hex, ack="client") logMsg("Subscribed to channel %s" % chan) except Exception as e: logMsg("Error connecting to ActiveMQ. Error: %s" % e) raise os.environ["TRACKER_LOGIN"] = "******" os.environ["TRACKER_PASSWORD"] = "******" packagebuilder_home = os.environ["PACKAGEBUILDER_HOME"] builder_id = platform.node().lower().replace(".fhcrc.org", "") if sys.platform == "win32": # bad hardcoding! I don't know why this is necessary: if builder_id in ["windows1", "windows2"]: os.environ["USERDNSDOMAIN"] = "bioconductor.org"
TIMEOUT = 60 # timeout in seconds logging.basicConfig(format='%(levelname)s: %(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) logging.getLogger("stomp.py").setLevel(logging.WARNING) class MyListener(ConnectionListener): def on_message(self, headers, message): logging.info(message) try: logging.info("Attempting to connect using new communication module") stomp = getNewStompConnection('', MyListener()) # stomp.set_listener('', PrintingListener()) stomp.subscribe(destination="/topic/keepalive_response", id=1, ack='auto') logging.info("Connection established using new communication module") except Exception as e: logging.error("main() Could not connect to ActiveMQ: %s." % e) raise while True: stomp.send(destination="/topic/keepalive", body="stay alive!") # level is set to info to keep logs quiet, change to info if # you want to see the following. logging.debug("Sent keepalive message.") time.sleep(TIMEOUT)
logging.info("on_message() Destination handled.") else: logging.warning("on_message() Invalid json (no job_id key).") # Acknowledge that the message has been processed self.message_received = True logging.info("main() Waiting for messages.") try: logging.debug("Attempting to connect using new communication module") stomp = getNewStompConnection('', MyListener()) logging.info("Connection established using new communication module") stomp.subscribe(destination="/topic/buildjobs", id=uuid.uuid4().hex, ack='client') logging.info("Subscribed to %s" % "/topic/buildjobs") stomp.subscribe(destination="/topic/builderevents", id=uuid.uuid4().hex, ack='client') logging.info("Subscribed to %s" % "/topic/builderevents") stomp.subscribe(destination="/topic/keepalive", id=uuid.uuid4().hex, ack='auto') logging.info("Subscribed to %s" % "/topic/keepalive") except: logging.error("Cannot connect to Stomp") raise logging.info("Waiting to do work. ") while True: time.sleep(15) logging.info("Done.")
s=blderProcess.returncode)) builder_log.close() logging.info("on_message() builder_log closed.") except Exception as e: logging.error("on_message() Caught exception: {e}".format(e=e)) return () else: logging.error("on_message() Invalid JSON: missing job_id key.") try: logging.debug("Attempting to connect using new communication module") stomp = getNewStompConnection('', MyListener()) logging.info("Connection established using new communication module") stomp.subscribe(destination=TOPICS['jobs'], id=uuid.uuid4().hex, ack='auto') logging.info("Subscribed to destination %s" % TOPICS['jobs']) stomp.subscribe(destination="/topic/keepalive", id=uuid.uuid4().hex, ack='auto') logging.info("Subscribed to %s" % "/topic/keepalive") except Exception as e: logging.error("main() Could not connect to RabbitMQ: %s." % e) raise logging.info('Waiting for messages; CTRL-C to exit.') while True: if logging.getLogger().isEnabledFor("debug"): logging.debug("main() Waiting to do work.")
blderProcess.wait() logging.info("on_message() blderProcess finished with status {s}.".format(s=blderProcess.returncode)) builder_log.close() logging.info("on_message() builder_log closed.") except Exception as e: logging.error("on_message() Caught exception: {e}".format(e=e)) return() else: logging.error("on_message() Invalid JSON: missing job_id key.") try: logging.debug("Attempting to connect using new communication module") stomp = getNewStompConnection('', MyListener()) logging.info("Connection established using new communication module") stomp.subscribe(destination=TOPICS['jobs'], id=uuid.uuid4().hex, ack='auto') logging.info("Subscribed to destination %s" % TOPICS['jobs']) stomp.subscribe(destination="/topic/keepalive", id=uuid.uuid4().hex, ack='auto') logging.info("Subscribed to %s" % "/topic/keepalive") except Exception as e: logging.error("main() Could not connect to RabbitMQ: %s." % e) raise logging.info('Waiting for messages; CTRL-C to exit.') while True: if logging.getLogger().isEnabledFor("debug"): logging.debug("main() Waiting to do work.")