fix(tasks): use TriggerSource enum values at all apply_async call sites

Replace raw strings ("system", "manual") with PaperlessTask.TriggerSource
enum values in the three callers that can import models. The settings
file remains a raw string (models cannot be imported at settings load
time) with a comment pointing to the enum value it must match.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
stumpylog
2026-04-16 10:19:45 -07:00
parent 4c01876a53
commit 78430892d1
4 changed files with 5 additions and 3 deletions

View File

@@ -3951,7 +3951,7 @@ class TasksViewSet(ReadOnlyModelViewSet[PaperlessTask]):
task_func, task_kwargs = self._RUNNABLE_TASKS[task_type]
async_result = task_func.apply_async(
kwargs=task_kwargs,
headers={"trigger_source": "manual"},
headers={"trigger_source": PaperlessTask.TriggerSource.MANUAL},
)
return Response({"task_id": async_result.id})
except Exception as e:

View File

@@ -183,6 +183,7 @@ def parse_beat_schedule() -> dict:
"schedule": crontab(minute, hour, day_week, day_month, month),
"options": {
**task["options"],
# PaperlessTask.TriggerSource.SCHEDULED -- models can't be imported here
"headers": {"trigger_source": "scheduled"},
},
}

View File

@@ -38,6 +38,7 @@ from rest_framework.response import Response
from rest_framework.throttling import ScopedRateThrottle
from rest_framework.viewsets import ModelViewSet
from documents.models import PaperlessTask
from documents.permissions import PaperlessObjectPermissions
from documents.tasks import llmindex_index
from paperless.filters import GroupFilterSet
@@ -429,7 +430,7 @@ class ApplicationConfigurationViewSet(ModelViewSet[ApplicationConfiguration]):
# AI index was just enabled and vector store file does not exist
llmindex_index.apply_async(
kwargs={"rebuild": True},
headers={"trigger_source": "system"},
headers={"trigger_source": PaperlessTask.TriggerSource.SYSTEM},
)

View File

@@ -39,7 +39,7 @@ def queue_llm_index_update_if_needed(*, rebuild: bool, reason: str) -> bool:
llmindex_index.apply_async(
kwargs={"rebuild": rebuild},
headers={"trigger_source": "system"},
headers={"trigger_source": PaperlessTask.TriggerSource.SYSTEM},
)
logger.warning(
"Queued LLM index update%s: %s",