Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli/__init__.py
Show All 31 Lines | |||||
) | ) | ||||
@click.pass_context | @click.pass_context | ||||
def cli(ctx, config_file, database, url, no_stdout): | def cli(ctx, config_file, database, url, no_stdout): | ||||
"""Software Heritage Scheduler tools. | """Software Heritage Scheduler tools. | ||||
Use a local scheduler instance by default (plugged to the | Use a local scheduler instance by default (plugged to the | ||||
main scheduler db). | main scheduler db). | ||||
""" | """ | ||||
try: | |||||
from psycopg2 import OperationalError | |||||
except ImportError: | |||||
class OperationalError(Exception): | |||||
pass | |||||
from swh.core import config | from swh.core import config | ||||
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) | |||||
setup_log_handler( | |||||
loglevel=log_level, | |||||
colorize=False, | |||||
format="[%(levelname)s] %(name)s -- %(message)s", | |||||
log_console=not no_stdout, | |||||
) | |||||
douardda: why is this removed? why in this revision? How is it related to added celery monitor cli… | |||||
Done Inline ActionsYeah, I wanted to do a separate commit for that, and then promptly forgot about it. olasd: Yeah, I wanted to do a separate commit for that, and then promptly forgot about it. | |||||
Done Inline ActionsNow done. olasd: Now done. | |||||
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" | ||||
conf["scheduler"]["args"]["db"] = database | conf["scheduler"]["args"]["db"] = database | ||||
elif url: | elif url: | ||||
conf["scheduler"]["cls"] = "remote" | conf["scheduler"]["cls"] = "remote" | ||||
conf["scheduler"]["args"] = {"url": url} | conf["scheduler"]["args"] = {"url": url} | ||||
sched_conf = conf["scheduler"] | sched_conf = conf["scheduler"] | ||||
try: | try: | ||||
logger.debug("Instantiating scheduler with %s" % (sched_conf)) | logger.debug("Instantiating scheduler with %s" % (sched_conf)) | ||||
scheduler = get_scheduler(**sched_conf) | scheduler = get_scheduler(**sched_conf) | ||||
except ValueError: | except (ValueError, OperationalError): | ||||
# 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, celery_monitor, task, task_type # noqa | ||||
def main(): | def main(): | ||||
import click.core | import click.core | ||||
click.core.DEPRECATED_HELP_NOTICE = """ | click.core.DEPRECATED_HELP_NOTICE = """ | ||||
DEPRECATED! Please use the command 'swh scheduler'.""" | DEPRECATED! Please use the command 'swh scheduler'.""" | ||||
cli.deprecated = True | 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() |
why is this removed? why in this revision? How is it related to added celery monitor cli commands?