def main(args=sys.argv): parser = argparse.ArgumentParser(description="Loads broker.") parser.add_argument("--frontend", dest="frontend", default=DEFAULT_FRONTEND, help="ZMQ socket to receive jobs.") parser.add_argument("--backend", dest="backend", default=DEFAULT_BACKEND, help="ZMQ socket for agents.") parser.add_argument("--heartbeat", dest="heartbeat", default=None, help="ZMQ socket for the heartbeat.") parser.add_argument("--register", dest="register", default=DEFAULT_REG, help="ZMQ socket for the registration.") parser.add_argument( "--receiver", dest="receiver", default=DEFAULT_BROKER_RECEIVER, help="ZMQ socket to receive events from the runners", ) parser.add_argument( "--publisher", dest="publisher", default=DEFAULT_PUBLISHER, help="ZMQ socket for the registration." ) parser.add_argument("--io-threads", type=int, default=DEFAULT_IOTHREADS, help="Number of I/O threads") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode") parser.add_argument( "--check", action="store_true", default=False, help=("Use this option to check if there's a running " " broker. Returns the PID if a broker is up."), ) parser.add_argument("--logfile", dest="logfile", default="stdout", help="File to log in to.") parser.add_argument("--db", dest="db", default="python", help="Database backend.") parser.add_argument("--web-root", help="Root url of the web dashboard.", type=str, default=None) # add db args for backend, options in get_backends(): for option, default, help, type_ in options: option = "db_%s_%s" % (backend, option) kargs = {"dest": option, "default": default} if type_ is bool: kargs["action"] = "store_true" else: kargs["type"] = type_ option = option.replace("_", "-") parser.add_argument("--%s" % option, **kargs) args = parser.parse_args() set_logger(args.debug, logfile=args.logfile) if args.check: pid = verify_broker(args.frontend) if pid is None: logger.info("There seem to be no broker on this endpoint") else: logger.info("A broker is running. PID: %s" % pid) return 0 # grabbing the db options dboptions = {} prefix = "db_%s_" % args.db for key, value in args._get_kwargs(): if not key.startswith(prefix): continue dboptions[key[len(prefix) :]] = value logger.info("Starting the broker") try: broker = Broker( frontend=args.frontend, backend=args.backend, heartbeat=args.heartbeat, register=args.register, receiver=args.receiver, publisher=args.publisher, io_threads=args.io_threads, db=args.db, dboptions=dboptions, web_root=args.web_root, ) except DuplicateBrokerError, e: logger.info("There is already a broker running on PID %s" % e) logger.info("Exiting") return 1
def main(args=sys.argv): parser = argparse.ArgumentParser(description='Loads broker.') parser.add_argument('--frontend', dest='frontend', default=DEFAULT_FRONTEND, help="ZMQ socket to receive jobs.") parser.add_argument('--backend', dest='backend', default=DEFAULT_BACKEND, help="ZMQ socket for agents.") parser.add_argument('--heartbeat', dest='heartbeat', default=None, help="ZMQ socket for the heartbeat.") parser.add_argument('--register', dest='register', default=DEFAULT_REG, help="ZMQ socket for the registration.") parser.add_argument('--receiver', dest='receiver', default=DEFAULT_BROKER_RECEIVER, help="ZMQ socket to receive events from the runners") parser.add_argument('--publisher', dest='publisher', default=DEFAULT_PUBLISHER, help="ZMQ socket for the registration.") parser.add_argument('--io-threads', type=int, default=DEFAULT_IOTHREADS, help="Number of I/O threads") parser.add_argument('--debug', action='store_true', default=False, help="Debug mode") parser.add_argument('--check', action='store_true', default=False, help=("Use this option to check if there's a running " " broker. Returns the PID if a broker is up.")) parser.add_argument('--logfile', dest='logfile', default='stdout', help="File to log in to.") parser.add_argument('--db', dest='db', default='python', help="Database backend.") parser.add_argument('--web-root', help='Root url of the web dashboard.', type=str, default=None) # add db args for backend, options in get_backends(): for option, default, help, type_ in options: option = 'db_%s_%s' % (backend, option) kargs = {'dest': option, 'default': default} if type_ is bool: kargs['action'] = 'store_true' else: kargs['type'] = type_ option = option.replace('_', '-') parser.add_argument('--%s' % option, **kargs) args = parser.parse_args() set_logger(args.debug, logfile=args.logfile) if args.check: pid = verify_broker(args.frontend) if pid is None: logger.info('There seem to be no broker on this endpoint') else: logger.info('A broker is running. PID: %s' % pid) return 0 # grabbing the db options dboptions = {} prefix = 'db_%s_' % args.db for key, value in args._get_kwargs(): if not key.startswith(prefix): continue dboptions[key[len(prefix):]] = value logger.info('Starting the broker') try: broker = Broker(frontend=args.frontend, backend=args.backend, heartbeat=args.heartbeat, register=args.register, receiver=args.receiver, publisher=args.publisher, io_threads=args.io_threads, db=args.db, dboptions=dboptions, web_root=args.web_root) except DuplicateBrokerError, e: logger.info('There is already a broker running on PID %s' % e) logger.info('Exiting') return 1
def main(args=sys.argv): parser = argparse.ArgumentParser(description='Loads broker.') parser.add_argument('--frontend', dest='frontend', default=DEFAULT_FRONTEND, help="ZMQ socket to receive jobs.") parser.add_argument('--backend', dest='backend', default=DEFAULT_BACKEND, help="ZMQ socket for agents.") parser.add_argument('--heartbeat', dest='heartbeat', default=None, help="ZMQ socket for the heartbeat.") parser.add_argument('--register', dest='register', default=DEFAULT_REG, help="ZMQ socket for the registration.") parser.add_argument('--receiver', dest='receiver', default=DEFAULT_BROKER_RECEIVER, help="ZMQ socket to receive events from the runners") parser.add_argument('--publisher', dest='publisher', default=DEFAULT_PUBLISHER, help="ZMQ socket for the registration.") parser.add_argument('--io-threads', type=int, default=DEFAULT_IOTHREADS, help="Number of I/O threads") parser.add_argument('--debug', action='store_true', default=False, help="Debug mode") parser.add_argument('--check', action='store_true', default=False, help=("Use this option to check if there's a running " " broker. Returns the PID if a broker is up.")) parser.add_argument('--logfile', dest='logfile', default='stdout', help="File to log in to.") parser.add_argument('--db', dest='db', default='python', help="Database backend.") # add db args for backend, options in get_backends(): for option, default, help, type_ in options: option = 'db_%s_%s' % (backend, option) kargs = {'dest': option, 'default': default} if type_ is bool: kargs['action'] = 'store_true' else: kargs['type'] = type_ option = option.replace('_', '-') parser.add_argument('--%s' % option, **kargs) args = parser.parse_args() set_logger(args.debug, logfile=args.logfile) if args.check: pid = verify_broker(args.frontend) if pid is None: logger.info('There seem to be no broker on this endpoint') else: logger.info('A broker is running. PID: %s' % pid) return 0 # grabbing the db options dboptions = {} prefix = 'db_%s_' % args.db for key, value in args._get_kwargs(): if not key.startswith(prefix): continue dboptions[key[len(prefix):]] = value logger.info('Starting the broker') try: broker = Broker(frontend=args.frontend, backend=args.backend, heartbeat=args.heartbeat, register=args.register, receiver=args.receiver, publisher=args.publisher, io_threads=args.io_threads, db=args.db, dboptions=dboptions) except DuplicateBrokerError, e: logger.info('There is already a broker running on PID %s' % e) logger.info('Exiting') return 1
def test_get_backends(self): backends = get_backends() if NO_REDIS_LIB: self.assertEqual(len(backends), 1) else: self.assertEqual(len(backends), 2)