Commit 960d4912 authored by Lionel Walter's avatar Lionel Walter
Browse files

Start job reporting in a separate thread

parent ba0883b5
......@@ -12,6 +12,8 @@ from import_api_app.resources.WriteJobResultsToDrupal import write_results
from kubernetes import client
from threading import Thread
import requests
......@@ -100,26 +102,40 @@ class JobStart(Resource):
return {'error': e.message}, 500
try:
start(process_id, job_name, job_parameters)
helm_result = start(process_id, job_name, job_parameters)
except ImportApiError as e:
return {'error': e.message}, 500
# wait before consuming results
time.sleep(3)
FlaskThread(target=reporting, args=(
job_reporting_topic,
job_parameters['drupalJobLogResultUuid']
)).start()
try:
report = get_report(job_reporting_topic)
except ImportApiError as e:
return {'error': e.message}, 500
return helm_result
# write report
# todo check if drupalJobLogResultUuid is defined
try:
write_results(job_parameters['drupalJobLogResultUuid'], report["report"])
except ImportApiError as e:
return {'error': e.message}, 500
return {
'status': 'SUCCESS',
'message': report["report"],
}, 201
class FlaskThread(Thread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.app = current_app._get_current_object()
def run(self):
with self.app.app_context():
super().run()
def reporting(job_reporting_topic, drupal_job_log_uuid):
# wait a bit before consuming results
time.sleep(3)
try:
report = get_report(job_reporting_topic)
except ImportApiError as e:
return {'error': e.message}, 500
# write report
# todo check if drupalJobLogResultUuid is defined
try:
write_results(drupal_job_log_uuid, report["report"])
except ImportApiError as e:
return {'error': e.message}, 500
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