perf: modify average_time_cost calculation in job model

pull/14813/head
wangruidong 2024-11-19 14:21:49 +08:00 committed by Bryan
parent c088437fe5
commit 543dde57ab
1 changed files with 1 additions and 5 deletions

View File

@ -188,11 +188,7 @@ class Job(JMSOrgBaseModel, PeriodTaskModelMixin):
@property @property
def average_time_cost(self): def average_time_cost(self):
total_cost = 0 return self.last_execution.time_cost if self.last_execution else 0
finished_count = self.executions.filter(status__in=['success', 'failed']).count()
for execution in self.executions.filter(status__in=['success', 'failed']).all():
total_cost += execution.time_cost
return total_cost / finished_count if finished_count else 0
def get_register_task(self): def get_register_task(self):
from ..tasks import run_ops_job from ..tasks import run_ops_job