From ec4523cd1ba35a1e5e444fa1e899d4fda56076b9 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Wed, 1 Jul 2020 19:11:18 +0100 Subject: [PATCH] Fix the server to use plain text dependencies as input --- gitlab_docker_autodep/main.py | 11 ++----- gitlab_docker_autodep/rebuild.py | 3 -- gitlab_docker_autodep/server.py | 51 ++------------------------------ 3 files changed, 6 insertions(+), 59 deletions(-) diff --git a/gitlab_docker_autodep/main.py b/gitlab_docker_autodep/main.py index eb36202..58313d1 100644 --- a/gitlab_docker_autodep/main.py +++ b/gitlab_docker_autodep/main.py @@ -141,15 +141,10 @@ def main(): rebuild_deps(gl, deps, project_path, branch_name, args.dry_run, args.recurse) elif cmd == 'server': + deps = read_deps(sys.stdin) # TODO - run_app( - args.url, - gitlab_token, - args.deps, - args.bind_host, - args.bind_port, - args.webhook_auth_token, - ) + run_app(gl, deps, args.bind_host, args.bind_port, + args.webhook_auth_token) if __name__ == '__main__': diff --git a/gitlab_docker_autodep/rebuild.py b/gitlab_docker_autodep/rebuild.py index b7b70a3..b9cbf4c 100644 --- a/gitlab_docker_autodep/rebuild.py +++ b/gitlab_docker_autodep/rebuild.py @@ -26,6 +26,3 @@ def rebuild_deps(gl, project_deps, project_path, branch_name, dry_run, rebuild(gl, path, wait_and_recurse) if wait_and_recurse: stack.extend(project_deps.get(path, [])) - - - diff --git a/gitlab_docker_autodep/server.py b/gitlab_docker_autodep/server.py index bbc3206..ffc0351 100644 --- a/gitlab_docker_autodep/server.py +++ b/gitlab_docker_autodep/server.py @@ -1,9 +1,5 @@ -import gitlab -import json import logging -import os import threading -import time try: import Queue except ImportError: @@ -15,40 +11,6 @@ from flask import Flask, request, make_response, abort from .rebuild import rebuild -class _ReloadableJSONFile(object): - - check_interval = 60 - - def __init__(self, path): - self.path = path - self.lock = threading.Lock() - self._load() - t = threading.Thread( - target=self._update_thread, - name='File reload thread for %s' % path) - t.setDaemon(True) - t.start() - - def get_contents(self): - with self.lock: - return self.data - - def _load(self): - with self.lock: - with open(self.path) as fd: - self.data = json.load(fd) - self.stamp = os.stat(self.path).st_mtime - - def _update_thread(self): - while True: - time.sleep(self.check_interval) - try: - if os.stat(self.path).st_mtime > self.stamp: - self._load() - except: - pass - - queue = Queue.Queue() @@ -75,11 +37,7 @@ def _process_request(gl, project_deps, data): path_with_namespace, branch, pipeline_status, action) -def worker_thread(gitlab_url, gitlab_token, project_deps): - gl = gitlab.Gitlab(gitlab_url, private_token=gitlab_token) - if gitlab_token: - gl.auth() - +def worker_thread(gl, project_deps): while True: data = queue.get() try: @@ -91,21 +49,18 @@ def worker_thread(gitlab_url, gitlab_token, project_deps): app = Flask(__name__) -def run_app(gitlab_url, gitlab_token, - project_deps_path, bind_host, bind_port, +def run_app(gl, project_deps, bind_host, bind_port, webhook_token, num_workers=3): app.config.update({ 'WEBHOOK_AUTH_TOKEN': webhook_token, }) - project_deps = _ReloadableJSONFile(project_deps_path) - # Start the worker threads that will process the requests in the # background. for i in range(num_workers): wt = threading.Thread( target=worker_thread, - args=(gitlab_url, gitlab_token, project_deps), + args=(gl, project_deps), name='Worker %d' % (i+1)) wt.setDaemon(True) wt.start() -- GitLab