Finalizes what the PaperlessTask will look like to the frontend

This commit is contained in:
Trenton H 2022-09-27 12:44:01 -07:00
parent 9247300230
commit fad1b03458
7 changed files with 27 additions and 28 deletions

View File

@ -6,7 +6,7 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("documents", "1026_remove_paperlesstask_created_and_more"),
("documents", "1025_alter_savedviewfilterrule_rule_type"),
]
# Manual SQL commands to drop the django_q related tables

View File

@ -1,4 +1,4 @@
# Generated by Django 4.0.7 on 2022-09-02 22:08
# Generated by Django 4.1.1 on 2022-09-27 19:31
from django.db import migrations, models
import django.db.models.deletion
@ -8,7 +8,7 @@ class Migration(migrations.Migration):
dependencies = [
("django_celery_results", "0011_taskresult_periodic_task_name"),
("documents", "1025_alter_savedviewfilterrule_rule_type"),
("documents", "1026_drop_django_q"),
]
operations = [
@ -24,10 +24,6 @@ class Migration(migrations.Migration):
model_name="paperlesstask",
name="started",
),
migrations.RemoveField(
model_name="paperlesstask",
name="task_id",
),
migrations.AlterField(
model_name="paperlesstask",
name="attempted_task",

View File

@ -527,6 +527,7 @@ class UiSettings(models.Model):
class PaperlessTask(models.Model):
task_id = models.CharField(max_length=128)
acknowledged = models.BooleanField(default=False)
attempted_task = models.OneToOneField(

View File

@ -622,14 +622,14 @@ class TasksViewSerializer(serializers.ModelSerializer):
depth = 1
fields = (
"id",
"task_id",
"date_created",
"date_done",
"type",
"status",
"result",
"acknowledged",
"date_created",
"date_done",
"task_name",
"task_id",
)
type = serializers.SerializerMethodField()
@ -670,14 +670,6 @@ class TasksViewSerializer(serializers.ModelSerializer):
result = obj.attempted_task.date_done
return result
task_name = serializers.SerializerMethodField()
def get_task_name(self, obj):
result = ""
if hasattr(obj, "attempted_task") and obj.attempted_task:
result = obj.attempted_task.task_name
return result
task_id = serializers.SerializerMethodField()
def get_task_id(self, obj):
@ -686,6 +678,14 @@ class TasksViewSerializer(serializers.ModelSerializer):
result = obj.attempted_task.task_id
return result
task_name = serializers.SerializerMethodField()
def get_task_name(self, obj):
result = ""
if hasattr(obj, "attempted_task") and obj.attempted_task:
result = obj.attempted_task.task_name
return result
class AcknowledgeTasksViewSerializer(serializers.Serializer):

View File

@ -509,6 +509,9 @@ def update_paperless_task(sender, instance: TaskResult, **kwargs):
paperless_task, _ = PaperlessTask.objects.get_or_create(
task_id=instance.task_id,
)
paperless_task.name = instance.task_name
paperless_task.created = instance.date_created
paperless_task.completed = instance.date_done
paperless_task.attempted_task = instance
paperless_task.save()
except Exception as e:

View File

@ -22,7 +22,6 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.test import override_settings
from django.utils import timezone
from django_q.models import Task
from documents import bulk_edit
from documents import index
from documents.models import Correspondent
@ -33,7 +32,6 @@ from documents.models import PaperlessTask
from documents.models import SavedView
from documents.models import StoragePath
from documents.models import Tag
from documents.models import UiSettings
from django_celery_results.models import TaskResult
from documents.models import Comment
from documents.models import StoragePath
@ -2805,23 +2803,19 @@ class TestTasks(APITestCase):
"""
result1 = TaskResult.objects.create(
task_id=str(uuid.uuid4()),
task_name="documents.tasks.some_task",
task_name="documents.tasks.some_great_task",
status=celery.states.PENDING,
)
PaperlessTask.objects.create(attempted_task=result1)
result2 = TaskResult.objects.create(
task_id=str(uuid.uuid4()),
task_name="documents.tasks.other_task",
task_name="documents.tasks.some_awesome_task",
status=celery.states.STARTED,
)
PaperlessTask.objects.create(attempted_task=result2)
response = self.client.get(self.ENDPOINT)
from pprint import pprint
for x in response.data:
pprint(x)
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)

View File

@ -463,13 +463,18 @@ WORKER_TIMEOUT: Final[int] = __get_int("PAPERLESS_WORKER_TIMEOUT", 1800)
CELERY_BROKER_URL = _REDIS_URL
CELERY_TIMEZONE = TIME_ZONE
CELERY_WORKER_HIJACK_ROOT_LOGGER = False
CELERY_WORKER_CONCURRENCY = TASK_WORKERS
CELERY_WORKER_MAX_TASKS_PER_CHILD = 1
CELERY_TASK_TRACK_STARTED = True
CELERY_RESULT_EXTENDED = True
CELERY_WORKER_SEND_TASK_EVENTS = True
CELERY_SEND_TASK_SENT_EVENT = True
CELERY_TASK_TRACK_STARTED = True
CELERY_TASK_TIME_LIMIT = WORKER_TIMEOUT
CELERY_RESULT_EXTENDED = True
CELERY_RESULT_BACKEND = "django-db"
CELERY_CACHE_BACKEND = "default"