feat(processing): reactive FIFO processing pipeline and worker-thread PDF merge - #1704
Open
manuc66 wants to merge 1 commit into
Open
feat(processing): reactive FIFO processing pipeline and worker-thread PDF merge#1704manuc66 wants to merge 1 commit into
manuc66 wants to merge 1 commit into
Conversation
manuc66
force-pushed
the
split/processing-pipeline
branch
from
September 5, 2026 05:25
9b6f10e to
a32816e
Compare
… PDF merge Port of PR #1699 onto master, adapted to the current codebase (no S3 or webhook yet): the staged post-processing pipeline, the in-memory FIFO processing queue, and the jsPDF merge moved to a worker thread. In listen and adf-autoscan mode, captured scans are dropped onto a single background drain so the loop keeps polling the printer while uploads or post-processing run; single-scan keeps its synchronous contract (exits only once delivery finished). Scan order is preserved. Durability is intentionally out of scope (in-memory queue). Also ships docs/processing-pipeline.md and the CHANGELOG entry.
manuc66
force-pushed
the
split/processing-pipeline
branch
from
September 5, 2026 05:28
a32816e to
95c0724
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
While a scan is post-processed (PDF merge, uploads), the
listenandadf-autoscanloops await the whole delivery before polling the printer again. A slow destination or a heavy merge can make the loop miss the next scan event or trip the printer'suserActionTimeout/waitScanNewPageRequesttimeouts. Insingle-scanthis is one iteration and does not matter.Solution
Producer/consumer in the same process:
postProcessing):generate PDF → announce → deliver → cleanup, threaded through a shared context — the seam where future pre-processing stages (OCR,--post-command) plug in.src/queue/processingQueue.ts): captured scans are drained in capture order by one background worker; the loop returns to polling immediately.src/pdfMergeWorker.ts): jsPDF runs in a worker thread, so health checks and printer HTTP responses stay responsive during a big merge.single-scankeeps its synchronous contract (exits only once delivery finished), routed throughprocessScanProcessingJob.Durability (explicitly not part of this PR)
The queue is in memory. A crash mid-job leaves captured files on disk (cleanup only runs once delivery finished) and delivery can be redone by hand — no worse than the previous synchronous behavior, and no breaking change for existing Paperless/Nextcloud users.
Review checklist
fs.readFilereads (webhook sha256, S3 upload) belong to the S3/webhook PRs.errorCount. Verify the listener keeps running when a delivery target is unreachable.flushOutboxblocking is the webhook PR's concern; here the queue guarantees the scan loop is never blocked by a slow delivery.Merge this PR first — it is the foundation. The S3-delivery and webhook/outbox PRs follow.
Testing
test/processingQueue.test.ts: enqueue returns before the work completes (capture not blocked), FIFO order through a real delivery, awaited single-job path.674 passing) including the adaptedlistenCmd/postProcessingsuites.