diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py index 0444c4f8b6e625a2e135840e50ba3e67e5745d56..9a08e262b1227d25bfde5efb95f3af24666f5cea 100644 --- a/atdb/taskdatabase/models.py +++ b/atdb/taskdatabase/models.py @@ -4,6 +4,9 @@ from django.utils import timezone from django.utils.timezone import datetime, timedelta from django.conf import settings +import logging +logger = logging.getLogger(__name__) + # constants datetime_format_string = '%Y-%m-%dT%H:%M:%SZ' @@ -228,6 +231,41 @@ class LogEntry(models.Model): def __str__(self): return str(self.id)+ ' - '+ str(self.task)+' - '+self.status + def save(self, *args, **kwargs): + #override save to check how long this task has been in this state. + try: + + # if this logentry already has a wall_clock_time, then don't change it. + if not self.wall_clock_time: + + # gather all entries for this task, to discover the previous one. + entries_for_this_task = LogEntry.objects.filter(task=self.task).order_by("-timestamp") + # remove entries from the list, including 'this', so that the latest remaining is the previous entry. + for entry in entries_for_this_task: + entries_for_this_task = entries_for_this_task.exclude(id=entry.id) + if entry == self: + break + + try: + latest_entry_before_self = entries_for_this_task.latest('timestamp') + previous_timestamp = latest_entry_before_self.timestamp + except: + # if no previous entry exists, then use the timestamp from the task. + previous_timestamp = self.task.creationTime + + dt = (self.timestamp - previous_timestamp).seconds + message = "logentry for task "+str(self.task.id)+", to "+self.status + " took " + str(dt) + " seconds" + logger.info(message) + + self.wall_clock_time = dt + except Exception as e: + print(e) + + finally: + # finally save the Monitor info itself also + super(LogEntry, self).save(*args, **kwargs) + + class Status(models.Model): name = models.CharField(max_length=50, default="unknown") diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py index 482bfd614020bbae2bcfaaa53d2f2491246e121d..917f3dae2feca9cf42359795ef12fe3bf38eaaef 100644 --- a/atdb/taskdatabase/services/algorithms.py +++ b/atdb/taskdatabase/services/algorithms.py @@ -608,7 +608,7 @@ def construct_logs_per_workflow_html_version1(log_records): def construct_logs_per_workflow_html(request, workflow_results): - results = "<p>Resources used per step per workflow: <b>cpu_cycles/wall_clock_time</b></p>" + results = "<p>Resources used per step per workflow: <b>cpu_cycles/wall_clock_time (seconds)</b></p>" # construct the header header = "<th>Workflow</th>" diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 47e4181d7741fa944d14aefffec72b103fe79f05..b463486bf50b8396799d6d4b14508b14893fd602 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 23 December 2022 - 8:00 + <p class="footer"> Version 10 Januari 2022 - 15:00 </div>