Add make thread

This commit is contained in:
Théophile Bastian 2018-03-03 02:13:35 +01:00
parent 46178f0169
commit 1b7d0fa8b2

View file

@ -3,7 +3,9 @@
A webhook-handler for Gogs running `make` when needed. """
import os
import sys
import subprocess
from threading import Thread
from functools import wraps
from flask import Flask, request
from . import settings
@ -37,6 +39,25 @@ def repo_path(hook):
return os.path.join(settings.CLONE_ROOT, hook['name'])
class MakeWorker(Thread):
''' A make job '''
def __init__(self, hook):
super().__init__()
self.hook = hook
self.name = 'makeworker-{}'.format(hook['name'])
self.path = repo_path(hook)
def run(self):
''' Run the make job '''
try:
subprocess.run(['make', '-C', self.path, '--']
+ self.hook['targets'])
except subprocess.CalledProcessError:
print('Hook {}: failed to make'.format(self.hook['name']),
file=sys.stderr)
def update_repo(hook, clone_url):
''' Update (or clone) the given repository. May raise GitError. '''
path = repo_path(hook)
@ -98,6 +119,10 @@ def view_root(payload, hook):
except GitError as error:
return 'Git error: {}\n'.format(error), 500
# TODO: make
worker = MakeWorker(hook)
worker.start()
return 'OK\n', 200
# TODO: @app.before_first_request settings checkup