def update_webhook_schedule(): """ A scheduled background job that runs every 30 minutes to poll the database for changes and reschedule the webhook time """ session = create_session() all_groups: list[GroupInDB] = db.groups.get_all(session) for group in all_groups: time = cron_parser(group.webhook_time) job = JOB_STORE.get(group.name) if not job: logger.error(f"No job found for group: {group.name}") logger.info(f"Creating scheduled task for {group.name}") JOB_STORE.update(add_group_to_schedule(scheduler, group)) continue scheduler.reschedule_job( job.scheduled_task.id, trigger="cron", hour=time.hours, minute=time.minutes, ) session.close() logger.info(scheduler.print_jobs())
def update_webhook_schedule(): """ A scheduled background job that runs every 30 minutes to poll the database for changes and reschedule the webhook time """ session = create_session() all_groups: list[GroupInDB] = db.groups.get_all(session) for group in all_groups: time = cron_parser(group.webhook_time) job = JOB_STORE.get(group.name) scheduler.reschedule_job( job.scheduled_task.id, trigger="cron", hour=time.hours, minute=time.minutes, ) session.close() logger.info(scheduler.print_jobs())
name=group.name, args=[group.id], ) } def init_webhook_schedule(scheduler, job_store: dict): session = create_session() all_groups: list[GroupInDB] = db.groups.get_all(session) for group in all_groups: job_store.update(add_group_to_schedule(scheduler, group)) session.close() return job_store logger.info("----INIT SCHEDULE OBJECT-----") JOB_STORE = { "backup_job": ScheduledFunction(scheduler, auto_backup_job, Cron(hours=00, minutes=00), "backups"), } JOB_STORE = init_webhook_schedule(scheduler=scheduler, job_store=JOB_STORE) logger.info(scheduler.print_jobs()) scheduler.start()