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"))
|
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def count(self):
|
def material(self):
|
||||||
if self.is_finished and not self.summary.get('error', None):
|
if self.job.type == 'adhoc':
|
||||||
return {
|
return "{}:{}".format(self.job.module, self.job.args)
|
||||||
"ok": len(self.summary['ok']),
|
if self.job.type == 'playbook':
|
||||||
"failed": len(self.summary['failures']) + len(self.summary['dark']),
|
return "{}:{}:{}".format(self.org.name, self.job.creator.name, self.job.playbook.name)
|
||||||
"excludes": len(self.summary.get('excludes', {})),
|
|
||||||
"total": self.job.assets.count()
|
|
||||||
}
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def assent_result_detail(self):
|
def assent_result_detail(self):
|
||||||
|
@ -160,9 +157,10 @@ class JobExecution(JMSOrgBaseModel):
|
||||||
def get_runner(self):
|
def get_runner(self):
|
||||||
inv = self.job.inventory
|
inv = self.job.inventory
|
||||||
inv.write_to_file(self.inventory_path)
|
inv.write_to_file(self.inventory_path)
|
||||||
|
self.summary = self.result = {"excludes": {}}
|
||||||
if len(inv.exclude_hosts) > 0:
|
if len(inv.exclude_hosts) > 0:
|
||||||
self.summary['excludes'] = inv.exclude_hosts
|
self.summary.update({"excludes": inv.exclude_hosts})
|
||||||
self.result['excludes'] = inv.exclude_hosts
|
self.result.update({"excludes": inv.exclude_hosts})
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
if isinstance(self.parameters, str):
|
if isinstance(self.parameters, str):
|
||||||
|
|
|
@ -30,14 +30,14 @@ class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
||||||
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
||||||
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
||||||
job_type = serializers.ReadOnlyField(label=_("Job type"))
|
job_type = serializers.ReadOnlyField(label=_("Job type"))
|
||||||
count = serializers.ReadOnlyField(label=_("Count"))
|
material = serializers.ReadOnlyField(label=_("Material"))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = JobExecution
|
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_finished',
|
||||||
'date_created',
|
'date_created',
|
||||||
'is_success', 'task_id', 'short_id', 'job_type']
|
'is_success', 'task_id', 'short_id', 'job_type', 'summary', 'material']
|
||||||
fields = read_only_fields + [
|
fields = read_only_fields + [
|
||||||
"job", "parameters", "creator"
|
"job", "parameters", "creator"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue