Mobilizon-Reshare-condividi.../scripts/scheduler.py

52 lines
1.3 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
"""
This module allows to customize the scheduling logic for mobilizon-reshare.
It's not intended to be part of the supported code base but just an example on how to schedule the commands of
mobilizon-reshare.
"""
import asyncio
import os
from functools import partial
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from apscheduler.triggers.cron import CronTrigger
from mobilizon_reshare.cli import _safe_execution
from mobilizon_reshare.cli.commands.recap.main import recap as recap_main
from mobilizon_reshare.cli.commands.start.main import start as start_main
2023-07-11 15:23:40 +02:00
from mobilizon_reshare.config.command import CommandConfig
sched = AsyncIOScheduler()
2023-07-11 15:23:40 +02:00
config = CommandConfig(dry_run=False)
async def start():
await start_main(config)
async def recap():
await recap_main(config)
# Runs "start" from Monday to Friday every 15 mins
sched.add_job(
partial(_safe_execution, start),
CronTrigger.from_crontab(
os.environ.get("MOBILIZON_RESHARE_INTERVAL", "*/15 10-18 * * 1-4")
),
)
# Runs "recap" once a week
sched.add_job(
partial(_safe_execution, recap),
CronTrigger.from_crontab(
os.environ.get("MOBILIZON_RESHARE_RECAP_INTERVAL", "5 11 * * 0")
),
)
sched.start()
try:
asyncio.get_event_loop().run_forever()
except (KeyboardInterrupt, SystemExit):
pass