2019-12-05 07:09:25 +00:00
|
|
|
# ~*~ coding: utf-8 ~*~
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from rest_framework import serializers
|
2022-12-02 09:18:11 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
from django_celery_beat.models import PeriodicTask
|
|
|
|
|
|
|
|
__all__ = [
|
2022-10-24 12:14:18 +00:00
|
|
|
'CeleryResultSerializer', 'CeleryTaskExecutionSerializer',
|
|
|
|
'CeleryPeriodTaskSerializer', 'CeleryTaskSerializer'
|
2019-12-05 07:09:25 +00:00
|
|
|
]
|
|
|
|
|
2022-10-24 12:14:18 +00:00
|
|
|
from ops.models import CeleryTask, CeleryTaskExecution
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
class CeleryResultSerializer(serializers.Serializer):
|
|
|
|
id = serializers.UUIDField()
|
|
|
|
result = serializers.JSONField()
|
|
|
|
state = serializers.CharField(max_length=16)
|
|
|
|
|
|
|
|
|
|
|
|
class CeleryPeriodTaskSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = PeriodicTask
|
|
|
|
fields = [
|
|
|
|
'name', 'task', 'enabled', 'description',
|
|
|
|
'last_run_at', 'total_run_count'
|
|
|
|
]
|
2022-10-24 12:14:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CeleryTaskSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = CeleryTask
|
2022-11-16 07:04:46 +00:00
|
|
|
read_only_fields = ['id', 'name', 'meta', 'summary', 'state', 'last_published_time']
|
|
|
|
fields = read_only_fields
|
2022-10-24 12:14:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CeleryTaskExecutionSerializer(serializers.ModelSerializer):
|
2022-12-02 09:18:11 +00:00
|
|
|
is_success = serializers.BooleanField(required=False, read_only=True, label=_('Success'))
|
|
|
|
|
2022-10-24 12:14:18 +00:00
|
|
|
class Meta:
|
|
|
|
model = CeleryTaskExecution
|
|
|
|
fields = [
|
2022-12-02 09:18:11 +00:00
|
|
|
"id", "name", "args", "kwargs", "time_cost", "timedelta", "is_success", "is_finished", "date_published",
|
2022-11-16 07:04:46 +00:00
|
|
|
"date_start",
|
|
|
|
"date_finished"
|
2022-10-24 12:14:18 +00:00
|
|
|
]
|