Add make thread
This commit is contained in:
parent
46178f0169
commit
1b7d0fa8b2
1 changed files with 26 additions and 1 deletions
27
gogsmaker.py
27
gogsmaker.py
|
@ -3,7 +3,9 @@
|
||||||
A webhook-handler for Gogs running `make` when needed. """
|
A webhook-handler for Gogs running `make` when needed. """
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from threading import Thread
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from flask import Flask, request
|
from flask import Flask, request
|
||||||
from . import settings
|
from . import settings
|
||||||
|
@ -37,6 +39,25 @@ def repo_path(hook):
|
||||||
return os.path.join(settings.CLONE_ROOT, hook['name'])
|
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):
|
def update_repo(hook, clone_url):
|
||||||
''' Update (or clone) the given repository. May raise GitError. '''
|
''' Update (or clone) the given repository. May raise GitError. '''
|
||||||
path = repo_path(hook)
|
path = repo_path(hook)
|
||||||
|
@ -98,6 +119,10 @@ def view_root(payload, hook):
|
||||||
except GitError as error:
|
except GitError as error:
|
||||||
return 'Git error: {}\n'.format(error), 500
|
return 'Git error: {}\n'.format(error), 500
|
||||||
|
|
||||||
# TODO: make
|
worker = MakeWorker(hook)
|
||||||
|
worker.start()
|
||||||
|
|
||||||
return 'OK\n', 200
|
return 'OK\n', 200
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: @app.before_first_request settings checkup
|
||||||
|
|
Loading…
Reference in a new issue