From d0fac3f83829b60cdf5bef6f0876512902a56c7e Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 18 Mar 2020 19:58:08 +0800 Subject: [PATCH] =?UTF-8?q?[Bugfix]=20=E4=BF=AE=E5=A4=8Dtask=20=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/models/adhoc.py | 1 + apps/ops/serializers/adhoc.py | 5 +++-- apps/ops/templates/ops/task_list.html | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/ops/models/adhoc.py b/apps/ops/models/adhoc.py index faa3ac01f..c29493fb2 100644 --- a/apps/ops/models/adhoc.py +++ b/apps/ops/models/adhoc.py @@ -182,6 +182,7 @@ class AdHoc(OrgModelMixin): id=hid, adhoc=self, task=self.task, task_display=str(self.task), date_start=timezone.now(), + hosts_amount=self.hosts.count(), ) execution.save() return execution.start() diff --git a/apps/ops/serializers/adhoc.py b/apps/ops/serializers/adhoc.py index 60fd39f90..afdd659fc 100644 --- a/apps/ops/serializers/adhoc.py +++ b/apps/ops/serializers/adhoc.py @@ -39,6 +39,7 @@ class AdHocExecutionExcludeResultSerializer(AdHocExecutionSerializer): class TaskSerializer(serializers.ModelSerializer): + summary = serializers.ReadOnlyField(source='history_summary') latest_execution = AdHocExecutionExcludeResultSerializer(read_only=True) class Meta: @@ -46,12 +47,12 @@ class TaskSerializer(serializers.ModelSerializer): fields = [ 'id', 'name', 'interval', 'crontab', 'is_periodic', 'is_deleted', 'comment', 'date_created', - 'date_updated', 'latest_execution', + 'date_updated', 'latest_execution', 'summary', ] read_only_fields = [ 'is_deleted', 'date_created', 'date_updated', 'latest_adhoc', 'latest_execution', 'total_run_amount', - 'success_run_amount', + 'success_run_amount', 'summary', ] diff --git a/apps/ops/templates/ops/task_list.html b/apps/ops/templates/ops/task_list.html index 6f393cb1c..a004138df 100644 --- a/apps/ops/templates/ops/task_list.html +++ b/apps/ops/templates/ops/task_list.html @@ -35,7 +35,7 @@ $(document).ready(function () { $(td).html(innerHtml); }}, {targets: 2, createdCell: function (td, cellData) { - var summary = cellData ? cellData.stat : {failed: 0, success: 0, total: 0}; + var summary = cellData || {failed: 0, success: 0, total: 0}; var innerHtml = 'failed/success/total'; innerHtml = innerHtml.replace('failed', summary.failed) .replace('success', summary.success) @@ -79,7 +79,7 @@ $(document).ready(function () { ajax_url: '{% url "api-ops:task-list" %}', columns: [ {data: "id"}, {data: "name", className: "text-left"}, - {data: "latest_execution", orderable: false}, + {data: "summary", orderable: false}, {data: "latest_execution", orderable: false}, {data: "latest_execution", orderable: false}, {data: "latest_execution"}, {data: "latest_execution", orderable:false}, {data: "id", orderable: false},