diff --git a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts index 5aa53052a..648c93cd3 100644 --- a/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts +++ b/src-ui/src/app/components/admin/tasks/tasks.component.spec.ts @@ -19,6 +19,7 @@ import { allIcons, NgxBootstrapIconsModule } from 'ngx-bootstrap-icons' import { routes } from 'src/app/app-routing.module' import { PaperlessTask, + PaperlessTaskName, PaperlessTaskStatus, PaperlessTaskType, } from 'src/app/data/paperless-task' @@ -39,7 +40,8 @@ const tasks: PaperlessTask[] = [ task_file_name: 'test.pdf', date_created: new Date('2023-03-01T10:26:03.093116Z'), date_done: new Date('2023-03-01T10:26:07.223048Z'), - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Failed, result: 'test.pd: Not consuming test.pdf: It is a duplicate of test (#100)', acknowledged: false, @@ -51,7 +53,8 @@ const tasks: PaperlessTask[] = [ task_file_name: '191092.pdf', date_created: new Date('2023-03-01T09:26:03.093116Z'), date_done: new Date('2023-03-01T09:26:07.223048Z'), - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Failed, result: '191092.pd: Not consuming 191092.pdf: It is a duplicate of 191092 (#311)', @@ -64,7 +67,8 @@ const tasks: PaperlessTask[] = [ task_file_name: 'Scan Jun 6, 2023 at 3.19 PM.pdf', date_created: new Date('2023-06-06T15:22:05.722323-07:00'), date_done: new Date('2023-06-06T15:22:14.564305-07:00'), - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Pending, result: null, acknowledged: false, @@ -76,7 +80,8 @@ const tasks: PaperlessTask[] = [ task_file_name: 'paperless-mail-l4dkg8ir', date_created: new Date('2023-06-04T11:24:32.898089-07:00'), date_done: new Date('2023-06-04T11:24:44.678605-07:00'), - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Complete, result: 'Success. New document id 422 created', acknowledged: false, @@ -88,7 +93,8 @@ const tasks: PaperlessTask[] = [ task_file_name: 'onlinePaymentSummary.pdf', date_created: new Date('2023-06-01T13:49:51.631305-07:00'), date_done: new Date('2023-06-01T13:49:54.190220-07:00'), - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Complete, result: 'Success. New document id 421 created', acknowledged: false, @@ -100,7 +106,8 @@ const tasks: PaperlessTask[] = [ task_file_name: 'paperless-mail-_rrpmqk6', date_created: new Date('2023-06-07T02:54:35.694916Z'), date_done: null, - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Started, result: null, acknowledged: false, @@ -155,7 +162,7 @@ describe('TasksComponent', () => { jest.useFakeTimers() fixture.detectChanges() httpTestingController - .expectOne(`${environment.apiBaseUrl}tasks/?type=file`) + .expectOne(`${environment.apiBaseUrl}tasks/?task_name=consume_file`) .flush(tasks) }) diff --git a/src-ui/src/app/data/paperless-task.ts b/src-ui/src/app/data/paperless-task.ts index 5b2003704..d788dcbd4 100644 --- a/src-ui/src/app/data/paperless-task.ts +++ b/src-ui/src/app/data/paperless-task.ts @@ -1,11 +1,17 @@ import { ObjectWithId } from './object-with-id' export enum PaperlessTaskType { - File = 'file', + Auto = 'auto_task', ScheduledTask = 'scheduled_task', ManualTask = 'manual_task', } +export enum PaperlessTaskName { + ConsumeFile = 'consume_file', + TrainClassifier = 'train_classifier', + SanityCheck = 'check_sanity', +} + export enum PaperlessTaskStatus { Pending = 'PENDING', Started = 'STARTED', @@ -24,6 +30,8 @@ export interface PaperlessTask extends ObjectWithId { task_file_name: string + task_name: PaperlessTaskName + date_created: Date date_done?: Date diff --git a/src-ui/src/app/services/tasks.service.spec.ts b/src-ui/src/app/services/tasks.service.spec.ts index e161c15dd..bb18b5216 100644 --- a/src-ui/src/app/services/tasks.service.spec.ts +++ b/src-ui/src/app/services/tasks.service.spec.ts @@ -5,7 +5,11 @@ import { } from '@angular/common/http/testing' import { TestBed } from '@angular/core/testing' import { environment } from 'src/environments/environment' -import { PaperlessTaskStatus, PaperlessTaskType } from '../data/paperless-task' +import { + PaperlessTaskName, + PaperlessTaskStatus, + PaperlessTaskType, +} from '../data/paperless-task' import { TasksService } from './tasks.service' describe('TasksService', () => { @@ -33,7 +37,7 @@ describe('TasksService', () => { it('calls tasks api endpoint on reload', () => { tasksService.reload() const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}tasks/?type=file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file` ) expect(req.request.method).toEqual('GET') }) @@ -42,7 +46,7 @@ describe('TasksService', () => { tasksService.loading = true tasksService.reload() httpTestingController.expectNone( - `${environment.apiBaseUrl}tasks/?type=file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file` ) }) @@ -58,7 +62,7 @@ describe('TasksService', () => { req.flush([]) // reload is then called httpTestingController - .expectOne(`${environment.apiBaseUrl}tasks/?type=file`) + .expectOne(`${environment.apiBaseUrl}tasks/?task_name=consume_file`) .flush([]) }) @@ -66,7 +70,8 @@ describe('TasksService', () => { expect(tasksService.total).toEqual(0) const mockTasks = [ { - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Complete, acknowledged: false, task_id: '1234', @@ -74,7 +79,8 @@ describe('TasksService', () => { date_created: new Date(), }, { - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Failed, acknowledged: false, task_id: '1235', @@ -82,7 +88,8 @@ describe('TasksService', () => { date_created: new Date(), }, { - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Pending, acknowledged: false, task_id: '1236', @@ -90,7 +97,8 @@ describe('TasksService', () => { date_created: new Date(), }, { - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Started, acknowledged: false, task_id: '1237', @@ -98,7 +106,8 @@ describe('TasksService', () => { date_created: new Date(), }, { - type: PaperlessTaskType.File, + type: PaperlessTaskType.Auto, + task_name: PaperlessTaskName.ConsumeFile, status: PaperlessTaskStatus.Complete, acknowledged: false, task_id: '1238', @@ -110,7 +119,7 @@ describe('TasksService', () => { tasksService.reload() const req = httpTestingController.expectOne( - `${environment.apiBaseUrl}tasks/?type=file` + `${environment.apiBaseUrl}tasks/?task_name=consume_file` ) req.flush(mockTasks) diff --git a/src-ui/src/app/services/tasks.service.ts b/src-ui/src/app/services/tasks.service.ts index 4e7226bad..51db7e48c 100644 --- a/src-ui/src/app/services/tasks.service.ts +++ b/src-ui/src/app/services/tasks.service.ts @@ -54,10 +54,10 @@ export class TasksService { this.loading = true this.http - .get(`${this.baseUrl}tasks/?type=file`) + .get(`${this.baseUrl}tasks/?task_name=consume_file`) .pipe(takeUntil(this.unsubscribeNotifer), first()) .subscribe((r) => { - this.fileTasks = r.filter((t) => t.type == PaperlessTaskType.File) // they're all File tasks, for now + this.fileTasks = r.filter((t) => t.type == PaperlessTaskType.Auto) this.loading = false }) } diff --git a/src/documents/filters.py b/src/documents/filters.py index 086c889e0..19b4d95b6 100644 --- a/src/documents/filters.py +++ b/src/documents/filters.py @@ -776,6 +776,7 @@ class PaperlessTaskFilterSet(FilterSet): model = PaperlessTask fields = { "type": ["exact"], + "task_name": ["exact"], "status": ["exact"], } diff --git a/src/documents/migrations/1063_paperlesstask_type.py b/src/documents/migrations/1063_paperlesstask_type.py deleted file mode 100644 index 5a3c5d670..000000000 --- a/src/documents/migrations/1063_paperlesstask_type.py +++ /dev/null @@ -1,28 +0,0 @@ -# Generated by Django 5.1.6 on 2025-02-14 01:11 - -from django.db import migrations -from django.db import models - - -class Migration(migrations.Migration): - dependencies = [ - ("documents", "1062_alter_savedviewfilterrule_rule_type"), - ] - - operations = [ - migrations.AddField( - model_name="paperlesstask", - name="type", - field=models.CharField( - choices=[ - ("file", "File Task"), - ("scheduled_task", "Scheduled Task"), - ("manual_task", "Manual Task"), - ], - default="file", - help_text="The type of task that was run", - max_length=30, - verbose_name="Task Type", - ), - ), - ] diff --git a/src/documents/migrations/1063_paperlesstask_type_alter_paperlesstask_task_name.py b/src/documents/migrations/1063_paperlesstask_type_alter_paperlesstask_task_name.py new file mode 100644 index 000000000..e3878c665 --- /dev/null +++ b/src/documents/migrations/1063_paperlesstask_type_alter_paperlesstask_task_name.py @@ -0,0 +1,52 @@ +# Generated by Django 5.1.6 on 2025-02-14 23:10 + +from django.db import migrations +from django.db import models + + +def make_existing_tasks_consume_auto(apps, schema_editor): + PaperlessTask = apps.get_model("documents", "PaperlessTask") + PaperlessTask.objects.all().update(type="auto_task", task_name="consume_file") + + +class Migration(migrations.Migration): + dependencies = [ + ("documents", "1062_alter_savedviewfilterrule_rule_type"), + ] + + operations = [ + migrations.AddField( + model_name="paperlesstask", + name="type", + field=models.CharField( + choices=[ + ("auto_task", "Auto Task"), + ("scheduled_task", "Scheduled Task"), + ("manual_task", "Manual Task"), + ], + default="auto_task", + help_text="The type of task that was run", + max_length=30, + verbose_name="Task Type", + ), + ), + migrations.AlterField( + model_name="paperlesstask", + name="task_name", + field=models.CharField( + choices=[ + ("consume_file", "Consume File"), + ("train_classifier", "Train Classifier"), + ("check_sanity", "Check Sanity"), + ], + help_text="Name of the task that was run", + max_length=255, + null=True, + verbose_name="Task Name", + ), + ), + migrations.RunPython( + make_existing_tasks_consume_auto, + migrations.RunPython.noop, + ), + ] diff --git a/src/documents/models.py b/src/documents/models.py index d6cb91e03..94888ce9f 100644 --- a/src/documents/models.py +++ b/src/documents/models.py @@ -651,10 +651,15 @@ class PaperlessTask(ModelWithOwner): TASK_STATE_CHOICES = sorted(zip(ALL_STATES, ALL_STATES)) class TaskType(models.TextChoices): - FILE = ("file", _("File Task")) + AUTO = ("auto_task", _("Auto Task")) SCHEDULED_TASK = ("scheduled_task", _("Scheduled Task")) MANUAL_TASK = ("manual_task", _("Manual Task")) + class TaskName(models.TextChoices): + CONSUME_FILE = ("consume_file", _("Consume File")) + TRAIN_CLASSIFIER = ("train_classifier", _("Train Classifier")) + CHECK_SANITY = ("check_sanity", _("Check Sanity")) + task_id = models.CharField( max_length=255, unique=True, @@ -678,8 +683,9 @@ class PaperlessTask(ModelWithOwner): task_name = models.CharField( null=True, max_length=255, + choices=TaskName.choices, verbose_name=_("Task Name"), - help_text=_("Name of the Task which was run"), + help_text=_("Name of the task that was run"), ) status = models.CharField( @@ -723,7 +729,7 @@ class PaperlessTask(ModelWithOwner): type = models.CharField( max_length=30, choices=TaskType.choices, - default=TaskType.FILE, + default=TaskType.AUTO, verbose_name=_("Task Type"), help_text=_("The type of task that was run"), ) diff --git a/src/documents/sanity_checker.py b/src/documents/sanity_checker.py index 5cd5bdce4..6cef98f1a 100644 --- a/src/documents/sanity_checker.py +++ b/src/documents/sanity_checker.py @@ -67,7 +67,7 @@ def check_sanity(*, progress=False, scheduled=True) -> SanityCheckMessages: type=PaperlessTask.TaskType.SCHEDULED_TASK if scheduled else PaperlessTask.TaskType.MANUAL_TASK, - task_name="check_sanity", + task_name=PaperlessTask.TaskName.CHECK_SANITY, status=states.STARTED, date_created=timezone.now(), date_started=timezone.now(), diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index fe4385e6d..5bab41b26 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -1689,6 +1689,7 @@ class TasksViewSerializer(OwnedObjectSerializer): fields = ( "id", "task_id", + "task_name", "task_file_name", "date_created", "date_done", diff --git a/src/documents/signals/handlers.py b/src/documents/signals/handlers.py index 1a821ea16..ec0a29705 100644 --- a/src/documents/signals/handlers.py +++ b/src/documents/signals/handlers.py @@ -1221,11 +1221,11 @@ def before_task_publish_handler(sender=None, headers=None, body=None, **kwargs): user_id = overrides.owner_id if overrides else None PaperlessTask.objects.create( - type=PaperlessTask.TaskType.FILE, + type=PaperlessTask.TaskType.AUTO, task_id=headers["id"], status=states.PENDING, task_file_name=task_file_name, - task_name=headers["task"], + task_name=PaperlessTask.TaskName.CONSUME_FILE, result=None, date_created=timezone.now(), date_started=None, diff --git a/src/documents/tasks.py b/src/documents/tasks.py index a798e3326..23b97bb08 100644 --- a/src/documents/tasks.py +++ b/src/documents/tasks.py @@ -82,7 +82,7 @@ def train_classifier(*, scheduled=True): if scheduled else PaperlessTask.TaskType.MANUAL_TASK, task_id=uuid.uuid4(), - task_name="train_classifier", + task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER, status=states.STARTED, date_created=timezone.now(), date_started=timezone.now(), diff --git a/src/documents/tests/test_api_status.py b/src/documents/tests/test_api_status.py index ca86954a8..9b7bf37ad 100644 --- a/src/documents/tests/test_api_status.py +++ b/src/documents/tests/test_api_status.py @@ -201,7 +201,7 @@ class TestSystemStatus(APITestCase): PaperlessTask.objects.create( type=PaperlessTask.TaskType.SCHEDULED_TASK, status=states.SUCCESS, - task_name="train_classifier", + task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER, ) self.client.force_login(self.user) response = self.client.get(self.ENDPOINT) @@ -238,7 +238,7 @@ class TestSystemStatus(APITestCase): PaperlessTask.objects.create( type=PaperlessTask.TaskType.SCHEDULED_TASK, status=states.FAILURE, - task_name="train_classifier", + task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER, result="Classifier training failed", ) self.client.force_login(self.user) @@ -262,7 +262,7 @@ class TestSystemStatus(APITestCase): PaperlessTask.objects.create( type=PaperlessTask.TaskType.SCHEDULED_TASK, status=states.SUCCESS, - task_name="check_sanity", + task_name=PaperlessTask.TaskName.CHECK_SANITY, ) self.client.force_login(self.user) response = self.client.get(self.ENDPOINT) @@ -299,7 +299,7 @@ class TestSystemStatus(APITestCase): PaperlessTask.objects.create( type=PaperlessTask.TaskType.SCHEDULED_TASK, status=states.FAILURE, - task_name="check_sanity", + task_name=PaperlessTask.TaskName.CHECK_SANITY, result="5 issues found.", ) self.client.force_login(self.user) diff --git a/src/documents/tests/test_api_tasks.py b/src/documents/tests/test_api_tasks.py index 922067930..24062d427 100644 --- a/src/documents/tests/test_api_tasks.py +++ b/src/documents/tests/test_api_tasks.py @@ -246,7 +246,7 @@ class TestTasks(DirectoriesMixin, APITestCase): PaperlessTask.objects.create( task_id=str(uuid.uuid4()), task_file_name="test.pdf", - task_name="documents.tasks.some_task", + task_name=PaperlessTask.TaskName.CONSUME_FILE, status=celery.states.SUCCESS, ) @@ -272,7 +272,7 @@ class TestTasks(DirectoriesMixin, APITestCase): PaperlessTask.objects.create( task_id=str(uuid.uuid4()), task_file_name="anothertest.pdf", - task_name="documents.tasks.some_task", + task_name=PaperlessTask.TaskName.CONSUME_FILE, status=celery.states.SUCCESS, ) diff --git a/src/documents/tests/test_task_signals.py b/src/documents/tests/test_task_signals.py index a025fb9dc..d94eb3848 100644 --- a/src/documents/tests/test_task_signals.py +++ b/src/documents/tests/test_task_signals.py @@ -68,7 +68,7 @@ class TestTaskSignalHandler(DirectoriesMixin, TestCase): self.assertIsNotNone(task) self.assertEqual(headers["id"], task.task_id) self.assertEqual("hello-999.pdf", task.task_file_name) - self.assertEqual("documents.tasks.consume_file", task.task_name) + self.assertEqual(PaperlessTask.TaskName.CONSUME_FILE, task.task_name) self.assertEqual(1, task.owner_id) self.assertEqual(celery.states.PENDING, task.status) diff --git a/src/documents/views.py b/src/documents/views.py index fe3ac837f..43984e578 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -2668,7 +2668,7 @@ class SystemStatusView(PassUserMixin): last_trained_task = ( PaperlessTask.objects.filter( - task_name__icontains="train_classifier", + task_name=PaperlessTask.TaskName.TRAIN_CLASSIFIER, ) .order_by("-date_done") .first() @@ -2687,7 +2687,7 @@ class SystemStatusView(PassUserMixin): last_sanity_check = ( PaperlessTask.objects.filter( - task_name__icontains="check_sanity", + task_name=PaperlessTask.TaskName.CHECK_SANITY, ) .order_by("-date_done") .first()