--redis-queue argument should be a string

This commit is contained in:
Fabio Manganiello 2022-05-25 10:11:06 +02:00
parent 2e2169544d
commit 239025290d
Signed by: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -51,8 +51,15 @@ class Daemon:
# number of executions retries before a request fails
n_tries = 2
def __init__(self, config_file=None, pidfile=None, requests_to_process=None,
no_capture_stdout=False, no_capture_stderr=False, redis_queue=None):
def __init__(
self,
config_file=None,
pidfile=None,
requests_to_process=None,
no_capture_stdout=False,
no_capture_stderr=False,
redis_queue=None,
):
"""
Constructor
Params:
@ -80,8 +87,11 @@ class Daemon:
logging.basicConfig(**Config.get('logging'))
redis_conf = Config.get('backend.redis') or {}
self.bus = RedisBus(redis_queue=self.redis_queue, on_message=self.on_message(),
**redis_conf.get('redis_args', {}))
self.bus = RedisBus(
redis_queue=self.redis_queue,
on_message=self.on_message(),
**redis_conf.get('redis_args', {})
)
self.no_capture_stdout = no_capture_stdout
self.no_capture_stderr = no_capture_stderr
@ -98,33 +108,59 @@ class Daemon:
args -- Your sys.argv[1:] [List of strings]
"""
parser = argparse.ArgumentParser()
parser.add_argument('--config', '-c', dest='config', required=False,
default=None, help=cls.config_file.__doc__)
parser.add_argument('--pidfile', '-P', dest='pidfile', required=False,
default=None, help="File where platypush will " +
"store its PID, useful if you're planning to " +
"integrate it in a service")
parser.add_argument('--no-capture-stdout', dest='no_capture_stdout',
required=False, action='store_true',
help="Set this flag if you have max stack depth " +
"exceeded errors so stdout won't be captured by " +
"the logging system")
parser.add_argument('--no-capture-stderr', dest='no_capture_stderr',
required=False, action='store_true',
help="Set this flag if you have max stack depth " +
"exceeded errors so stderr won't be captured by " +
"the logging system")
parser.add_argument('--redis-queue', dest='redis_queue',
required=False, action='store_true',
parser.add_argument(
'--config',
'-c',
dest='config',
required=False,
default=None,
help=cls.config_file.__doc__,
)
parser.add_argument(
'--pidfile',
'-P',
dest='pidfile',
required=False,
default=None,
help="File where platypush will "
+ "store its PID, useful if you're planning to "
+ "integrate it in a service",
)
parser.add_argument(
'--no-capture-stdout',
dest='no_capture_stdout',
required=False,
action='store_true',
help="Set this flag if you have max stack depth "
+ "exceeded errors so stdout won't be captured by "
+ "the logging system",
)
parser.add_argument(
'--no-capture-stderr',
dest='no_capture_stderr',
required=False,
action='store_true',
help="Set this flag if you have max stack depth "
+ "exceeded errors so stderr won't be captured by "
+ "the logging system",
)
parser.add_argument(
'--redis-queue',
dest='redis_queue',
required=False,
default=cls._default_redis_queue,
help="Name of the Redis queue to be used to internally deliver messages "
"(default: platypush/bus)")
"(default: platypush/bus)",
)
opts, args = parser.parse_known_args(args)
return cls(config_file=opts.config, pidfile=opts.pidfile,
return cls(
config_file=opts.config,
pidfile=opts.pidfile,
no_capture_stdout=opts.no_capture_stdout,
no_capture_stderr=opts.no_capture_stderr,
redis_queue=opts.redis_queue)
redis_queue=opts.redis_queue,
)
def on_message(self):
"""
@ -145,8 +181,10 @@ class Daemon:
logger.info('Dropped unauthorized request: {}'.format(msg))
self.processed_requests += 1
if self.requests_to_process \
and self.processed_requests >= self.requests_to_process:
if (
self.requests_to_process
and self.processed_requests >= self.requests_to_process
):
self.stop_app()
elif isinstance(msg, Response):
logger.info('Received response: {}'.format(msg))