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 logging | import logging | ||||
from swh.core.cli import CONTEXT_SETTINGS | import click | ||||
from swh.core.cli import CONTEXT_SETTINGS, AliasedGroup | |||||
@click.group(context_settings=CONTEXT_SETTINGS) | @click.group(name='scheduler', context_settings=CONTEXT_SETTINGS, | ||||
cls=AliasedGroup) | |||||
@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. | """Software Heritage Scheduler tools. | ||||
Default to use the the local scheduler instance (plugged to the | Use a local scheduler instance by default (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) | ctx.ensure_object(dict) | ||||
log_level = ctx.obj.get('log_level', logging.INFO) | log_level = ctx.obj.get('log_level', logging.INFO) | ||||
Show All 22 Lines | def cli(ctx, config_file, database, url, no_stdout): | ||||
except ValueError: | except ValueError: | ||||
# it's the subcommand to decide whether not having a proper | # it's the subcommand to decide whether not having a proper | ||||
# scheduler instance is a problem. | # scheduler instance is a problem. | ||||
pass | pass | ||||
ctx.obj['scheduler'] = scheduler | ctx.obj['scheduler'] = scheduler | ||||
ctx.obj['config'] = conf | ctx.obj['config'] = conf | ||||
from . import admin, task, task_type # noqa | from . import admin, task, task_type # noqa | ||||
def main(): | def main(): | ||||
import click.core | |||||
click.core.DEPRECATED_HELP_NOTICE = ''' | |||||
DEPRECATED! Please use the command 'swh scheduler'.''' | |||||
cli.deprecated = True | |||||
return cli(auto_envvar_prefix='SWH_SCHEDULER') | return cli(auto_envvar_prefix='SWH_SCHEDULER') | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
main() | main() |