def run_update(args):
logging.info('Getting updates...')
db = init_db(args.db)
cur = db.cursor()
cfg = next(yaml.safe_load_all(open(args.chores, 'r', encoding='utf-8')))
chores_avail = []
tasks = sched.scheduler(time.time)
for name, config in cfg.items():
result = cur.execute('SELECT updated, last_result FROM chore_status WHERE name = ?', (name,)).fetchone()
if result:
result = chores.ChoreStatus(*result)
chorename = config.pop('chore')
chore = chores.CHORE_HANDLERS[chorename](name, status=result, **config)
chores_avail.append((chorename, chore))
try:
while 1:
for chorename, chore in chores_avail:
tasks.enterabs(
chore.status.updated + args.keep * 60,
chores.CHORE_PRIO[chorename],
wrap_fetch, (chore, cur)
)
tasks.run()
db.commit()
if args.keep:
logging.info('A round of updating completed.')
else:
break
except KeyboardInterrupt:
logging.warning('Interrupted.')
finally:
db.commit()
评论列表
文章目录