events: set task start time before start not on init (#4908)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
parent
7618c2e45f
commit
10b7d78825
|
@ -111,6 +111,7 @@ class MonitoredTask(Task):
|
||||||
_result: Optional[TaskResult]
|
_result: Optional[TaskResult]
|
||||||
|
|
||||||
_uid: Optional[str]
|
_uid: Optional[str]
|
||||||
|
start: Optional[float] = None
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs) -> None:
|
def __init__(self, *args, **kwargs) -> None:
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
@ -118,7 +119,6 @@ class MonitoredTask(Task):
|
||||||
self._uid = None
|
self._uid = None
|
||||||
self._result = None
|
self._result = None
|
||||||
self.result_timeout_hours = 6
|
self.result_timeout_hours = 6
|
||||||
self.start = default_timer()
|
|
||||||
|
|
||||||
def set_uid(self, uid: str):
|
def set_uid(self, uid: str):
|
||||||
"""Set UID, so in the case of an unexpected error its saved correctly"""
|
"""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."""
|
"""Set result for current run, will overwrite previous result."""
|
||||||
self._result = 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
|
# pylint: disable=too-many-arguments
|
||||||
def after_return(self, status, retval, task_id, args: list[Any], kwargs: dict[str, Any], einfo):
|
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)
|
super().after_return(status, retval, task_id, args, kwargs, einfo=einfo)
|
||||||
|
@ -138,7 +142,7 @@ class MonitoredTask(Task):
|
||||||
info = TaskInfo(
|
info = TaskInfo(
|
||||||
task_name=self.__name__,
|
task_name=self.__name__,
|
||||||
task_description=self.__doc__,
|
task_description=self.__doc__,
|
||||||
start_timestamp=self.start,
|
start_timestamp=self.start or default_timer(),
|
||||||
finish_timestamp=default_timer(),
|
finish_timestamp=default_timer(),
|
||||||
finish_time=datetime.now(),
|
finish_time=datetime.now(),
|
||||||
result=self._result,
|
result=self._result,
|
||||||
|
@ -162,7 +166,7 @@ class MonitoredTask(Task):
|
||||||
TaskInfo(
|
TaskInfo(
|
||||||
task_name=self.__name__,
|
task_name=self.__name__,
|
||||||
task_description=self.__doc__,
|
task_description=self.__doc__,
|
||||||
start_timestamp=self.start,
|
start_timestamp=self.start or default_timer(),
|
||||||
finish_timestamp=default_timer(),
|
finish_timestamp=default_timer(),
|
||||||
finish_time=datetime.now(),
|
finish_time=datetime.now(),
|
||||||
result=self._result,
|
result=self._result,
|
||||||
|
|
|
@ -88,7 +88,7 @@ export class SystemTaskListPage extends TablePage<Task> {
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="pf-c-description-list__description">
|
<dd class="pf-c-description-list__description">
|
||||||
<div class="pf-c-description-list__text">
|
<div class="pf-c-description-list__text">
|
||||||
${t`${Math.round(item.taskDuration)} seconds`}
|
${t`${item.taskDuration.toFixed(2)} seconds`}
|
||||||
</div>
|
</div>
|
||||||
</dd>
|
</dd>
|
||||||
</div>
|
</div>
|
||||||
|
|
Reference in New Issue