2022-12-02 04:21:56 +00:00
|
|
|
from django.utils.translation import ugettext as _
|
2022-11-11 11:20:17 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
from common.drf.fields import ReadableHiddenField
|
2022-11-18 10:46:48 +00:00
|
|
|
from ops.mixin import PeriodTaskSerializerMixin
|
2022-11-11 11:20:17 +00:00
|
|
|
from ops.models import Job, JobExecution
|
2022-12-16 07:52:02 +00:00
|
|
|
from ops.models.job import JobAuditLog
|
2022-12-15 09:25:21 +00:00
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2022-11-11 11:20:17 +00:00
|
|
|
|
|
|
|
|
2022-12-15 09:25:21 +00:00
|
|
|
class JobSerializer(BulkOrgResourceModelSerializer, PeriodTaskSerializerMixin):
|
2022-12-06 03:03:14 +00:00
|
|
|
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
2022-12-02 09:18:11 +00:00
|
|
|
run_after_save = serializers.BooleanField(label=_("Run after save"), read_only=True, default=False, required=False)
|
2022-11-11 11:20:17 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Job
|
2022-12-02 09:18:11 +00:00
|
|
|
read_only_fields = ["id", "date_last_run", "date_created", "date_updated", "average_time_cost",
|
|
|
|
"run_after_save"]
|
2022-11-18 10:46:48 +00:00
|
|
|
fields = read_only_fields + [
|
2022-12-06 03:03:14 +00:00
|
|
|
"name", "instant", "type", "module", "args", "playbook", "assets", "runas_policy", "runas", "creator",
|
2022-11-29 11:44:12 +00:00
|
|
|
"use_parameter_define",
|
2022-11-17 12:10:13 +00:00
|
|
|
"parameters_define",
|
2022-11-16 13:06:14 +00:00
|
|
|
"timeout",
|
|
|
|
"chdir",
|
|
|
|
"comment",
|
2022-11-18 10:46:48 +00:00
|
|
|
"summary",
|
2022-12-02 09:18:11 +00:00
|
|
|
"is_periodic", "interval", "crontab"
|
2022-11-11 11:20:17 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-12-15 09:25:21 +00:00
|
|
|
class JobExecutionSerializer(BulkOrgResourceModelSerializer):
|
2022-12-06 03:03:14 +00:00
|
|
|
creator = ReadableHiddenField(default=serializers.CurrentUserDefault())
|
2022-12-06 11:43:32 +00:00
|
|
|
job_type = serializers.ReadOnlyField(label=_("Job type"))
|
2022-12-07 12:13:26 +00:00
|
|
|
count = serializers.ReadOnlyField(label=_("Count"))
|
2022-12-06 03:03:14 +00:00
|
|
|
|
2022-11-11 11:20:17 +00:00
|
|
|
class Meta:
|
|
|
|
model = JobExecution
|
2022-12-07 12:13:26 +00:00
|
|
|
read_only_fields = ["id", "task_id", "timedelta", "count", "time_cost", 'is_finished', 'date_start',
|
|
|
|
'date_finished',
|
|
|
|
'date_created',
|
2022-12-16 10:39:59 +00:00
|
|
|
'is_success', 'task_id', 'short_id', 'job_type']
|
2022-11-11 11:20:17 +00:00
|
|
|
fields = read_only_fields + [
|
2022-12-16 10:39:59 +00:00
|
|
|
"job", "parameters", "creator"
|
2022-11-11 11:20:17 +00:00
|
|
|
]
|