Commit 80becf13 authored by Floreal Cabanettes's avatar Floreal Cabanettes
Browse files

Improve analytics: add failed jobs

parent d51d5daa
......@@ -128,11 +128,13 @@ if MODE == "webserver":
if config.analytics_enabled:
class Analytics(BaseModel):
id_job = CharField(max_length=50, default="unknown")
date_created = DateTimeField()
target_size = IntegerField()
query_size = IntegerField(null=True)
mail_client = CharField()
batch_type = CharField(max_length=20)
status = CharField(max_length=20, default="unknown")
if not Analytics.table_exists():
Analytics.create_table()
......
......@@ -1075,6 +1075,8 @@ class JobManager:
def prepare_data_local(self):
"""
Prepare data locally. On standalone mode, launch job after, if success.
:return: True if job succeed, else False
:rtype: bool
"""
with open(self.preptime_file, "w") as ptime, Job.connect():
self.set_job_status("preparing")
......@@ -1154,6 +1156,7 @@ class JobManager:
self.set_job_status("prepared")
if MODE != "webserver":
self.run_job("local")
return True
def _end_of_prepare_dotplot(self):
"""
......@@ -1269,9 +1272,11 @@ class JobManager:
with Job.connect():
job = Job.get(Job.id_job == self.id_job)
if job.batch_type == "local":
self.prepare_data_local()
success = self.prepare_data_local()
else:
self.prepare_data_cluster(job.batch_type)
success = self.prepare_data_cluster(job.batch_type)
if not success:
self._set_analytics_job_status("fail-prepare")
else:
self.prepare_data_local()
else:
......@@ -1360,6 +1365,7 @@ class JobManager:
job = Job.get(Job.id_job == self.id_job)
job.status = status
job.error = error
self._set_analytics_job_status("fail-sort")
else:
self.set_status_standalone(status, error)
if success:
......@@ -1368,14 +1374,22 @@ class JobManager:
job = Job.get(Job.id_job == self.id_job)
job.status = "success"
job.save()
# Analytics:
self._set_analytics_job_status("success")
if self.config.send_mail_status:
self.send_mail_post()
else:
self.set_status_standalone(status)
elif MODE == "webserver":
self._set_analytics_job_status("fail-map")
except Exception as e:
traceback.print_exc()
self.set_job_status("fail", "Your job has failed for an unexpected reason. Please contact the support if"
"the problem persists.")
if MODE == "webserver" and self.config.send_mail_status:
self.send_mail_post()
if MODE == "webserver":
self._set_analytics_job_status("fail-map-after")
def _save_analytics_data(self):
"""
......@@ -1389,6 +1403,7 @@ class JobManager:
if self.query is not None:
query_size = os.path.getsize(self.query.get_path())
log = Analytics.create(
id_job=self.id_job,
date_created=datetime.now(),
target_size=target_size,
query_size=query_size,
......@@ -1396,6 +1411,14 @@ class JobManager:
batch_type=job.batch_type)
log.save()
def _set_analytics_job_status(self, status):
if self.config.analytics_enabled:
from dgenies.database import Analytics
with Job.connect():
analytic = Analytics.get(Analytics.id_job == self.id_job)
analytic.status = status
analytic.save()
def unpack_backup(self):
"""
Untar backup file
......@@ -1443,6 +1466,8 @@ class JobManager:
:type error_set: bool
"""
with Job.connect():
if self.config.analytics_enabled:
self._save_analytics_data()
if success:
if self.backup is not None:
success = self.unpack_backup()
......@@ -1457,12 +1482,11 @@ class JobManager:
job = Job.get(Job.id_job == self.id_job)
job.status = status
job.save()
if self.config.analytics_enabled:
self._save_analytics_data()
else:
self.set_status_standalone(status)
self.prepare_data_in_thread()
else:
self._set_analytics_job_status("fail-getfiles")
if not error_set:
status = "fail"
error = "<p>Error while getting input files. Please contact the support to report the bug.</p>"
......
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