mirror of
https://github.com/Tech-Workers-Coalition-Italia/mobilizon-reshare.git
synced 2025-02-27 17:07:44 +01:00
added scheduling (#133)
This commit is contained in:
parent
1f1ff2e5c2
commit
8c16812ed0
27
docker/scheduler.py
Normal file
27
docker/scheduler.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# 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
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
||||||
|
from mobilizon_reshare.cli import _safe_execution
|
||||||
|
from mobilizon_reshare.cli.commands.start.main import start
|
||||||
|
|
||||||
|
sched = AsyncIOScheduler()
|
||||||
|
|
||||||
|
# Runs "start" from Monday to Friday every 15 mins
|
||||||
|
sched.add_job(
|
||||||
|
partial(_safe_execution, start),
|
||||||
|
"cron",
|
||||||
|
day_of_week="mon-fri",
|
||||||
|
minute="*/15",
|
||||||
|
hour="10-18",
|
||||||
|
)
|
||||||
|
# Runs "recap" once a week
|
||||||
|
sched.add_job(partial(_safe_execution, start), "cron", day_of_week="mon", hour="11")
|
||||||
|
sched.start()
|
||||||
|
try:
|
||||||
|
asyncio.get_event_loop().run_forever()
|
||||||
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
pass
|
@ -10,9 +10,8 @@ from mobilizon_reshare.storage.db import tear_down, MoReDB
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
async def graceful_exit(code):
|
async def graceful_exit():
|
||||||
await tear_down()
|
await tear_down()
|
||||||
exit(code)
|
|
||||||
|
|
||||||
|
|
||||||
async def init():
|
async def init():
|
||||||
@ -33,8 +32,10 @@ async def _safe_execution(f):
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
finally:
|
finally:
|
||||||
logger.debug("Closing")
|
logger.debug("Closing")
|
||||||
await graceful_exit(return_code)
|
await graceful_exit()
|
||||||
|
return return_code
|
||||||
|
|
||||||
|
|
||||||
def safe_execution(f):
|
def safe_execution(f):
|
||||||
asyncio.run(_safe_execution(f))
|
code = asyncio.run(_safe_execution(f))
|
||||||
|
exit(code)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user