Git Lab CI for docker build enabled! You can enable it using .gitlab-ci.yml in your project. Check file template at https://gitlab.bio.di.uminho.pt/snippets/5

Commit 3f0c2d0d authored by Davide Lagoa's avatar Davide Lagoa
Browse files

adapted to merlin plugin

parent 35c4f19d
...@@ -4,9 +4,27 @@ import os ...@@ -4,9 +4,27 @@ import os
import shutil import shutil
import datetime import datetime
import FilesUtilities import FilesUtilities
import logging
from logging.handlers import TimedRotatingFileHandler
app = Flask(__name__) app = Flask(__name__)
logPath = '/workdir/logs/workerlogs'
if not os.path.exists(logPath):
os.makedirs(logPath)
# format the log entries
formatter = logging.Formatter('%(asctime)s %(name)s %(levelname)s %(message)s')
handler = TimedRotatingFileHandler(logPath + '/worker.log', when='midnight', backupCount=20)
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
#####
PROCESS_PATH = '/home/transyt.py' PROCESS_PATH = '/home/transyt.py'
SUBMISSIONS_PATH = '/workdir/workerSubmissions/' SUBMISSIONS_PATH = '/workdir/workerSubmissions/'
RESULTS_PATH = '/workdir/resultsWorker/' RESULTS_PATH = '/workdir/resultsWorker/'
...@@ -22,6 +40,8 @@ start_time = datetime.datetime.now() ...@@ -22,6 +40,8 @@ start_time = datetime.datetime.now()
running = False running = False
logging.info("worker running...")
@app.after_request @app.after_request
def after_request(response): def after_request(response):
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, public, max-age=0" response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate, public, max-age=0"
...@@ -34,6 +54,8 @@ def start(): ...@@ -34,6 +54,8 @@ def start():
global start_time global start_time
global running global running
logger.info("Submission in progress...")
start_time = datetime.datetime.now() start_time = datetime.datetime.now()
if os.path.exists(SUBMISSIONS_PATH): if os.path.exists(SUBMISSIONS_PATH):
...@@ -45,19 +67,24 @@ def start(): ...@@ -45,19 +67,24 @@ def start():
os.makedirs(SUBMISSIONS_PATH) os.makedirs(SUBMISSIONS_PATH)
os.makedirs(RESULTS_PATH) os.makedirs(RESULTS_PATH)
logger.debug("directories reset complete")
try: try:
for file in request.files.values(): for file in request.files.values():
destination = "/".join([SUBMISSIONS_PATH, file.filename]) destination = "/".join([SUBMISSIONS_PATH, file.filename])
logger.info("saving file " + destination)
file.save(destination) file.save(destination)
subprocess.Popen(["python", PROCESS_PATH, SUBMISSIONS_PATH, RESULTS_PATH]) subprocess.Popen(["python", PROCESS_PATH, SUBMISSIONS_PATH, RESULTS_PATH])
running = True running = True
logger.info("returning code 102!")
return ('processing', 102) return ('processing', 102)
except IndexError: except IndexError:
print('An error occurred while processing the submission') logger.info('An error occurred while processing the submission, returning code 500!')
return ('error', 500) return ('error', 500)
...@@ -80,6 +107,7 @@ def display_msg(): ...@@ -80,6 +107,7 @@ def display_msg():
@app.route('/handshake') @app.route('/handshake')
def handshake(): def handshake():
logger.info("handshake requested!")
return jsonify({"result": "alive"}), 200 return jsonify({"result": "alive"}), 200
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment