bunqueue 2.8.60 → 2.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -78
- package/dist/application/background/dlq.js +2 -0
- package/dist/application/background/recovery/active.d.ts +1 -0
- package/dist/application/background/recovery/active.js +12 -0
- package/dist/application/background/recovery/index.js +3 -1
- package/dist/application/background/recovery/pending.js +1 -0
- package/dist/application/cleanupTasks.js +4 -16
- package/dist/application/contextFactory.js +8 -0
- package/dist/application/dlqManager.d.ts +10 -0
- package/dist/application/dlqManager.js +48 -9
- package/dist/application/dlqRetry.js +60 -38
- package/dist/application/eventsManager.d.ts +9 -2
- package/dist/application/eventsManager.js +106 -55
- package/dist/application/operations/ackHelpers.d.ts +1 -4
- package/dist/application/operations/ackHelpers.js +39 -14
- package/dist/application/operations/flowPush.js +1 -0
- package/dist/application/operations/flowValidation.js +4 -4
- package/dist/application/operations/jobManagement.d.ts +4 -0
- package/dist/application/operations/jobMoveOperations.js +9 -4
- package/dist/application/operations/pull.d.ts +7 -2
- package/dist/application/operations/pull.js +15 -57
- package/dist/application/operations/pullFinalization.d.ts +6 -0
- package/dist/application/operations/pullFinalization.js +69 -0
- package/dist/application/operations/pullStateTransition.d.ts +8 -7
- package/dist/application/operations/pullStateTransition.js +25 -18
- package/dist/application/operations/push.js +3 -0
- package/dist/application/operations/pushBatch.js +14 -7
- package/dist/application/operations/pushContext.d.ts +2 -1
- package/dist/application/postgres-queue-manager/batchSnapshot.d.ts +16 -0
- package/dist/application/postgres-queue-manager/batchSnapshot.js +17 -0
- package/dist/application/postgres-queue-manager/cloud.d.ts +30 -0
- package/dist/application/postgres-queue-manager/cloud.js +55 -0
- package/dist/application/postgres-queue-manager/config.d.ts +5 -0
- package/dist/application/postgres-queue-manager/config.js +1 -0
- package/dist/application/postgres-queue-manager/control.d.ts +30 -0
- package/dist/application/postgres-queue-manager/control.js +210 -0
- package/dist/application/postgres-queue-manager/deferredWrites.d.ts +13 -0
- package/dist/application/postgres-queue-manager/deferredWrites.js +60 -0
- package/dist/application/postgres-queue-manager/delivery.d.ts +20 -0
- package/dist/application/postgres-queue-manager/delivery.js +83 -0
- package/dist/application/postgres-queue-manager/groupQueries.d.ts +10 -0
- package/dist/application/postgres-queue-manager/groupQueries.js +40 -0
- package/dist/application/postgres-queue-manager/lease.d.ts +13 -0
- package/dist/application/postgres-queue-manager/lease.js +88 -0
- package/dist/application/postgres-queue-manager/lifetimeMetrics.d.ts +32 -0
- package/dist/application/postgres-queue-manager/lifetimeMetrics.js +53 -0
- package/dist/application/postgres-queue-manager/maintenance.d.ts +14 -0
- package/dist/application/postgres-queue-manager/maintenance.js +100 -0
- package/dist/application/postgres-queue-manager/operationGate.d.ts +26 -0
- package/dist/application/postgres-queue-manager/operationGate.js +96 -0
- package/dist/application/postgres-queue-manager/operations.d.ts +25 -0
- package/dist/application/postgres-queue-manager/operations.js +194 -0
- package/dist/application/postgres-queue-manager/projectionRefreshes.d.ts +43 -0
- package/dist/application/postgres-queue-manager/projectionRefreshes.js +170 -0
- package/dist/application/postgres-queue-manager/queries.d.ts +142 -0
- package/dist/application/postgres-queue-manager/queries.js +231 -0
- package/dist/application/postgres-queue-manager/relationships.d.ts +10 -0
- package/dist/application/postgres-queue-manager/relationships.js +45 -0
- package/dist/application/postgres-queue-manager/services.d.ts +31 -0
- package/dist/application/postgres-queue-manager/services.js +149 -0
- package/dist/application/postgres-queue-manager/snapshot.d.ts +51 -0
- package/dist/application/postgres-queue-manager/snapshot.js +236 -0
- package/dist/application/postgres-queue-manager/snapshotViews.d.ts +15 -0
- package/dist/application/postgres-queue-manager/snapshotViews.js +100 -0
- package/dist/application/postgres-queue-manager/startupEventBuffer.d.ts +12 -0
- package/dist/application/postgres-queue-manager/startupEventBuffer.js +36 -0
- package/dist/application/postgres-queue-manager/state.d.ts +47 -0
- package/dist/application/postgres-queue-manager/state.js +273 -0
- package/dist/application/postgres-queue-manager/terminalDelivery.d.ts +20 -0
- package/dist/application/postgres-queue-manager/terminalDelivery.js +100 -0
- package/dist/application/postgresQueueManager.d.ts +2 -0
- package/dist/application/postgresQueueManager.js +1 -0
- package/dist/application/queue-manager/control.js +1 -0
- package/dist/application/queue-manager/delivery.d.ts +5 -4
- package/dist/application/queue-manager/delivery.js +15 -8
- package/dist/application/queue-manager/flow-failures.js +4 -0
- package/dist/application/queue-manager/limits.d.ts +13 -0
- package/dist/application/queue-manager/limits.js +65 -0
- package/dist/application/queue-manager/observability.js +15 -3
- package/dist/application/queue-manager/queries.d.ts +7 -0
- package/dist/application/queue-manager/queries.js +9 -0
- package/dist/application/queue-manager/services.d.ts +1 -1
- package/dist/application/queue-manager/services.js +4 -2
- package/dist/application/queue-manager/state.js +17 -2
- package/dist/application/queueTelemetryJournal.d.ts +2 -0
- package/dist/application/queueTelemetryJournal.js +23 -0
- package/dist/application/types/ack.d.ts +3 -1
- package/dist/cli/commandRouter.d.ts +1 -1
- package/dist/cli/commands/server.js +1 -1
- package/dist/client/flowPush.js +6 -0
- package/dist/client/forwarder.d.ts +6 -4
- package/dist/client/forwarder.js +5 -3
- package/dist/client/groupId.d.ts +1 -0
- package/dist/client/groupId.js +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/jobHelpers.js +1 -0
- package/dist/client/queue/dlq.d.ts +2 -0
- package/dist/client/queue/dlq.js +14 -0
- package/dist/client/queue/dlqOps.d.ts +2 -0
- package/dist/client/queue/dlqOps.js +4 -0
- package/dist/client/queue/helpers.js +2 -0
- package/dist/client/queue/operations/add/bulk.js +4 -4
- package/dist/client/queue/operations/add/payload.d.ts +1 -0
- package/dist/client/queue/operations/add/payload.js +7 -1
- package/dist/client/queue/operations/add/single.js +3 -3
- package/dist/client/queue/operations/groups.d.ts +21 -0
- package/dist/client/queue/operations/groups.js +88 -0
- package/dist/client/queue/runtime/configuration.d.ts +4 -0
- package/dist/client/queue/runtime/configuration.js +8 -0
- package/dist/client/queue/runtime/queries.d.ts +13 -0
- package/dist/client/queue/runtime/queries.js +31 -0
- package/dist/client/queue/runtime/state.d.ts +4 -0
- package/dist/client/queue/runtime/state.js +1 -0
- package/dist/client/types/index.d.ts +2 -2
- package/dist/client/types/options.d.ts +4 -0
- package/dist/client/types/worker.d.ts +8 -0
- package/dist/client/worker/runtime/execution.js +4 -8
- package/dist/client/worker/runtime/options.js +3 -0
- package/dist/client/worker/runtime/polling.d.ts +1 -0
- package/dist/client/worker/runtime/polling.js +9 -0
- package/dist/client/worker/types/options.d.ts +2 -1
- package/dist/client/worker/workerPull.d.ts +2 -0
- package/dist/client/worker/workerPull.js +6 -4
- package/dist/config/resolve.d.ts +14 -0
- package/dist/config/resolve.js +50 -5
- package/dist/config/types.d.ts +18 -0
- package/dist/domain/job/groupFifoOrder.d.ts +9 -0
- package/dist/domain/job/groupFifoOrder.js +26 -0
- package/dist/domain/queue/dlqShard.d.ts +2 -0
- package/dist/domain/queue/dlqShard.js +16 -0
- package/dist/domain/queue/groupLimiterManager.d.ts +23 -0
- package/dist/domain/queue/groupLimiterManager.js +107 -0
- package/dist/domain/queue/groupScheduler.d.ts +31 -0
- package/dist/domain/queue/groupScheduler.js +256 -0
- package/dist/domain/queue/groupSchedulerOrder.d.ts +6 -0
- package/dist/domain/queue/groupSchedulerOrder.js +30 -0
- package/dist/domain/queue/priorityQueue.d.ts +13 -23
- package/dist/domain/queue/priorityQueue.js +53 -42
- package/dist/domain/queue/shard/dlq.d.ts +1 -0
- package/dist/domain/queue/shard/dlq.js +3 -0
- package/dist/domain/queue/shard/keys.d.ts +1 -0
- package/dist/domain/queue/shard/keys.js +25 -2
- package/dist/domain/queue/shard/lifecycle.js +4 -0
- package/dist/domain/queue/shard/limits.d.ts +20 -1
- package/dist/domain/queue/shard/limits.js +56 -0
- package/dist/domain/queue/shard/state.d.ts +5 -0
- package/dist/domain/queue/shard/state.js +9 -1
- package/dist/domain/types/commands/core.d.ts +3 -0
- package/dist/domain/types/commands/dlq.d.ts +5 -0
- package/dist/domain/types/commands/limits.d.ts +41 -0
- package/dist/domain/types/commands/union.d.ts +1 -1
- package/dist/domain/types/cron.d.ts +5 -0
- package/dist/domain/types/cron.js +14 -3
- package/dist/domain/types/dlq.d.ts +1 -1
- package/dist/domain/types/dlq.js +1 -2
- package/dist/domain/types/group.d.ts +21 -0
- package/dist/domain/types/group.js +78 -0
- package/dist/domain/types/jobs/model.d.ts +1 -1
- package/dist/domain/types/priorityQueue.d.ts +1 -0
- package/dist/infrastructure/cloud/commandHandler.js +5 -3
- package/dist/infrastructure/cloud/commands/integrations.js +11 -11
- package/dist/infrastructure/cloud/commands/jobs.js +48 -40
- package/dist/infrastructure/cloud/commands/queues.js +61 -75
- package/dist/infrastructure/cloud/queueAdapter/local.d.ts +41 -0
- package/dist/infrastructure/cloud/queueAdapter/local.js +187 -0
- package/dist/infrastructure/cloud/queueAdapter/postgres.d.ts +42 -0
- package/dist/infrastructure/cloud/queueAdapter/postgres.js +188 -0
- package/dist/infrastructure/cloud/queueAdapter/registry.d.ts +4 -0
- package/dist/infrastructure/cloud/queueAdapter/registry.js +15 -0
- package/dist/infrastructure/cloud/queueAdapter/types.d.ts +87 -0
- package/dist/infrastructure/cloud/queueAdapter/types.js +1 -0
- package/dist/infrastructure/cloud/snapshot/analytics.d.ts +2 -0
- package/dist/infrastructure/cloud/snapshot/analytics.js +7 -0
- package/dist/infrastructure/cloud/snapshot/collector.d.ts +4 -0
- package/dist/infrastructure/cloud/snapshot/collector.js +39 -1
- package/dist/infrastructure/cloud/snapshot/config.d.ts +3 -0
- package/dist/infrastructure/cloud/snapshot/config.js +43 -0
- package/dist/infrastructure/cloud/snapshot/jobs.d.ts +3 -0
- package/dist/infrastructure/cloud/snapshot/jobs.js +32 -1
- package/dist/infrastructure/cloud/snapshotCollector.js +20 -35
- package/dist/infrastructure/cloud/snapshotHelpers.d.ts +3 -3
- package/dist/infrastructure/cloud/snapshotHelpers.js +3 -3
- package/dist/infrastructure/cloud/statsRefresh.js +2 -1
- package/dist/infrastructure/cloud/types/command.d.ts +2 -2
- package/dist/infrastructure/persistence/jobOptionsBlob.d.ts +1 -0
- package/dist/infrastructure/persistence/jobOptionsBlob.js +10 -2
- package/dist/infrastructure/persistence/migrations.js +11 -0
- package/dist/infrastructure/persistence/postgres/admission.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/admission.js +196 -0
- package/dist/infrastructure/persistence/postgres/admissionParent.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/admissionParent.js +35 -0
- package/dist/infrastructure/persistence/postgres/admissionResult.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/admissionResult.js +1 -0
- package/dist/infrastructure/persistence/postgres/admissionStore.d.ts +12 -0
- package/dist/infrastructure/persistence/postgres/admissionStore.js +101 -0
- package/dist/infrastructure/persistence/postgres/advisoryLocks.d.ts +2 -0
- package/dist/infrastructure/persistence/postgres/advisoryLocks.js +13 -0
- package/dist/infrastructure/persistence/postgres/batchAdmission.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/batchAdmission.js +128 -0
- package/dist/infrastructure/persistence/postgres/batchCompletion.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/batchCompletion.js +174 -0
- package/dist/infrastructure/persistence/postgres/batchEvents.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/batchEvents.js +72 -0
- package/dist/infrastructure/persistence/postgres/brokerSessions.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/brokerSessions.js +94 -0
- package/dist/infrastructure/persistence/postgres/claimBatch.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/claimBatch.js +69 -0
- package/dist/infrastructure/persistence/postgres/claimSelection.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/claimSelection.js +140 -0
- package/dist/infrastructure/persistence/postgres/claims.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/claims.js +153 -0
- package/dist/infrastructure/persistence/postgres/cloudReadModel.d.ts +26 -0
- package/dist/infrastructure/persistence/postgres/cloudReadModel.js +123 -0
- package/dist/infrastructure/persistence/postgres/codec.d.ts +30 -0
- package/dist/infrastructure/persistence/postgres/codec.js +82 -0
- package/dist/infrastructure/persistence/postgres/completionEvents.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/completionEvents.js +21 -0
- package/dist/infrastructure/persistence/postgres/completionLifecycle.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/completionLifecycle.js +145 -0
- package/dist/infrastructure/persistence/postgres/completionOutcome.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/completionOutcome.js +112 -0
- package/dist/infrastructure/persistence/postgres/completionQueries.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/completionQueries.js +87 -0
- package/dist/infrastructure/persistence/postgres/connection.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/connection.js +15 -0
- package/dist/infrastructure/persistence/postgres/context.d.ts +28 -0
- package/dist/infrastructure/persistence/postgres/context.js +74 -0
- package/dist/infrastructure/persistence/postgres/control.d.ts +23 -0
- package/dist/infrastructure/persistence/postgres/control.js +105 -0
- package/dist/infrastructure/persistence/postgres/crons.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/crons.js +205 -0
- package/dist/infrastructure/persistence/postgres/deduplication.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/deduplication.js +47 -0
- package/dist/infrastructure/persistence/postgres/dependencyDestruction.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/dependencyDestruction.js +74 -0
- package/dist/infrastructure/persistence/postgres/dependencyPromotion.d.ts +29 -0
- package/dist/infrastructure/persistence/postgres/dependencyPromotion.js +212 -0
- package/dist/infrastructure/persistence/postgres/destructiveMutations.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/destructiveMutations.js +111 -0
- package/dist/infrastructure/persistence/postgres/dlqLifecycle.d.ts +13 -0
- package/dist/infrastructure/persistence/postgres/dlqLifecycle.js +184 -0
- package/dist/infrastructure/persistence/postgres/dlqMaintenance.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/dlqMaintenance.js +36 -0
- package/dist/infrastructure/persistence/postgres/dlqRetryPlan.d.ts +21 -0
- package/dist/infrastructure/persistence/postgres/dlqRetryPlan.js +92 -0
- package/dist/infrastructure/persistence/postgres/eventCatchupCursors.d.ts +32 -0
- package/dist/infrastructure/persistence/postgres/eventCatchupCursors.js +66 -0
- package/dist/infrastructure/persistence/postgres/eventCommitGc.d.ts +27 -0
- package/dist/infrastructure/persistence/postgres/eventCommitGc.js +62 -0
- package/dist/infrastructure/persistence/postgres/eventJournal.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/eventJournal.js +76 -0
- package/dist/infrastructure/persistence/postgres/eventJournalSchema.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/eventJournalSchema.js +267 -0
- package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.d.ts +26 -0
- package/dist/infrastructure/persistence/postgres/eventPruneWatermarks.js +129 -0
- package/dist/infrastructure/persistence/postgres/eventRetention.d.ts +18 -0
- package/dist/infrastructure/persistence/postgres/eventRetention.js +76 -0
- package/dist/infrastructure/persistence/postgres/events.d.ts +45 -0
- package/dist/infrastructure/persistence/postgres/events.js +276 -0
- package/dist/infrastructure/persistence/postgres/expiry.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/expiry.js +74 -0
- package/dist/infrastructure/persistence/postgres/flowFailures.d.ts +17 -0
- package/dist/infrastructure/persistence/postgres/flowFailures.js +199 -0
- package/dist/infrastructure/persistence/postgres/groupClaims.d.ts +15 -0
- package/dist/infrastructure/persistence/postgres/groupClaims.js +95 -0
- package/dist/infrastructure/persistence/postgres/groupSchema.d.ts +2 -0
- package/dist/infrastructure/persistence/postgres/groupSchema.js +155 -0
- package/dist/infrastructure/persistence/postgres/groupSchemaFingerprint.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/groupSchemaFingerprint.js +127 -0
- package/dist/infrastructure/persistence/postgres/groupStateRetention.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/groupStateRetention.js +93 -0
- package/dist/infrastructure/persistence/postgres/groups.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/groups.js +117 -0
- package/dist/infrastructure/persistence/postgres/jobData.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/jobData.js +32 -0
- package/dist/infrastructure/persistence/postgres/leaseRelease.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/leaseRelease.js +120 -0
- package/dist/infrastructure/persistence/postgres/leaseRenewal.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/leaseRenewal.js +35 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetrics.d.ts +15 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetrics.js +46 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/lifetimeMetricsFinalizer.js +13 -0
- package/dist/infrastructure/persistence/postgres/logs.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/logs.js +70 -0
- package/dist/infrastructure/persistence/postgres/maintenance.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/maintenance.js +138 -0
- package/dist/infrastructure/persistence/postgres/maintenanceFlights.d.ts +14 -0
- package/dist/infrastructure/persistence/postgres/maintenanceFlights.js +66 -0
- package/dist/infrastructure/persistence/postgres/metricWrites.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/metricWrites.js +94 -0
- package/dist/infrastructure/persistence/postgres/mutations.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/mutations.js +171 -0
- package/dist/infrastructure/persistence/postgres/outcomes.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/outcomes.js +194 -0
- package/dist/infrastructure/persistence/postgres/policies.d.ts +11 -0
- package/dist/infrastructure/persistence/postgres/policies.js +18 -0
- package/dist/infrastructure/persistence/postgres/postCommitMaintenance.d.ts +17 -0
- package/dist/infrastructure/persistence/postgres/postCommitMaintenance.js +117 -0
- package/dist/infrastructure/persistence/postgres/promotion.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/promotion.js +43 -0
- package/dist/infrastructure/persistence/postgres/queries.d.ts +22 -0
- package/dist/infrastructure/persistence/postgres/queries.js +152 -0
- package/dist/infrastructure/persistence/postgres/queueDestruction.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/queueDestruction.js +158 -0
- package/dist/infrastructure/persistence/postgres/queueLifecycle.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/queueLifecycle.js +60 -0
- package/dist/infrastructure/persistence/postgres/rateLimit.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/rateLimit.js +10 -0
- package/dist/infrastructure/persistence/postgres/readModels.d.ts +32 -0
- package/dist/infrastructure/persistence/postgres/readModels.js +72 -0
- package/dist/infrastructure/persistence/postgres/recovery.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/recovery.js +178 -0
- package/dist/infrastructure/persistence/postgres/relationships.d.ts +9 -0
- package/dist/infrastructure/persistence/postgres/relationships.js +201 -0
- package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/removeUnprocessedChildren.js +241 -0
- package/dist/infrastructure/persistence/postgres/repeatMutations.d.ts +5 -0
- package/dist/infrastructure/persistence/postgres/repeatMutations.js +37 -0
- package/dist/infrastructure/persistence/postgres/runtime.d.ts +45 -0
- package/dist/infrastructure/persistence/postgres/runtime.js +238 -0
- package/dist/infrastructure/persistence/postgres/runtimeConfig.d.ts +21 -0
- package/dist/infrastructure/persistence/postgres/runtimeConfig.js +39 -0
- package/dist/infrastructure/persistence/postgres/schema.d.ts +4 -0
- package/dist/infrastructure/persistence/postgres/schema.js +261 -0
- package/dist/infrastructure/persistence/postgres/schemaInitialization.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/schemaInitialization.js +226 -0
- package/dist/infrastructure/persistence/postgres/serialAdmission.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/serialAdmission.js +96 -0
- package/dist/infrastructure/persistence/postgres/snapshotBudget.d.ts +3 -0
- package/dist/infrastructure/persistence/postgres/snapshotBudget.js +83 -0
- package/dist/infrastructure/persistence/postgres/storageHealth.d.ts +10 -0
- package/dist/infrastructure/persistence/postgres/storageHealth.js +29 -0
- package/dist/infrastructure/persistence/postgres/store.d.ts +100 -0
- package/dist/infrastructure/persistence/postgres/store.js +180 -0
- package/dist/infrastructure/persistence/postgres/telemetry.d.ts +8 -0
- package/dist/infrastructure/persistence/postgres/telemetry.js +100 -0
- package/dist/infrastructure/persistence/postgres/terminal.d.ts +8 -0
- package/dist/infrastructure/persistence/postgres/terminal.js +137 -0
- package/dist/infrastructure/persistence/postgres/transactionRetry.d.ts +6 -0
- package/dist/infrastructure/persistence/postgres/transactionRetry.js +42 -0
- package/dist/infrastructure/persistence/postgres/types.d.ts +176 -0
- package/dist/infrastructure/persistence/postgres/types.js +1 -0
- package/dist/infrastructure/persistence/postgres/workers.d.ts +15 -0
- package/dist/infrastructure/persistence/postgres/workers.js +126 -0
- package/dist/infrastructure/persistence/postgres.d.ts +2 -0
- package/dist/infrastructure/persistence/postgres.js +1 -0
- package/dist/infrastructure/persistence/schema.d.ts +2 -2
- package/dist/infrastructure/persistence/schema.js +12 -1
- package/dist/infrastructure/persistence/sqlite/control.d.ts +14 -0
- package/dist/infrastructure/persistence/sqlite/control.js +69 -0
- package/dist/infrastructure/persistence/sqlite/jobs.d.ts +12 -0
- package/dist/infrastructure/persistence/sqlite/jobs.js +38 -0
- package/dist/infrastructure/persistence/sqlite/telemetry.d.ts +2 -1
- package/dist/infrastructure/persistence/sqlite/telemetry.js +5 -64
- package/dist/infrastructure/persistence/sqlite/telemetryWrites.d.ts +4 -0
- package/dist/infrastructure/persistence/sqlite/telemetryWrites.js +123 -0
- package/dist/infrastructure/persistence/sqliteSerializer.js +2 -0
- package/dist/infrastructure/scheduler/cron/persisted.d.ts +5 -0
- package/dist/infrastructure/scheduler/cron/persisted.js +27 -0
- package/dist/infrastructure/scheduler/cron/runtime.js +5 -10
- package/dist/infrastructure/scheduler/cron/validation.d.ts +3 -0
- package/dist/infrastructure/scheduler/cron/validation.js +11 -0
- package/dist/infrastructure/scheduler/cronParser.d.ts +1 -1
- package/dist/infrastructure/scheduler/cronParser.js +144 -11
- package/dist/infrastructure/server/bootstrap.d.ts +2 -3
- package/dist/infrastructure/server/bootstrap.js +33 -59
- package/dist/infrastructure/server/errors.d.ts +4 -0
- package/dist/infrastructure/server/errors.js +54 -0
- package/dist/infrastructure/server/handler-routes/control.d.ts +5 -5
- package/dist/infrastructure/server/handler-routes/control.js +16 -1
- package/dist/infrastructure/server/handler-routes/monitoring.d.ts +2 -2
- package/dist/infrastructure/server/handler.js +9 -11
- package/dist/infrastructure/server/handlers/advanced/dependencies.js +7 -6
- package/dist/infrastructure/server/handlers/advanced/jobs.js +19 -6
- package/dist/infrastructure/server/handlers/advanced/queue.d.ts +9 -9
- package/dist/infrastructure/server/handlers/advanced/queue.js +91 -27
- package/dist/infrastructure/server/handlers/core.d.ts +0 -5
- package/dist/infrastructure/server/handlers/core.js +47 -49
- package/dist/infrastructure/server/handlers/cron.d.ts +4 -4
- package/dist/infrastructure/server/handlers/cron.js +60 -59
- package/dist/infrastructure/server/handlers/dashboard.d.ts +1 -1
- package/dist/infrastructure/server/handlers/dashboard.js +21 -8
- package/dist/infrastructure/server/handlers/dlq.d.ts +6 -3
- package/dist/infrastructure/server/handlers/dlq.js +35 -9
- package/dist/infrastructure/server/handlers/flow.js +2 -1
- package/dist/infrastructure/server/handlers/groups.d.ts +11 -0
- package/dist/infrastructure/server/handlers/groups.js +55 -0
- package/dist/infrastructure/server/handlers/management.d.ts +5 -5
- package/dist/infrastructure/server/handlers/management.js +36 -9
- package/dist/infrastructure/server/handlers/monitoring/health.d.ts +5 -5
- package/dist/infrastructure/server/handlers/monitoring/health.js +45 -16
- package/dist/infrastructure/server/handlers/monitoring/operations.d.ts +1 -1
- package/dist/infrastructure/server/handlers/monitoring/operations.js +8 -1
- package/dist/infrastructure/server/handlers/monitoring/workers.d.ts +3 -3
- package/dist/infrastructure/server/handlers/monitoring/workers.js +31 -7
- package/dist/infrastructure/server/handlers/pushBatchValidation.d.ts +3 -1
- package/dist/infrastructure/server/handlers/pushBatchValidation.js +56 -8
- package/dist/infrastructure/server/handlers/query.d.ts +1 -1
- package/dist/infrastructure/server/handlers/query.js +5 -4
- package/dist/infrastructure/server/http.js +2 -2
- package/dist/infrastructure/server/httpDashboardEndpoints.d.ts +1 -1
- package/dist/infrastructure/server/httpDashboardEndpoints.js +19 -6
- package/dist/infrastructure/server/httpEndpoints.js +18 -7
- package/dist/infrastructure/server/httpRouteQueues.js +11 -1
- package/dist/infrastructure/server/protocol/validation.d.ts +1 -0
- package/dist/infrastructure/server/protocol/validation.js +1 -0
- package/dist/infrastructure/server/protocol.d.ts +1 -1
- package/dist/infrastructure/server/protocol.js +1 -1
- package/dist/infrastructure/server/shutdownCoordinator.d.ts +24 -0
- package/dist/infrastructure/server/shutdownCoordinator.js +106 -0
- package/dist/infrastructure/server/sseHandler.js +8 -3
- package/dist/infrastructure/server/storageAdapter.d.ts +29 -0
- package/dist/infrastructure/server/storageAdapter.js +61 -0
- package/dist/infrastructure/server/storageManager.d.ts +12 -0
- package/dist/infrastructure/server/storageManager.js +102 -0
- package/dist/infrastructure/server/tcp.js +2 -3
- package/dist/infrastructure/server/ws/snapshots.d.ts +1 -1
- package/dist/infrastructure/server/ws/snapshots.js +19 -4
- package/dist/infrastructure/server/wsHandler.js +10 -5
- package/dist/main.js +1 -1
- package/dist/mcp/backend/embedded/services.js +2 -1
- package/dist/mcp/index.d.ts +2 -2
- package/dist/mcp/index.js +2 -2
- package/dist/shared/storageHealth.d.ts +9 -0
- package/dist/shared/storageHealth.js +12 -0
- package/package.json +75 -65
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { processingShardIndex, shardIndex } from '../../shared/hash';
|
|
2
|
+
import { LRUMap } from '../../shared/lru';
|
|
3
|
+
import { countSnapshotJobs, countSnapshotPriorities, findSnapshotJob, listSnapshotDlq, listSnapshotJobs, snapshotJobIds, snapshotQueueNames, } from './snapshotViews';
|
|
4
|
+
/** Eventually-consistent read model; PostgreSQL remains authoritative for every transition. */
|
|
5
|
+
export class PostgresQueueSnapshot {
|
|
6
|
+
maxCompletedJobs;
|
|
7
|
+
maxJobResults;
|
|
8
|
+
jobs = new Map();
|
|
9
|
+
results;
|
|
10
|
+
queues = new Map();
|
|
11
|
+
knownQueues = new Set();
|
|
12
|
+
completedOrder = new Map();
|
|
13
|
+
constructor(maxCompletedJobs, maxJobResults) {
|
|
14
|
+
this.maxCompletedJobs = maxCompletedJobs;
|
|
15
|
+
this.maxJobResults = maxJobResults;
|
|
16
|
+
this.results = new LRUMap(maxJobResults);
|
|
17
|
+
}
|
|
18
|
+
hydrate(rows) {
|
|
19
|
+
this.jobs.clear();
|
|
20
|
+
this.completedOrder.clear();
|
|
21
|
+
this.knownQueues.clear();
|
|
22
|
+
for (const row of rows)
|
|
23
|
+
this.put(row);
|
|
24
|
+
}
|
|
25
|
+
replaceQueue(queue, rows, state, completions = []) {
|
|
26
|
+
for (const [id, row] of this.jobs) {
|
|
27
|
+
if (row.job.queue === queue)
|
|
28
|
+
this.remove(id);
|
|
29
|
+
}
|
|
30
|
+
this.removeQueueResults(queue);
|
|
31
|
+
for (const row of rows)
|
|
32
|
+
this.put(row);
|
|
33
|
+
for (const completion of completions)
|
|
34
|
+
this.putCompletion(completion);
|
|
35
|
+
this.queues.set(queue, state);
|
|
36
|
+
this.knownQueues.add(queue);
|
|
37
|
+
}
|
|
38
|
+
removeQueue(queue) {
|
|
39
|
+
const removed = [];
|
|
40
|
+
for (const [id, row] of this.jobs) {
|
|
41
|
+
if (row.job.queue !== queue)
|
|
42
|
+
continue;
|
|
43
|
+
this.remove(id);
|
|
44
|
+
removed.push(id);
|
|
45
|
+
}
|
|
46
|
+
this.removeQueueResults(queue);
|
|
47
|
+
this.queues.delete(queue);
|
|
48
|
+
this.knownQueues.delete(queue);
|
|
49
|
+
return removed;
|
|
50
|
+
}
|
|
51
|
+
hydrateResults(entries) {
|
|
52
|
+
this.results.clear();
|
|
53
|
+
for (const entry of entries)
|
|
54
|
+
this.putCompletion(entry);
|
|
55
|
+
}
|
|
56
|
+
put(row) {
|
|
57
|
+
this.knownQueues.add(row.job.queue);
|
|
58
|
+
this.completedOrder.delete(row.job.id);
|
|
59
|
+
this.jobs.set(row.job.id, row);
|
|
60
|
+
this.results.delete(row.job.id);
|
|
61
|
+
if (row.state === 'completed') {
|
|
62
|
+
this.putResult(row.job.id, row.job.queue, row.result);
|
|
63
|
+
this.completedOrder.set(row.job.id, true);
|
|
64
|
+
this.trimCompletedJobs();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
claim(claimed) {
|
|
68
|
+
const current = this.jobs.get(claimed.job.id);
|
|
69
|
+
this.put({
|
|
70
|
+
job: claimed.job,
|
|
71
|
+
state: 'active',
|
|
72
|
+
result: current?.result,
|
|
73
|
+
error: null,
|
|
74
|
+
dlqEntry: null,
|
|
75
|
+
dlqRetryState: current?.dlqRetryState ?? null,
|
|
76
|
+
token: claimed.token,
|
|
77
|
+
leaseOwner: claimed.owner,
|
|
78
|
+
leaseBrokerId: claimed.brokerId,
|
|
79
|
+
leaseUntil: claimed.leaseUntil,
|
|
80
|
+
leaseRenewals: 0,
|
|
81
|
+
version: (current?.version ?? 0) + 1,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
remove(id) {
|
|
85
|
+
this.jobs.delete(id);
|
|
86
|
+
this.completedOrder.delete(id);
|
|
87
|
+
this.results.delete(id);
|
|
88
|
+
}
|
|
89
|
+
reconcile(id, row, completion) {
|
|
90
|
+
if (row) {
|
|
91
|
+
this.put(row);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
this.remove(id);
|
|
95
|
+
if (completion)
|
|
96
|
+
this.putCompletion(completion);
|
|
97
|
+
}
|
|
98
|
+
setQueueState(state) {
|
|
99
|
+
this.queues.set(state.queue, state);
|
|
100
|
+
this.knownQueues.add(state.queue);
|
|
101
|
+
}
|
|
102
|
+
apply(event) {
|
|
103
|
+
if (event.removed || event.type === 'removed') {
|
|
104
|
+
this.remove(event.jobId);
|
|
105
|
+
if (event.type === 'completed' &&
|
|
106
|
+
event.state === 'completed' &&
|
|
107
|
+
Object.hasOwn(event, 'result')) {
|
|
108
|
+
this.putResult(event.jobId, event.queue, event.result);
|
|
109
|
+
}
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (Object.hasOwn(event, 'result'))
|
|
113
|
+
this.putResult(event.jobId, event.queue, event.result);
|
|
114
|
+
if (!event.job || !event.state)
|
|
115
|
+
return;
|
|
116
|
+
const current = this.jobs.get(event.jobId);
|
|
117
|
+
this.put({
|
|
118
|
+
job: event.job,
|
|
119
|
+
state: event.state,
|
|
120
|
+
result: Object.hasOwn(event, 'result') ? event.result : current?.result,
|
|
121
|
+
error: event.error ?? current?.error ?? null,
|
|
122
|
+
dlqEntry: Object.hasOwn(event, 'dlqEntry')
|
|
123
|
+
? (event.dlqEntry ?? null)
|
|
124
|
+
: (current?.dlqEntry ?? null),
|
|
125
|
+
dlqRetryState: Object.hasOwn(event, 'dlqRetryState')
|
|
126
|
+
? (event.dlqRetryState ?? null)
|
|
127
|
+
: (current?.dlqRetryState ?? null),
|
|
128
|
+
token: event.state === 'active' ? (current?.token ?? null) : null,
|
|
129
|
+
leaseOwner: event.state === 'active' ? (current?.leaseOwner ?? null) : null,
|
|
130
|
+
leaseBrokerId: event.state === 'active' ? (current?.leaseBrokerId ?? null) : null,
|
|
131
|
+
leaseUntil: event.state === 'active' ? (current?.leaseUntil ?? null) : null,
|
|
132
|
+
leaseRenewals: event.state === 'active' ? (current?.leaseRenewals ?? 0) : 0,
|
|
133
|
+
version: (current?.version ?? 0) + 1,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
get(id) {
|
|
137
|
+
return this.jobs.get(id) ?? null;
|
|
138
|
+
}
|
|
139
|
+
getResult(id) {
|
|
140
|
+
return this.results.get(id)?.result;
|
|
141
|
+
}
|
|
142
|
+
hasResult(id) {
|
|
143
|
+
return this.results.has(id);
|
|
144
|
+
}
|
|
145
|
+
locations() {
|
|
146
|
+
const locations = new Map();
|
|
147
|
+
for (const [id, row] of this.jobs) {
|
|
148
|
+
if (row.state === 'active') {
|
|
149
|
+
locations.set(id, { type: 'processing', shardIdx: processingShardIndex(id) });
|
|
150
|
+
}
|
|
151
|
+
else if (row.state === 'completed') {
|
|
152
|
+
locations.set(id, { type: 'completed', queueName: row.job.queue });
|
|
153
|
+
}
|
|
154
|
+
else if (row.state === 'failed') {
|
|
155
|
+
locations.set(id, { type: 'dlq', queueName: row.job.queue });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
locations.set(id, {
|
|
159
|
+
type: 'queue',
|
|
160
|
+
shardIdx: shardIndex(row.job.queue),
|
|
161
|
+
queueName: row.job.queue,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return locations;
|
|
166
|
+
}
|
|
167
|
+
completedIds() {
|
|
168
|
+
return new Set([...this.jobs.values()].flatMap((row) => (row.state === 'completed' ? [row.job.id] : [])));
|
|
169
|
+
}
|
|
170
|
+
completionIds() {
|
|
171
|
+
return new Set([...this.completedIds(), ...this.results.keys()]);
|
|
172
|
+
}
|
|
173
|
+
putCompletion(entry) {
|
|
174
|
+
this.putResult(entry.jobId, entry.queue, entry.result);
|
|
175
|
+
}
|
|
176
|
+
putResult(id, queue, result) {
|
|
177
|
+
if (this.maxJobResults === 0)
|
|
178
|
+
return;
|
|
179
|
+
this.results.set(id, { queue, result });
|
|
180
|
+
}
|
|
181
|
+
removeQueueResults(queue) {
|
|
182
|
+
for (const [id, entry] of this.results) {
|
|
183
|
+
if (entry.queue === queue)
|
|
184
|
+
this.results.delete(id);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
trimCompletedJobs() {
|
|
188
|
+
while (this.completedOrder.size > this.maxCompletedJobs) {
|
|
189
|
+
const oldest = this.completedOrder.keys().next().value;
|
|
190
|
+
if (oldest === undefined)
|
|
191
|
+
return;
|
|
192
|
+
this.completedOrder.delete(oldest);
|
|
193
|
+
this.jobs.delete(oldest);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
getByCustomId(customId) {
|
|
197
|
+
return findSnapshotJob(this.jobs, (job) => job.customId === customId);
|
|
198
|
+
}
|
|
199
|
+
getByUniqueKey(queue, key) {
|
|
200
|
+
return findSnapshotJob(this.jobs, (job) => job.queue === queue && job.uniqueKey === key);
|
|
201
|
+
}
|
|
202
|
+
ids(queue, states) {
|
|
203
|
+
return snapshotJobIds(this.jobs, queue, states);
|
|
204
|
+
}
|
|
205
|
+
removeStates(queue, states) {
|
|
206
|
+
let count = 0;
|
|
207
|
+
for (const [id, row] of this.jobs) {
|
|
208
|
+
if (row.job.queue !== queue || !states.includes(row.state))
|
|
209
|
+
continue;
|
|
210
|
+
this.remove(id);
|
|
211
|
+
count++;
|
|
212
|
+
}
|
|
213
|
+
return count;
|
|
214
|
+
}
|
|
215
|
+
queueState(queue) {
|
|
216
|
+
return this.queues.get(queue) ?? null;
|
|
217
|
+
}
|
|
218
|
+
queueNames() {
|
|
219
|
+
return snapshotQueueNames(this.jobs, this.queues, this.knownQueues);
|
|
220
|
+
}
|
|
221
|
+
list(queue, options = {}) {
|
|
222
|
+
return listSnapshotJobs(this.jobs, this.queues, queue, options);
|
|
223
|
+
}
|
|
224
|
+
counts(queue) {
|
|
225
|
+
return countSnapshotJobs(this.jobs, queue);
|
|
226
|
+
}
|
|
227
|
+
priorities(queue) {
|
|
228
|
+
return countSnapshotPriorities(this.jobs, queue);
|
|
229
|
+
}
|
|
230
|
+
dlq(queue, filter) {
|
|
231
|
+
return listSnapshotDlq(this.jobs, queue, filter);
|
|
232
|
+
}
|
|
233
|
+
size() {
|
|
234
|
+
return this.jobs.size;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { DlqEntry, DlqFilter } from '../../domain/types/dlq';
|
|
2
|
+
import type { Job, JobId } from '../../domain/types/job';
|
|
3
|
+
import type { PostgresCounts, PostgresJobState, PostgresQueueState, PostgresStoredJob } from '../../infrastructure/persistence/postgres';
|
|
4
|
+
export declare function findSnapshotJob(jobs: ReadonlyMap<JobId, PostgresStoredJob>, predicate: (job: Job) => boolean): Job | null;
|
|
5
|
+
export declare function snapshotJobIds(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queue: string, states?: readonly PostgresJobState[]): JobId[];
|
|
6
|
+
export declare function snapshotQueueNames(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queues: ReadonlyMap<string, PostgresQueueState>, knownQueues?: ReadonlySet<string>): string[];
|
|
7
|
+
export declare function listSnapshotJobs(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queues: ReadonlyMap<string, PostgresQueueState>, queue: string, options: {
|
|
8
|
+
state?: string | string[];
|
|
9
|
+
start?: number;
|
|
10
|
+
end?: number;
|
|
11
|
+
asc?: boolean;
|
|
12
|
+
}): Job[];
|
|
13
|
+
export declare function countSnapshotJobs(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queue?: string): PostgresCounts;
|
|
14
|
+
export declare function countSnapshotPriorities(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queue: string): Record<number, number>;
|
|
15
|
+
export declare function listSnapshotDlq(jobs: ReadonlyMap<JobId, PostgresStoredJob>, queue: string, filter?: DlqFilter): DlqEntry[];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const EMPTY_COUNTS = {
|
|
2
|
+
waiting: 0,
|
|
3
|
+
prioritized: 0,
|
|
4
|
+
delayed: 0,
|
|
5
|
+
active: 0,
|
|
6
|
+
completed: 0,
|
|
7
|
+
failed: 0,
|
|
8
|
+
waitingChildren: 0,
|
|
9
|
+
};
|
|
10
|
+
function stateMatches(state, requested, paused) {
|
|
11
|
+
if (!requested)
|
|
12
|
+
return true;
|
|
13
|
+
if (requested.includes('paused') && paused) {
|
|
14
|
+
if (state === 'waiting' || state === 'prioritized')
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if (paused && (state === 'waiting' || state === 'prioritized'))
|
|
18
|
+
return false;
|
|
19
|
+
return requested.includes(state);
|
|
20
|
+
}
|
|
21
|
+
function compareIds(left, right) {
|
|
22
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
23
|
+
}
|
|
24
|
+
export function findSnapshotJob(jobs, predicate) {
|
|
25
|
+
for (const row of jobs.values())
|
|
26
|
+
if (predicate(row.job))
|
|
27
|
+
return row.job;
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
export function snapshotJobIds(jobs, queue, states) {
|
|
31
|
+
return [...jobs.values()].flatMap((row) => row.job.queue === queue && (!states || states.includes(row.state)) ? [row.job.id] : []);
|
|
32
|
+
}
|
|
33
|
+
export function snapshotQueueNames(jobs, queues, knownQueues = new Set()) {
|
|
34
|
+
const names = new Set([...knownQueues, ...queues.keys()]);
|
|
35
|
+
for (const row of jobs.values())
|
|
36
|
+
names.add(row.job.queue);
|
|
37
|
+
return [...names].sort();
|
|
38
|
+
}
|
|
39
|
+
export function listSnapshotJobs(jobs, queues, queue, options) {
|
|
40
|
+
const requested = options.state === undefined || (Array.isArray(options.state) && options.state.length === 0)
|
|
41
|
+
? null
|
|
42
|
+
: Array.isArray(options.state)
|
|
43
|
+
? options.state
|
|
44
|
+
: [options.state];
|
|
45
|
+
const paused = queues.get(queue)?.paused ?? false;
|
|
46
|
+
const rows = [...jobs.values()].filter((row) => row.job.queue === queue && stateMatches(row.state, requested, paused));
|
|
47
|
+
const asc = options.asc ?? true;
|
|
48
|
+
rows.sort((left, right) => {
|
|
49
|
+
const created = left.job.createdAt - right.job.createdAt;
|
|
50
|
+
if (created !== 0)
|
|
51
|
+
return asc ? created : -created;
|
|
52
|
+
return asc
|
|
53
|
+
? compareIds(String(left.job.id), String(right.job.id))
|
|
54
|
+
: compareIds(String(right.job.id), String(left.job.id));
|
|
55
|
+
});
|
|
56
|
+
const start = Math.max(0, options.start ?? 0);
|
|
57
|
+
const end = Math.max(start, options.end ?? 100);
|
|
58
|
+
return rows.slice(start, end).map((row) => row.job);
|
|
59
|
+
}
|
|
60
|
+
export function countSnapshotJobs(jobs, queue) {
|
|
61
|
+
const counts = { ...EMPTY_COUNTS };
|
|
62
|
+
for (const row of jobs.values()) {
|
|
63
|
+
if (queue && row.job.queue !== queue)
|
|
64
|
+
continue;
|
|
65
|
+
if (row.state === 'waiting-children')
|
|
66
|
+
counts.waitingChildren++;
|
|
67
|
+
else
|
|
68
|
+
counts[row.state]++;
|
|
69
|
+
}
|
|
70
|
+
return counts;
|
|
71
|
+
}
|
|
72
|
+
export function countSnapshotPriorities(jobs, queue) {
|
|
73
|
+
const counts = {};
|
|
74
|
+
for (const row of jobs.values()) {
|
|
75
|
+
if (row.job.queue !== queue || !['waiting', 'prioritized', 'delayed'].includes(row.state)) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
counts[row.job.priority] = (counts[row.job.priority] ?? 0) + 1;
|
|
79
|
+
}
|
|
80
|
+
return counts;
|
|
81
|
+
}
|
|
82
|
+
export function listSnapshotDlq(jobs, queue, filter) {
|
|
83
|
+
const now = Date.now();
|
|
84
|
+
let entries = [...jobs.values()].flatMap((row) => row.job.queue === queue && row.state === 'failed' && row.dlqEntry ? [row.dlqEntry] : []);
|
|
85
|
+
if (filter?.reason)
|
|
86
|
+
entries = entries.filter((entry) => entry.reason === filter.reason);
|
|
87
|
+
const olderThan = filter?.olderThan;
|
|
88
|
+
const newerThan = filter?.newerThan;
|
|
89
|
+
if (olderThan)
|
|
90
|
+
entries = entries.filter((entry) => entry.enteredAt < olderThan);
|
|
91
|
+
if (newerThan)
|
|
92
|
+
entries = entries.filter((entry) => entry.enteredAt > newerThan);
|
|
93
|
+
if (filter?.expired !== undefined) {
|
|
94
|
+
entries = entries.filter((entry) => (entry.expiresAt !== null && entry.expiresAt <= now) === filter.expired);
|
|
95
|
+
}
|
|
96
|
+
const offset = Math.max(0, filter?.offset ?? 0);
|
|
97
|
+
return entries
|
|
98
|
+
.sort((left, right) => right.enteredAt - left.enteredAt || compareIds(String(right.job.id), String(left.job.id)))
|
|
99
|
+
.slice(offset, offset + Math.max(0, filter?.limit ?? entries.length));
|
|
100
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PostgresDeliveredStoreEvent } from '../../infrastructure/persistence/postgres';
|
|
2
|
+
/** Bounded capture used to reconcile events with an in-flight authoritative snapshot. */
|
|
3
|
+
export declare class PostgresStartupEventBuffer {
|
|
4
|
+
private readonly limit;
|
|
5
|
+
private readonly events;
|
|
6
|
+
private didOverflow;
|
|
7
|
+
constructor(limit?: number);
|
|
8
|
+
get overflowed(): boolean;
|
|
9
|
+
capture(event: PostgresDeliveredStoreEvent): void;
|
|
10
|
+
reset(): void;
|
|
11
|
+
take(): readonly PostgresDeliveredStoreEvent[] | null;
|
|
12
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const DEFAULT_STARTUP_EVENT_LIMIT = 256;
|
|
2
|
+
/** Bounded capture used to reconcile events with an in-flight authoritative snapshot. */
|
|
3
|
+
export class PostgresStartupEventBuffer {
|
|
4
|
+
limit;
|
|
5
|
+
events = [];
|
|
6
|
+
didOverflow = false;
|
|
7
|
+
constructor(limit = DEFAULT_STARTUP_EVENT_LIMIT) {
|
|
8
|
+
this.limit = limit;
|
|
9
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
10
|
+
throw new RangeError('PostgreSQL startup event buffer limit must be a positive integer');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
get overflowed() {
|
|
14
|
+
return this.didOverflow;
|
|
15
|
+
}
|
|
16
|
+
capture(event) {
|
|
17
|
+
if (this.didOverflow)
|
|
18
|
+
return;
|
|
19
|
+
if (this.events.length === this.limit) {
|
|
20
|
+
this.didOverflow = true;
|
|
21
|
+
this.events.length = 0;
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
this.events.push(event);
|
|
25
|
+
}
|
|
26
|
+
reset() {
|
|
27
|
+
this.events.length = 0;
|
|
28
|
+
this.didOverflow = false;
|
|
29
|
+
}
|
|
30
|
+
take() {
|
|
31
|
+
if (this.didOverflow)
|
|
32
|
+
return null;
|
|
33
|
+
const captured = this.events.splice(0);
|
|
34
|
+
return captured;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { JobId } from '../../domain/types/job';
|
|
2
|
+
import { PostgresQueueStore, type PostgresStoredJob } from '../../infrastructure/persistence/postgres';
|
|
3
|
+
import { QueueManager } from '../queueManager';
|
|
4
|
+
import type { PostgresQueueManagerConfig } from './config';
|
|
5
|
+
import { PostgresQueueSnapshot } from './snapshot';
|
|
6
|
+
import { PostgresOperationGate } from './operationGate';
|
|
7
|
+
export declare abstract class PostgresQueueManagerState extends QueueManager {
|
|
8
|
+
protected readonly postgresStore: PostgresQueueStore;
|
|
9
|
+
protected readonly postgresSnapshot: PostgresQueueSnapshot;
|
|
10
|
+
protected readonly activeTokens: Map<JobId, string>;
|
|
11
|
+
protected readonly postgresReady: Promise<void>;
|
|
12
|
+
private readonly refreshes;
|
|
13
|
+
private readonly dirtyQueues;
|
|
14
|
+
private readonly queueEventVersions;
|
|
15
|
+
private snapshotEventBuffer;
|
|
16
|
+
private terminalMetricBaselineCommitSeq;
|
|
17
|
+
private readonly unsubscribeEvent;
|
|
18
|
+
private readonly unsubscribeInvalidation;
|
|
19
|
+
private readonly writes;
|
|
20
|
+
protected readonly operations: PostgresOperationGate;
|
|
21
|
+
private readonly projectionRefreshes;
|
|
22
|
+
private shutdownPromise;
|
|
23
|
+
private shutdownComplete;
|
|
24
|
+
private baseStopped;
|
|
25
|
+
private stopQueueRefreshes;
|
|
26
|
+
constructor(config: PostgresQueueManagerConfig);
|
|
27
|
+
waitUntilReady(): Promise<void>;
|
|
28
|
+
flushPostgresWrites(): Promise<void>;
|
|
29
|
+
shutdownPostgres(): Promise<void>;
|
|
30
|
+
shutdown(): void;
|
|
31
|
+
private performPostgresShutdown;
|
|
32
|
+
protected tokenFor(id: JobId, token?: string): string | null;
|
|
33
|
+
protected forgetToken(id: JobId): void;
|
|
34
|
+
protected runPostgresOperation<T>(operation: () => Promise<T>): Promise<T>;
|
|
35
|
+
protected refreshJob(id: JobId, queue?: string): Promise<void>;
|
|
36
|
+
protected fetchPostgresJob(id: JobId): Promise<PostgresStoredJob | null>;
|
|
37
|
+
protected refreshJobs(ids: readonly JobId[], queue?: string): Promise<void>;
|
|
38
|
+
protected refreshQueue(queue: string): Promise<boolean>;
|
|
39
|
+
protected refreshQueueAfterCommit(queue: string): Promise<void>;
|
|
40
|
+
protected enqueueWrite(operation: () => Promise<void>): void;
|
|
41
|
+
private initializePostgres;
|
|
42
|
+
private scheduleQueueRefresh;
|
|
43
|
+
private refreshDirtyQueue;
|
|
44
|
+
private onStoreEvent;
|
|
45
|
+
protected applyPostgresClaim(claim: Parameters<PostgresQueueSnapshot['claim']>[0]): void;
|
|
46
|
+
private stopBaseRuntime;
|
|
47
|
+
}
|