Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/cli.py
Show First 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | def cli(ctx, config_file, database, url, log_level): | ||||
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'] = 'local' | 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('Instanciating scheduler with %s' % ( | logger.debug('Instanciating scheduler with %s' % ( | ||||
sched_conf)) | sched_conf)) | ||||
scheduler = get_scheduler(**sched_conf) | scheduler = get_scheduler(**sched_conf) | ||||
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. | ||||
▲ Show 20 Lines • Show All 374 Lines • ▼ Show 20 Lines | def runner(ctx, period): | ||||
try: | try: | ||||
while True: | while True: | ||||
logger.debug('Run ready tasks') | logger.debug('Run ready tasks') | ||||
try: | try: | ||||
ntasks = len(run_ready_tasks(scheduler, app)) | ntasks = len(run_ready_tasks(scheduler, app)) | ||||
if ntasks: | if ntasks: | ||||
logger.info('Scheduled %s tasks', ntasks) | logger.info('Scheduled %s tasks', ntasks) | ||||
except Exception: | except Exception: | ||||
scheduler.rollback() | |||||
logger.exception('Unexpected error in run_ready_tasks()') | logger.exception('Unexpected error in run_ready_tasks()') | ||||
if not period: | if not period: | ||||
break | break | ||||
time.sleep(period) | time.sleep(period) | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
ctx.exit(0) | ctx.exit(0) | ||||
▲ Show 20 Lines • Show All 145 Lines • Show Last 20 Lines |