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
|
import logging
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
|
||||||
import sentry_sdk
|
import sentry_sdk
|
||||||
|
from apscheduler.util import get_callable_name
|
||||||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
from sentry_sdk.integrations.aiohttp import AioHttpIntegration
|
||||||
|
|
||||||
from actioner.scheduler import create_scheduler
|
from actioner.scheduler import create_scheduler
|
||||||
from actioner.settings import LOGGING_LEVEL, SENTRY_DSN
|
from actioner.settings import LOGGING_LEVEL, SENTRY_DSN
|
||||||
from actioner.web import get_server, run_server
|
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():
|
def main():
|
||||||
logging.basicConfig(level=LOGGING_LEVEL)
|
logging.basicConfig(level=LOGGING_LEVEL)
|
||||||
|
|
||||||
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[AioHttpIntegration()])
|
sentry_sdk.init(dsn=SENTRY_DSN, integrations=[AioHttpIntegration()])
|
||||||
|
|
||||||
server = get_server()
|
args = parse_args()
|
||||||
scheduler = create_scheduler()
|
|
||||||
|
|
||||||
# HACK: APScheduler doesn't like running in an external event loop. https://github.com/agronholm/apscheduler/issues/360
|
if args.once:
|
||||||
Process(target=run_server, args=(server,)).start()
|
scheduler = create_scheduler()
|
||||||
Process(target=scheduler.start).start()
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|
Reference in a new issue