Skip to content
Snippets Groups Projects
Commit ec4523cd authored by ale's avatar ale
Browse files

Fix the server to use plain text dependencies as input

parent d4175d13
No related branches found
No related tags found
1 merge request!1Modular
......@@ -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__':
......
......@@ -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, []))
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment