-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
37 lines (25 loc) · 843 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
from apscheduler.schedulers.background import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
from github_overlord import cli
from github_overlord.utils import log
def handle_click_exit(func):
def wrapper(*args, **kwargs):
try:
func(*args, **kwargs)
except SystemExit as e:
if e.code != 0:
raise
return wrapper
def job():
for command in list(cli.commands.values()):
log.info("running command", command=command.name)
handle_click_exit(command)()
def cron():
schedule = os.environ.get("SCHEDULE", "0 6 * * *")
print(f"Running on schedule: {schedule}")
scheduler = BlockingScheduler()
scheduler.add_job(job, CronTrigger.from_crontab(schedule))
scheduler.start()
if __name__ == "__main__":
cron()