2022-02-05 18:46:02 +01:00
|
|
|
#!/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
|
2023-07-11 15:49:37 +02:00
|
|
|
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
|
2022-02-05 18:46:02 +01:00
|
|
|
|
|
|
|
sched = AsyncIOScheduler()
|
2023-07-11 15:23:40 +02:00
|
|
|
config = CommandConfig(dry_run=False)
|
2022-02-05 18:46:02 +01:00
|
|
|
|
2023-07-11 15:49:37 +02:00
|
|
|
|
|
|
|
async def start():
|
|
|
|
await start_main(config)
|
|
|
|
|
|
|
|
|
|
|
|
async def recap():
|
|
|
|
await recap_main(config)
|
|
|
|
|
|
|
|
|
2022-02-05 18:46:02 +01:00
|
|
|
# Runs "start" from Monday to Friday every 15 mins
|
|
|
|
sched.add_job(
|
2023-07-11 15:49:37 +02:00
|
|
|
partial(_safe_execution, start),
|
2022-02-05 18:46:02 +01:00
|
|
|
CronTrigger.from_crontab(
|
2023-07-11 15:49:37 +02:00
|
|
|
os.environ.get("MOBILIZON_RESHARE_INTERVAL", "*/15 10-18 * * 1-4")
|
2022-02-05 18:46:02 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
# Runs "recap" once a week
|
|
|
|
sched.add_job(
|
2023-07-11 15:49:37 +02:00
|
|
|
partial(_safe_execution, recap),
|
2022-02-05 18:46:02 +01:00
|
|
|
CronTrigger.from_crontab(
|
2022-02-20 12:45:50 +01:00
|
|
|
os.environ.get("MOBILIZON_RESHARE_RECAP_INTERVAL", "5 11 * * 0")
|
2022-02-05 18:46:02 +01:00
|
|
|
),
|
|
|
|
)
|
|
|
|
sched.start()
|
|
|
|
try:
|
|
|
|
asyncio.get_event_loop().run_forever()
|
|
|
|
except (KeyboardInterrupt, SystemExit):
|
|
|
|
pass
|