mirror of
https://github.com/IEEE-SB-Passau/pelican-deployment-system.git
synced 2017-09-06 16:35:38 +02:00
app.py, starts a wsgiref server, can also be imported to get wsgi app
This commit is contained in:
59
app.py
Executable file
59
app.py
Executable file
@@ -0,0 +1,59 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
from pelican_deploy import DeploymentRunner
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from importlib.machinery import SourceFileLoader
|
||||
from operator import methodcaller
|
||||
from bottle import run, default_app
|
||||
from wsgiref.simple_server import make_server
|
||||
import pelican_deploy.webhookbottle
|
||||
import logging
|
||||
import atexit
|
||||
import sys
|
||||
|
||||
def init_app(configpath):
|
||||
|
||||
config = SourceFileLoader("config", configpath).load_module()
|
||||
|
||||
runners = {name: DeploymentRunner(name, conf)
|
||||
for name, conf in config.RUNNERS.items()}
|
||||
|
||||
for r in runners.values():
|
||||
atexit.register(r.shutdown) # finally, wait for builds to finish
|
||||
|
||||
for r in runners.values():
|
||||
atexit.register(r.try_abort_build) # then try to abort running builds
|
||||
|
||||
schedulers = {r: BackgroundScheduler(daemon=True) for r in runners}
|
||||
for s in schedulers.values():
|
||||
s.start()
|
||||
atexit.register(s.shutdown) # first stop the schedulers
|
||||
|
||||
atexit.register(print,
|
||||
"<><><><><><><><><><><><><><><><><><><><><><><><><>\n",
|
||||
">>>>> Shutting down gracefully, please wait! <<<<<\n",
|
||||
"<><><><><><><><><><><><><><><><><><><><><><><><><>",
|
||||
file=sys.stderr, sep="")
|
||||
|
||||
for i, (rname, trigger) in enumerate(config.SCHEDULED_BUILD_JOBS):
|
||||
schedulers[rname].add_job(runners[rname].build,
|
||||
trigger=trigger,
|
||||
name="{} ({})".format(rname, i),
|
||||
id="{}_{}".format(rname, i),
|
||||
max_instances=1,
|
||||
kwars={"wait": True})
|
||||
|
||||
pelican_deploy.webhookbottle.set_runners(**runners)
|
||||
pelican_deploy.webhookbottle.set_github_secret(config.GITHUB_SECRET)
|
||||
default_app().mount("/hooks/", pelican_deploy.webhookbottle.app)
|
||||
|
||||
return default_app()
|
||||
|
||||
if __name__ == "__main__":
|
||||
if (len(sys.argv) != 4):
|
||||
print("Usage: {} <configfile> <host> <port>".format(sys.argv[0]))
|
||||
sys.exit(1)
|
||||
_, configpath, host, port = sys.argv
|
||||
|
||||
app = init_app(configpath)
|
||||
run(app=app, host=host, port=port, debug=True)
|
||||
Reference in New Issue
Block a user