mirror of
https://github.com/dagucloud/dagu.git
synced 2026-12-05 05:32:51 +00:00
5.9 KiB
5.9 KiB
Implementation Notes
2026-05-24
- Branch target:
refactor/queue-persis-store. - Initial staged documentation change was committed first as
doc: update persistence refactor plan, keeping it separate from product-code changes. - Implementation target: port the queue store from
internal/persis/filequeueto apersis.Collection-backed adapter ininternal/persis/store. - Literal queue collection/root decision: use
cfg.Paths.QueueDirthroughfile.NewCollection(cfg.Paths.QueueDir)for the first wiring step so the file backend preserves the existingdata/queuelayout. This avoids silently moving queue files to a newqueue_itemsdirectory. - Literal queue record ID decision: store records as
{queueName}/{itemID}while keeping the publicQueuedItemData.ID()value as{itemID}. This preserves the existingQueueStorecontract for deletion and cursor callers. - Test coverage decision: start with memory-backed store tests for the queue adapter because the refactor goal is backend-neutral behavior. File-backend compatibility is covered through the existing
persis.Collectioncontract; if queue file layout issues appear while wiring, add a file-backed queue test before committing. - Queue item ID decision: generated item IDs keep the old
item_{high|low}_{timestamp}Z_{dagRunID}prefix shape, but add a UUID suffix to avoid accidental overwrite when the same run is enqueued more than once at the same timestamp. - Queue watcher tradeoff: the new adapter uses a backend-neutral polling watcher rather than the old filesystem watcher. This keeps
internal/persis/storeindependent frominternal/persis/filequeue, and the scheduler already has interval-based processing as a fallback. - Dequeue tradeoff:
Collection.Claimremoves the record before the adapter decodes it. The queue store now restores the claimed record on decode/validation failure so a malformed first item is not silently dropped. - Added a file-backed legacy compatibility test that writes the old raw queue item JSON format under
{queueDir}/{queueName}/item_*.json. This guards the no-migration path when wiring the new adapter tocfg.Paths.QueueDir. - Wiring decision: changed
internal/cmd/context.goto constructstore.NewQueueStore(file.NewCollection(cfg.Paths.QueueDir)). I did not switch the broader context to a single sharedfile.New(cfg.Paths.DataDir)backend yet, becausedagrun,proc, and distributed stores are still on legacy packages. - Test fixture wiring change: updated shared command/scheduler/API fixtures to construct the new queue store too. Keeping fixtures on the old queue store created mixed-backend tests where the command deleted records through the new store but assertions read stale legacy queue indexes.
- Scheduler package boundary cleanup: moved
WatermarkStoreout ofinternal/persis/storeso package-local tests underinternal/service/schedulercan instantiatestore.NewQueueStorewithout an import cycle. - Cleanup:
DequeueByNameand queue listing now use the{queueName}/item_prefix so legacy.queue-index.jsonfiles are never claimed as queue items. - Cleanup: moved
WatermarkStoretointernal/persis/schedulerstoreso the genericinternal/persis/storepackage no longer imports scheduler. Scheduler package tests can now usestore.NewQueueStore. - Cleanup: split queue item parsing, cursor handling, and watcher polling into separate files.
- Removed the legacy
internal/persis/filequeuepackage after verifying it had no non-test consumers. Legacy file layout coverage now lives ininternal/persis/store/queue_test.go. - Documentation cleanup: updated
refactor_persis_layer.htmlso the queue slice is marked complete,filequeueis described as removed, and the current wiring showsstore.NewQueueStore(file.NewCollection(cfg.Paths.QueueDir)). - Coverage cleanup: added focused queue-store tests for invalid enqueue input, normalized item deletion, cursor edge cases, invalid record parsing, queue metadata parsing, and the polling watcher.
- Review cleanup:
DeleteByItemIDsnow uses an optional exact-delete collection extension (DeleteIfExists) so corrupt queue item records can still be deleted and missing records are counted accurately without a pre-read race. - Review cleanup:
DequeueByNamerestores a claimed record if payload validation fails. This preserves malformed or legacy-incompatible records for inspection instead of dropping them during decode. - Review cleanup: queue list APIs now surface malformed queue item records instead of silently skipping them;
QueueListderives names from record IDs so broken payloads still keep the queue visible. - Review cleanup:
ListCursoruses a collection-backed queue read index plus an in-process cache. This avoids decoding every queued item on every cursor page while keeping a rebuild path for legacy directories and stale indexes. File and memory collections exposeRecordVersionso the cache can be invalidated when the persisted index changes. - Review cleanup: the polling queue watcher now snapshots queue item IDs and emits only when the queue changes, instead of notifying on every tick.
- Documentation drift cleanup: escaped Mermaid arrows in
refactor_persis_layer.htmlas HTML entities and updated stale PR #2194 wording to PR #2197 status text dated May 24, 2026. - Follow-up review cleanup: file-backed queue listing now discovers item IDs without decoding payloads, so corrupt/truncated queue files remain visible to
List,Len,All,QueueList, and watcher fingerprints. Invalid items are returned withData()errors instead of making the whole queue listing fail. - Follow-up review cleanup: scheduler dispatch selection now skips invalid queued items and continues to healthy items behind them, avoiding a head-of-line block from one malformed payload.
- Follow-up review cleanup: file-backed queue mutations and cursor-index rebuilds run under a per-queue
dirlockvia an optional collection lock hook, so persisted queue index updates are serialized across Dagu processes.