events: set task start time before start not on init (#4908)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-03-12 15:13:04 +01:00 committed by GitHub
parent 7618c2e45f
commit 10b7d78825
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -111,6 +111,7 @@ class MonitoredTask(Task):
_result: Optional[TaskResult]
_uid: Optional[str]
start: Optional[float] = None
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
@ -118,7 +119,6 @@ class MonitoredTask(Task):
self._uid = None
self._result = None
self.result_timeout_hours = 6
self.start = default_timer()
def set_uid(self, uid: str):
"""Set UID, so in the case of an unexpected error its saved correctly"""
@ -128,6 +128,10 @@ class MonitoredTask(Task):
"""Set result for current run, will overwrite previous result."""
self._result = result
def before_start(self, task_id, args, kwargs):
self.start = default_timer()
return super().before_start(task_id, args, kwargs)
# pylint: disable=too-many-arguments
def after_return(self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo):
super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
@ -138,7 +142,7 @@ class MonitoredTask(Task):
info = TaskInfo(
task_name=self.__name__,
task_description=self.__doc__,
start_timestamp=self.start,
start_timestamp=self.start or default_timer(),
finish_timestamp=default_timer(),
finish_time=datetime.now(),
result=self._result,
@ -162,7 +166,7 @@ class MonitoredTask(Task):
TaskInfo(
task_name=self.__name__,
task_description=self.__doc__,
start_timestamp=self.start,
start_timestamp=self.start or default_timer(),
finish_timestamp=default_timer(),
finish_time=datetime.now(),
result=self._result,

View File

@ -88,7 +88,7 @@ export class SystemTaskListPage extends TablePage<Task> {
</dt>
<dd class="pf-c-description-list__description">
<div class="pf-c-description-list__text">
${t`${Math.round(item.taskDuration)} seconds`}
${t`${item.taskDuration.toFixed(2)} seconds`}
</div>
</dd>
</div>