forked from platypush/platypush
--redis-queue argument should be a string
This commit is contained in:
parent
2e2169544d
commit
239025290d
1 changed files with 72 additions and 34 deletions
|
@ -29,7 +29,7 @@ logger = logging.getLogger('platypush')
|
||||||
|
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
""" Main class for the Platypush daemon """
|
"""Main class for the Platypush daemon"""
|
||||||
|
|
||||||
# Configuration file (default: either ~/.config/platypush/config.yaml or
|
# Configuration file (default: either ~/.config/platypush/config.yaml or
|
||||||
# /etc/platypush/config.yaml
|
# /etc/platypush/config.yaml
|
||||||
|
@ -51,8 +51,15 @@ class Daemon:
|
||||||
# number of executions retries before a request fails
|
# number of executions retries before a request fails
|
||||||
n_tries = 2
|
n_tries = 2
|
||||||
|
|
||||||
def __init__(self, config_file=None, pidfile=None, requests_to_process=None,
|
def __init__(
|
||||||
no_capture_stdout=False, no_capture_stderr=False, redis_queue=None):
|
self,
|
||||||
|
config_file=None,
|
||||||
|
pidfile=None,
|
||||||
|
requests_to_process=None,
|
||||||
|
no_capture_stdout=False,
|
||||||
|
no_capture_stderr=False,
|
||||||
|
redis_queue=None,
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Constructor
|
Constructor
|
||||||
Params:
|
Params:
|
||||||
|
@ -80,8 +87,11 @@ class Daemon:
|
||||||
logging.basicConfig(**Config.get('logging'))
|
logging.basicConfig(**Config.get('logging'))
|
||||||
|
|
||||||
redis_conf = Config.get('backend.redis') or {}
|
redis_conf = Config.get('backend.redis') or {}
|
||||||
self.bus = RedisBus(redis_queue=self.redis_queue, on_message=self.on_message(),
|
self.bus = RedisBus(
|
||||||
**redis_conf.get('redis_args', {}))
|
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_stdout = no_capture_stdout
|
||||||
self.no_capture_stderr = no_capture_stderr
|
self.no_capture_stderr = no_capture_stderr
|
||||||
|
@ -98,33 +108,59 @@ class Daemon:
|
||||||
args -- Your sys.argv[1:] [List of strings]
|
args -- Your sys.argv[1:] [List of strings]
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--config', '-c', dest='config', required=False,
|
parser.add_argument(
|
||||||
default=None, help=cls.config_file.__doc__)
|
'--config',
|
||||||
parser.add_argument('--pidfile', '-P', dest='pidfile', required=False,
|
'-c',
|
||||||
default=None, help="File where platypush will " +
|
dest='config',
|
||||||
"store its PID, useful if you're planning to " +
|
required=False,
|
||||||
"integrate it in a service")
|
default=None,
|
||||||
parser.add_argument('--no-capture-stdout', dest='no_capture_stdout',
|
help=cls.config_file.__doc__,
|
||||||
required=False, action='store_true',
|
)
|
||||||
help="Set this flag if you have max stack depth " +
|
parser.add_argument(
|
||||||
"exceeded errors so stdout won't be captured by " +
|
'--pidfile',
|
||||||
"the logging system")
|
'-P',
|
||||||
parser.add_argument('--no-capture-stderr', dest='no_capture_stderr',
|
dest='pidfile',
|
||||||
required=False, action='store_true',
|
required=False,
|
||||||
help="Set this flag if you have max stack depth " +
|
default=None,
|
||||||
"exceeded errors so stderr won't be captured by " +
|
help="File where platypush will "
|
||||||
"the logging system")
|
+ "store its PID, useful if you're planning to "
|
||||||
parser.add_argument('--redis-queue', dest='redis_queue',
|
+ "integrate it in a service",
|
||||||
required=False, action='store_true',
|
)
|
||||||
default=cls._default_redis_queue,
|
parser.add_argument(
|
||||||
help="Name of the Redis queue to be used to internally deliver messages "
|
'--no-capture-stdout',
|
||||||
"(default: platypush/bus)")
|
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)",
|
||||||
|
)
|
||||||
|
|
||||||
opts, args = parser.parse_known_args(args)
|
opts, args = parser.parse_known_args(args)
|
||||||
return cls(config_file=opts.config, pidfile=opts.pidfile,
|
return cls(
|
||||||
no_capture_stdout=opts.no_capture_stdout,
|
config_file=opts.config,
|
||||||
no_capture_stderr=opts.no_capture_stderr,
|
pidfile=opts.pidfile,
|
||||||
redis_queue=opts.redis_queue)
|
no_capture_stdout=opts.no_capture_stdout,
|
||||||
|
no_capture_stderr=opts.no_capture_stderr,
|
||||||
|
redis_queue=opts.redis_queue,
|
||||||
|
)
|
||||||
|
|
||||||
def on_message(self):
|
def on_message(self):
|
||||||
"""
|
"""
|
||||||
|
@ -145,8 +181,10 @@ class Daemon:
|
||||||
logger.info('Dropped unauthorized request: {}'.format(msg))
|
logger.info('Dropped unauthorized request: {}'.format(msg))
|
||||||
|
|
||||||
self.processed_requests += 1
|
self.processed_requests += 1
|
||||||
if self.requests_to_process \
|
if (
|
||||||
and self.processed_requests >= self.requests_to_process:
|
self.requests_to_process
|
||||||
|
and self.processed_requests >= self.requests_to_process
|
||||||
|
):
|
||||||
self.stop_app()
|
self.stop_app()
|
||||||
elif isinstance(msg, Response):
|
elif isinstance(msg, Response):
|
||||||
logger.info('Received response: {}'.format(msg))
|
logger.info('Received response: {}'.format(msg))
|
||||||
|
@ -158,7 +196,7 @@ class Daemon:
|
||||||
return _f
|
return _f
|
||||||
|
|
||||||
def stop_app(self):
|
def stop_app(self):
|
||||||
""" Stops the backends and the bus """
|
"""Stops the backends and the bus"""
|
||||||
from .plugins import RunnablePlugin
|
from .plugins import RunnablePlugin
|
||||||
|
|
||||||
for backend in self.backends.values():
|
for backend in self.backends.values():
|
||||||
|
@ -173,7 +211,7 @@ class Daemon:
|
||||||
self.cron_scheduler.stop()
|
self.cron_scheduler.stop()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
""" Start the daemon """
|
"""Start the daemon"""
|
||||||
if not self.no_capture_stdout:
|
if not self.no_capture_stdout:
|
||||||
sys.stdout = Logger(logger.info)
|
sys.stdout = Logger(logger.info)
|
||||||
if not self.no_capture_stderr:
|
if not self.no_capture_stderr:
|
||||||
|
|
Loading…
Reference in a new issue