mirror of https://github.com/jumpserver/jumpserver
perf: 优化celery任务
parent
6d0545f04f
commit
2f5e133558
|
@ -71,5 +71,9 @@ class CeleryTaskExecution(models.Model):
|
|||
return self.date_finished - self.date_start
|
||||
return None
|
||||
|
||||
@property
|
||||
def is_success(self):
|
||||
return self.state == 'SUCCESS'
|
||||
|
||||
def __str__(self):
|
||||
return "{}: {}".format(self.name, self.id)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# ~*~ coding: utf-8 ~*~
|
||||
from __future__ import unicode_literals
|
||||
from rest_framework import serializers
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from django_celery_beat.models import PeriodicTask
|
||||
|
||||
|
@ -35,10 +36,12 @@ class CeleryTaskSerializer(serializers.ModelSerializer):
|
|||
|
||||
|
||||
class CeleryTaskExecutionSerializer(serializers.ModelSerializer):
|
||||
is_success = serializers.BooleanField(required=False, read_only=True, label=_('Success'))
|
||||
|
||||
class Meta:
|
||||
model = CeleryTaskExecution
|
||||
fields = [
|
||||
"id", "name", "args", "kwargs", "time_cost", "timedelta", "state", "is_finished", "date_published",
|
||||
"id", "name", "args", "kwargs", "time_cost", "timedelta", "is_success", "is_finished", "date_published",
|
||||
"date_start",
|
||||
"date_finished"
|
||||
]
|
||||
|
|
|
@ -8,11 +8,12 @@ from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
|||
|
||||
class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
||||
owner = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
||||
run_after_save = serializers.BooleanField(label=_("Run after save"), default=False, required=False)
|
||||
run_after_save = serializers.BooleanField(label=_("Run after save"), read_only=True, default=False, required=False)
|
||||
|
||||
class Meta:
|
||||
model = Job
|
||||
read_only_fields = ["id", "date_last_run", "date_created", "date_updated", "average_time_cost"]
|
||||
read_only_fields = ["id", "date_last_run", "date_created", "date_updated", "average_time_cost",
|
||||
"run_after_save"]
|
||||
fields = read_only_fields + [
|
||||
"name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "owner",
|
||||
"use_parameter_define",
|
||||
|
@ -21,7 +22,7 @@ class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
|||
"chdir",
|
||||
"comment",
|
||||
"summary",
|
||||
"is_periodic", "interval", "crontab", "run_after_save"
|
||||
"is_periodic", "interval", "crontab"
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue