mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-17 11:21:29 +00:00
Fix: flush file moves before the scheduled workflow websocket notification
This commit is contained in:
1 parent
18f243d381
commit
1721bd559a
2 files changed
+46
-3
No files matched your search
@@ -698,14 +698,16 @@ def check_scheduled_workflows() -> None:
|
||||
workflow_to_run=workflow,
|
||||
document=document,
|
||||
)
|
||||
# Move this document's files now rather than at the end
|
||||
# of the task, so a long run makes steady progress and
|
||||
# the notification below carries the final filename and
|
||||
# modified timestamp.
|
||||
flush_pending_file_moves()
|
||||
# Scheduled workflows dont send document_updated signal, so send a websocket update here to ensure clients are updated
|
||||
send_websocket_document_updated(
|
||||
sender=None,
|
||||
document=document,
|
||||
)
|
||||
# Move this document's files now rather than at the end
|
||||
# of the task, so a long run makes steady progress.
|
||||
flush_pending_file_moves()
|
||||
|
||||
|
||||
def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None:
|
||||
|
||||
@@ -1439,6 +1439,47 @@ class TestCeleryTaskScope:
|
||||
assert seen[first_pk] is False
|
||||
assert seen[second_pk] is True
|
||||
|
||||
def test_websocket_notification_sent_after_move(
|
||||
self,
|
||||
document: Document,
|
||||
paperless_dirs: PaperlessDirs,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A document matched by a scheduled workflow that renames it
|
||||
WHEN:
|
||||
- check_scheduled_workflows runs
|
||||
THEN:
|
||||
- The websocket notification is sent after the file has moved and
|
||||
the filename column is updated, so clients see the final state
|
||||
"""
|
||||
trigger = WorkflowTrigger.objects.create(
|
||||
type=WorkflowTrigger.WorkflowTriggerType.SCHEDULED,
|
||||
schedule_offset_days=0,
|
||||
schedule_date_field=WorkflowTrigger.ScheduleDateField.ADDED,
|
||||
)
|
||||
workflow = Workflow.objects.create(name="scheduled", order=0)
|
||||
workflow.triggers.add(trigger)
|
||||
workflow.actions.add(WorkflowAction.objects.create(assign_title="unused"))
|
||||
|
||||
def rename(*, document: Document, **kwargs: object) -> None:
|
||||
document.title = "renamed"
|
||||
document.save()
|
||||
|
||||
state: dict[str, object] = {}
|
||||
|
||||
def notify(*, document: Document, **kwargs: object) -> None:
|
||||
state["moved"] = (paperless_dirs.originals_dir / "renamed.pdf").is_file()
|
||||
state["filename"] = Document.objects.get(pk=document.pk).filename
|
||||
|
||||
mocker.patch("documents.tasks.run_workflows", side_effect=rename)
|
||||
mocker.patch("documents.tasks.send_websocket_document_updated", notify)
|
||||
|
||||
check_scheduled_workflows.apply()
|
||||
|
||||
assert state == {"moved": True, "filename": "renamed.pdf"}
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestEmptyTrashLockOrdering:
|
||||
|
||||
Reference in new issue
Block a user