Allow running scheduled jobs once
This commit is contained in:
parent
9fd854dfe4
commit
2ef14e8d9e
1 changed files with 20 additions and 5 deletions
|
@ -1,25 +1,40 @@
|
|||
import argparse
|
||||
import logging
|
||||
from multiprocessing import Process
|
||||
|
||||
import sentry_sdk
|
||||
from apscheduler.util import get_callable_name
|
||||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||
|
||||
from actioner.scheduler import create_scheduler
|
||||
from actioner.settings import LOGGING_LEVEL, SENTRY_DSN
|
||||
from actioner.web import get_server, run_server
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--once", action="store_true")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
logging.basicConfig(level=LOGGING_LEVEL)
|
||||
|
||||
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[AioHttpIntegration()])
|
||||
|
||||
server = get_server()
|
||||
scheduler = create_scheduler()
|
||||
args = parse_args()
|
||||
|
||||
# HACK: APScheduler doesn't like running in an external event loop. https://github.com/agronholm/apscheduler/issues/360
|
||||
Process(target=run_server, args=(server,)).start()
|
||||
Process(target=scheduler.start).start()
|
||||
if args.once:
|
||||
scheduler = create_scheduler()
|
||||
jobs = {job.func for job in scheduler.get_jobs()}
|
||||
for job in jobs:
|
||||
logger.info("Executing '{}'".format(get_callable_name(job)))
|
||||
job()
|
||||
else:
|
||||
Process(target=run_server, args=(get_server(),)).start()
|
||||
Process(target=create_scheduler().start).start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Reference in a new issue