def __init__(self, opts): settings = bg_utils.settings_from_args(opts) bg_utils.set_log_level(settings) self._accessor = bg_utils.accessor_from_settings(settings) self._opts = opts self.time_start = time.mktime(self._opts.time_start.timetuple()) self.time_end = time.mktime(self._opts.time_end.timetuple())
def main(args=None): """Entry point for the module.""" if not args: args = sys.argv[1:] opts = _parse_opts(args) settings = bg_utils.settings_from_args(opts) bg_utils.set_log_level(settings) accessor = bg_utils.accessor_from_settings(settings) opts.func(accessor, opts)
def main(args=None, accessor=None): """Entry point for the module.""" if not args: args = sys.argv[1:] opts = _parse_opts(args) settings = bg_utils.settings_from_args(opts) bg_utils.set_log_level(settings) accessor = accessor or bg_utils.accessor_from_settings(settings) opts.func(accessor, opts) accessor.flush()
def test_run_with_args(self): cmd = command_test.CommandTest() parser = argparse.ArgumentParser() bg_utils.add_argparse_arguments(parser) cmd.add_arguments(parser) opts = parser.parse_args(["--cassandra_contact_points=127.0.0.1,192.168.0.1", "--cassandra_contact_points_metadata=127.0.0.1,192.168.1.1"]) settings = bg_utils.settings_from_args(opts) self.assertIsInstance(settings['cassandra_contact_points'], list) self.assertIsInstance( settings['cassandra_contact_points_metadata'], list) cmd.run(self.accessor, opts)
def main(args=None, accessor=None): """Entry point for the module.""" if not args: args = sys.argv[1:] opts = _parse_opts(args) if not getattr(opts, "func", None): opts.func = command_shell.CommandShell().run settings = bg_utils.settings_from_args(opts) bg_utils.set_log_level(settings) accessor = accessor or bg_utils.accessor_from_settings(settings) opts.func(accessor, opts) accessor.flush() accessor.shutdown()
def run(self, accessor, opts): """Run clean and repair at a given frequency. See command.BaseCommand """ workers = { "repair": { "name": "repair", "fn": lambda x: self._run_repair(x, accessor, opts), "output": collections.deque(maxlen=4096), "status": "", "thread": None }, "clean": { "name": "clean", "fn": lambda x: self._run_clean(x, accessor, opts), "output": collections.deque(maxlen=4096), "status": "", "thread": None }, } _init_logger(workers) accessor.connect() # start prometheus server utils.start_admin(utils.settings_from_args(opts)) # Spawn workers for worker in workers.values(): logging.info("starting %s worker" % worker["name"]) th = threading.Thread(name=worker["name"], target=worker["fn"], args=(worker, )) th.daemon = True th.start() worker["thread"] = th _run_webserver(workers, accessor, opts)