Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli/__init__.py
# Copyright (C) 2016-2019 The Software Heritage developers | # Copyright (C) 2016-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import click | import click | ||||
import logging | import logging | ||||
from swh.core.cli import CONTEXT_SETTINGS | |||||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help']) | |||||
@click.group(context_settings=CONTEXT_SETTINGS) | @click.group(context_settings=CONTEXT_SETTINGS) | ||||
@click.option('--config-file', '-C', default=None, | @click.option('--config-file', '-C', default=None, | ||||
type=click.Path(exists=True, dir_okay=False,), | type=click.Path(exists=True, dir_okay=False,), | ||||
help="Configuration file.") | help="Configuration file.") | ||||
@click.option('--database', '-d', default=None, | @click.option('--database', '-d', default=None, | ||||
help="Scheduling database DSN (imply cls is 'local')") | help="Scheduling database DSN (imply cls is 'local')") | ||||
@click.option('--url', '-u', default=None, | @click.option('--url', '-u', default=None, | ||||
help="Scheduler's url access (imply cls is 'remote')") | help="Scheduler's url access (imply cls is 'remote')") | ||||
@click.option('--no-stdout', is_flag=True, default=False, | @click.option('--no-stdout', is_flag=True, default=False, | ||||
help="Do NOT output logs on the console") | help="Do NOT output logs on the console") | ||||
@click.pass_context | @click.pass_context | ||||
def cli(ctx, config_file, database, url, no_stdout): | def cli(ctx, config_file, database, url, no_stdout): | ||||
"""Scheduler CLI interface. | """Scheduler CLI interface. | ||||
Default to use the the local scheduler instance (plugged to the | Default to use the the local scheduler instance (plugged to the | ||||
main scheduler db). | main scheduler db). | ||||
""" | """ | ||||
from swh.core import config | from swh.core import config | ||||
from swh.scheduler.celery_backend.config import setup_log_handler | from swh.scheduler.celery_backend.config import setup_log_handler | ||||
from swh.scheduler import get_scheduler, DEFAULT_CONFIG | from swh.scheduler import get_scheduler, DEFAULT_CONFIG | ||||
ctx.ensure_object(dict) | |||||
# TODO: Remove the two lines below once the swh-scheduler command | |||||
# is dropped | |||||
log_level = logging.INFO | |||||
if 'log_level' in ctx.obj: | |||||
log_level = ctx.obj['log_level'] | |||||
setup_log_handler( | setup_log_handler( | ||||
loglevel=ctx.obj['log_level'], colorize=False, | loglevel=log_level, colorize=False, | ||||
format='[%(levelname)s] %(name)s -- %(message)s', | format='[%(levelname)s] %(name)s -- %(message)s', | ||||
log_console=not no_stdout) | log_console=not no_stdout) | ||||
ctx.ensure_object(dict) | |||||
logger = logging.getLogger(__name__) | logger = logging.getLogger(__name__) | ||||
scheduler = None | scheduler = None | ||||
conf = config.read(config_file, DEFAULT_CONFIG) | conf = config.read(config_file, DEFAULT_CONFIG) | ||||
if 'scheduler' not in conf: | if 'scheduler' not in conf: | ||||
raise ValueError("missing 'scheduler' configuration") | raise ValueError("missing 'scheduler' configuration") | ||||
if database: | if database: | ||||
conf['scheduler']['cls'] = 'local' | conf['scheduler']['cls'] = 'local' | ||||
Show All 27 Lines |