From ab13e512371a260ad678a68550cbafccafa1c6c4 Mon Sep 17 00:00:00 2001 From: Peter Dahlberg Date: Mon, 13 Jun 2016 16:05:22 +0200 Subject: [PATCH] things --- develop_main.py | 24 ++++++++++++++++-------- pelican_deploy/deploy.py | 9 ++++++--- pelican_deploy/webhookbottle.py | 2 -- requirements.txt | 2 ++ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/develop_main.py b/develop_main.py index 3548c5c..e85cc22 100755 --- a/develop_main.py +++ b/develop_main.py @@ -3,30 +3,38 @@ 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 import pelican_deploy.webhookbottle import logging if __name__ == "__main__": - #for r in runners.values(): - # r.build_blocking() config = SourceFileLoader("config", "deploy_config.py").load_module() runners = {name: DeploymentRunner(name, conf) for name, conf in config.RUNNERS.items()} - # start a scheduler - scheduler = BackgroundScheduler() - scheduler.start() + #for r in runners.values(): + # print(r.build(wait=True)) + + schedulers = {r: BackgroundScheduler(daemon=False) for r in runners} + for s in schedulers.values(): + s.start() for i, (rname, trigger) in enumerate(config.SCHEDULED_BUILD_JOBS): - scheduler.add_job(runners[rname].build, trigger=trigger, - name="{} ({})".format(i, rname)) + 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) - pelican_deploy.webhookbottle.devrun() + default_app().mount("/hooks/", pelican_deploy.webhookbottle.app) + + run(host='0.0.0.0', port=4000, debug=True) diff --git a/pelican_deploy/deploy.py b/pelican_deploy/deploy.py index d9ac8f2..7a9808d 100644 --- a/pelican_deploy/deploy.py +++ b/pelican_deploy/deploy.py @@ -85,7 +85,7 @@ class DeploymentRunner: # deinit submodules to avoid removed ones dangling around later # they should stay around in .git, so reinit should be fast - result = repo.submodule("deinit", ".") + result = repo.submodule("deinit", "--force", ".") log_git(result) result = repo.checkout("--force", self.git_branch) @@ -111,7 +111,7 @@ class DeploymentRunner: result = repo.submodule("update", "--init", "--force", "--recursive") log_git(result) - def build(self, abort_running=False): + def build(self, abort_running=False, wait=False): with self._build_lock: if abort_running: self.try_abort_build() @@ -123,7 +123,10 @@ class DeploymentRunner: self._futures.remove(fut) build_func = exception_logged(self.build_blocking, log.error) - self._futures.add(self._executor.submit(build_func)) + future = self._executor.submit(build_func) + self._futures.add(future) + if wait: + return future.result() def try_abort_build(self): proc = self._build_proc diff --git a/pelican_deploy/webhookbottle.py b/pelican_deploy/webhookbottle.py index f8025f6..2e47d11 100644 --- a/pelican_deploy/webhookbottle.py +++ b/pelican_deploy/webhookbottle.py @@ -62,5 +62,3 @@ def github(name): _start_build(name, hook.get("ref", "")) return "Success!" -def devrun(): - run(app=app, host='0.0.0.0', port=4000, debug=True) diff --git a/requirements.txt b/requirements.txt index ab859ba..9eae50f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ bottle apscheduler +pytz +tzlocal tox