mirror of https://github.com/jumpserver/jumpserver
feat: 优化job execution 详情字段
parent
54f720e992
commit
d8cccfd40f
|
@ -99,14 +99,11 @@ class JobExecution(JMSOrgBaseModel):
|
|||
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
|
||||
|
||||
@property
|
||||
def count(self):
|
||||
if self.is_finished and not self.summary.get('error', None):
|
||||
return {
|
||||
"ok": len(self.summary['ok']),
|
||||
"failed": len(self.summary['failures']) + len(self.summary['dark']),
|
||||
"excludes": len(self.summary.get('excludes', {})),
|
||||
"total": self.job.assets.count()
|
||||
}
|
||||
def material(self):
|
||||
if self.job.type == 'adhoc':
|
||||
return "{}:{}".format(self.job.module, self.job.args)
|
||||
if self.job.type == 'playbook':
|
||||
return "{}:{}:{}".format(self.org.name, self.job.creator.name, self.job.playbook.name)
|
||||
|
||||
@property
|
||||
def assent_result_detail(self):
|
||||
|
@ -160,9 +157,10 @@ class JobExecution(JMSOrgBaseModel):
|
|||
def get_runner(self):
|
||||
inv = self.job.inventory
|
||||
inv.write_to_file(self.inventory_path)
|
||||
self.summary = self.result = {"excludes": {}}
|
||||
if len(inv.exclude_hosts) > 0:
|
||||
self.summary['excludes'] = inv.exclude_hosts
|
||||
self.result['excludes'] = inv.exclude_hosts
|
||||
self.summary.update({"excludes": inv.exclude_hosts})
|
||||
self.result.update({"excludes": inv.exclude_hosts})
|
||||
self.save()
|
||||
|
||||
if isinstance(self.parameters, str):
|
||||
|
|
|
@ -30,14 +30,14 @@ class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
|||
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
||||
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
||||
job_type = serializers.ReadOnlyField(label=_("Job type"))
|
||||
count = serializers.ReadOnlyField(label=_("Count"))
|
||||
material = serializers.ReadOnlyField(label=_("Material"))
|
||||
|
||||
class Meta:
|
||||
model = JobExecution
|
||||
read_only_fields = ["id", "task_id", "timedelta", "count", "time_cost", 'is_finished', 'date_start',
|
||||
read_only_fields = ["id", "task_id", "timedelta", "time_cost", 'is_finished', 'date_start',
|
||||
'date_finished',
|
||||
'date_created',
|
||||
'is_success', 'task_id', 'short_id', 'job_type']
|
||||
'is_success', 'task_id', 'short_id', 'job_type', 'summary', 'material']
|
||||
fields = read_only_fields + [
|
||||
"job", "parameters", "creator"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue