From d8cccfd40ff021ef96c602454905357a5030194e Mon Sep 17 00:00:00 2001 From: Aaron3S Date: Tue, 20 Dec 2022 16:36:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96job=20execution=20?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/models/job.py | 18 ++++++++---------- apps/ops/serializers/job.py | 6 +++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/apps/ops/models/job.py b/apps/ops/models/job.py index d8a70d55e..4f003895e 100644 --- a/apps/ops/models/job.py +++ b/apps/ops/models/job.py @@ -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): diff --git a/apps/ops/serializers/job.py b/apps/ops/serializers/job.py index 81f77b915..005b88cdc 100644 --- a/apps/ops/serializers/job.py +++ b/apps/ops/serializers/job.py @@ -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" ]