diff --git a/authentik/events/monitored_tasks.py b/authentik/events/monitored_tasks.py index 3b7987e90..6f246f8a5 100644 --- a/authentik/events/monitored_tasks.py +++ b/authentik/events/monitored_tasks.py @@ -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, diff --git a/web/src/admin/system-tasks/SystemTaskListPage.ts b/web/src/admin/system-tasks/SystemTaskListPage.ts index c2f18809a..fc36de27b 100644 --- a/web/src/admin/system-tasks/SystemTaskListPage.ts +++ b/web/src/admin/system-tasks/SystemTaskListPage.ts @@ -88,7 +88,7 @@ export class SystemTaskListPage extends TablePage {
- ${t`${Math.round(item.taskDuration)} seconds`} + ${t`${item.taskDuration.toFixed(2)} seconds`}