bunqueue-client 0.1.9 → 0.2.0
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/CHANGELOG.md +150 -0
- package/LEGACY.md +460 -0
- package/README.md +204 -349
- package/dist/ack-batcher.js +7 -67
- package/dist/canonical-manifest.json +930 -0
- package/dist/chunk-b967v3w3.js +79 -0
- package/dist/chunk-fekm0ma6.js +110 -0
- package/dist/chunk-jxkszwqp.js +573 -0
- package/dist/embedded.js +16418 -0
- package/dist/frame.js +14 -57
- package/dist/index.d.ts +1 -27
- package/dist/index.js +10905 -16
- package/dist/legacy.d.ts +1 -0
- package/dist/legacy.js +2081 -0
- package/dist/{ack-batcher.d.ts → types/sdk/typescript/src/ack-batcher.d.ts} +3 -3
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/aging.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/batch.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue-api.d.ts +5 -5
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/bunqueue.d.ts +13 -13
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/circuit-breaker.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dedup-debounce.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/dlq-rate-limit.d.ts +2 -2
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/rate-gate.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/retry.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/triggers.d.ts +3 -3
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/ttl.d.ts +1 -1
- package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/types.d.ts +4 -4
- package/dist/types/sdk/typescript/src/canonical-transport/bun-sqlite-types.d.ts +21 -0
- package/dist/{connection-pool.d.ts → types/sdk/typescript/src/connection-pool.d.ts} +1 -1
- package/dist/{connection-types.d.ts → types/sdk/typescript/src/connection-types.d.ts} +1 -1
- package/dist/{connection.d.ts → types/sdk/typescript/src/connection.d.ts} +6 -19
- package/dist/{errors.d.ts → types/sdk/typescript/src/errors.d.ts} +3 -0
- package/dist/types/sdk/typescript/src/flow-commit.d.ts +5 -0
- package/dist/types/sdk/typescript/src/flow-plan-legacy.d.ts +13 -0
- package/dist/types/sdk/typescript/src/flow-plan.d.ts +29 -0
- package/dist/{flow-types.d.ts → types/sdk/typescript/src/flow-types.d.ts} +7 -4
- package/dist/{flow.d.ts → types/sdk/typescript/src/flow.d.ts} +6 -10
- package/dist/{frame.d.ts → types/sdk/typescript/src/frame.d.ts} +1 -1
- package/dist/types/sdk/typescript/src/index.d.ts +10 -0
- package/dist/{job.d.ts → types/sdk/typescript/src/job.d.ts} +4 -3
- package/dist/types/sdk/typescript/src/legacy.d.ts +27 -0
- package/dist/{observability.d.ts → types/sdk/typescript/src/observability.d.ts} +14 -0
- package/dist/{queue-admin.d.ts → types/sdk/typescript/src/queue-admin.d.ts} +3 -4
- package/dist/{queue-control.d.ts → types/sdk/typescript/src/queue-control.d.ts} +5 -5
- package/dist/{queue-query.d.ts → types/sdk/typescript/src/queue-query.d.ts} +3 -3
- package/dist/{queue.d.ts → types/sdk/typescript/src/queue.d.ts} +8 -8
- package/dist/{responses.d.ts → types/sdk/typescript/src/responses.d.ts} +2 -2
- package/dist/types/sdk/typescript/src/serialization.d.ts +10 -0
- package/dist/{socket-factory.d.ts → types/sdk/typescript/src/socket-factory.d.ts} +1 -1
- package/dist/types/sdk/typescript/src/terminal-outcome.d.ts +8 -0
- package/dist/{types.d.ts → types/sdk/typescript/src/types.d.ts} +5 -2
- package/dist/{worker-base.d.ts → types/sdk/typescript/src/worker-base.d.ts} +6 -6
- package/dist/types/sdk/typescript/src/worker-slot-signal.d.ts +6 -0
- package/dist/{worker-types.d.ts → types/sdk/typescript/src/worker-types.d.ts} +3 -3
- package/dist/{worker.d.ts → types/sdk/typescript/src/worker.d.ts} +3 -2
- package/dist/types/src/application/background/dlq.d.ts +2 -0
- package/dist/types/src/application/background/lifecycle.d.ts +4 -0
- package/dist/types/src/application/background/recovery/active.d.ts +5 -0
- package/dist/types/src/application/background/recovery/index.d.ts +2 -0
- package/dist/types/src/application/background/recovery/pending.d.ts +3 -0
- package/dist/types/src/application/background/recovery/restore.d.ts +5 -0
- package/dist/types/src/application/background/recovery/shared.d.ts +6 -0
- package/dist/types/src/application/background/timeouts.d.ts +25 -0
- package/dist/types/src/application/backgroundTasks.d.ts +7 -0
- package/dist/types/src/application/cleanupTasks.d.ts +10 -0
- package/dist/types/src/application/clientTracking.d.ts +44 -0
- package/dist/types/src/application/completedCleanup.d.ts +34 -0
- package/dist/types/src/application/completedRetry.d.ts +21 -0
- package/dist/types/src/application/contextFactory.d.ts +49 -0
- package/dist/types/src/application/dependencyCompletions.d.ts +63 -0
- package/dist/types/src/application/dependencyProcessor.d.ts +15 -0
- package/dist/types/src/application/dependencyResultTracker.d.ts +18 -0
- package/dist/types/src/application/dlqManager.d.ts +49 -0
- package/dist/types/src/application/dlqRetry.d.ts +12 -0
- package/dist/types/src/application/emptyQueueCleanup.d.ts +3 -0
- package/dist/types/src/application/eventsManager.d.ts +50 -0
- package/dist/types/src/application/flowFailureRecovery.d.ts +20 -0
- package/dist/types/src/application/flowParentBackpatch.d.ts +27 -0
- package/dist/types/src/application/jobLogsManager.d.ts +21 -0
- package/dist/types/src/application/latencyTracker.d.ts +39 -0
- package/dist/types/src/application/lockManager.d.ts +15 -0
- package/dist/types/src/application/lockOperations.d.ts +38 -0
- package/dist/types/src/application/metricsExporter.d.ts +27 -0
- package/dist/types/src/application/monitoringChecks.d.ts +36 -0
- package/dist/types/src/application/operations/ack/batch.d.ts +8 -0
- package/dist/types/src/application/operations/ack/completion.d.ts +3 -0
- package/dist/types/src/application/operations/ack/failure.d.ts +3 -0
- package/dist/types/src/application/operations/ack.d.ts +5 -0
- package/dist/types/src/application/operations/ackHelpers.d.ts +36 -0
- package/dist/types/src/application/operations/customId.d.ts +51 -0
- package/dist/types/src/application/operations/flowPush.d.ts +9 -0
- package/dist/types/src/application/operations/flowTopologyValidation.d.ts +3 -0
- package/dist/types/src/application/operations/flowValidation.d.ts +3 -0
- package/dist/types/src/application/operations/jobClaim.d.ts +17 -0
- package/dist/types/src/application/operations/jobManagement.d.ts +43 -0
- package/dist/types/src/application/operations/jobMoveOperations.d.ts +9 -0
- package/dist/types/src/application/operations/jobPromotion.d.ts +7 -0
- package/dist/types/src/application/operations/jobStateTransitions.d.ts +15 -0
- package/dist/types/src/application/operations/parentLink.d.ts +36 -0
- package/dist/types/src/application/operations/parentLinkInput.d.ts +8 -0
- package/dist/types/src/application/operations/pull.d.ts +20 -0
- package/dist/types/src/application/operations/pullFinalization.d.ts +6 -0
- package/dist/types/src/application/operations/pullStateTransition.d.ts +51 -0
- package/dist/types/src/application/operations/push.d.ts +13 -0
- package/dist/types/src/application/operations/pushAdmission.d.ts +36 -0
- package/dist/types/src/application/operations/pushBatch.d.ts +4 -0
- package/dist/types/src/application/operations/pushContext.d.ts +48 -0
- package/dist/types/src/application/operations/pushDeduplication.d.ts +42 -0
- package/dist/types/src/application/operations/pushInsert.d.ts +39 -0
- package/dist/types/src/application/operations/pushLocks.d.ts +15 -0
- package/dist/types/src/application/operations/query/collect.d.ts +12 -0
- package/dist/types/src/application/operations/query/jobLookup.d.ts +9 -0
- package/dist/types/src/application/operations/query/pagination.d.ts +8 -0
- package/dist/types/src/application/operations/query/state.d.ts +4 -0
- package/dist/types/src/application/operations/queryOperations.d.ts +5 -0
- package/dist/types/src/application/operations/queueControl.d.ts +50 -0
- package/dist/types/src/application/prometheusOperationalMetrics.d.ts +31 -0
- package/dist/types/src/application/queue-manager/ack.d.ts +23 -0
- package/dist/types/src/application/queue-manager/configuration.d.ts +27 -0
- package/dist/types/src/application/queue-manager/context.d.ts +5 -0
- package/dist/types/src/application/queue-manager/control.d.ts +20 -0
- package/dist/types/src/application/queue-manager/delivery.d.ts +33 -0
- package/dist/types/src/application/queue-manager/dependencies.d.ts +8 -0
- package/dist/types/src/application/queue-manager/dependency-runtime.d.ts +8 -0
- package/dist/types/src/application/queue-manager/flow-failures.d.ts +18 -0
- package/dist/types/src/application/queue-manager/flow-options.d.ts +8 -0
- package/dist/types/src/application/queue-manager/job-management.d.ts +17 -0
- package/dist/types/src/application/queue-manager/lifecycle.d.ts +4 -0
- package/dist/types/src/application/queue-manager/limits.d.ts +58 -0
- package/dist/types/src/application/queue-manager/locks.d.ts +21 -0
- package/dist/types/src/application/queue-manager/observability.d.ts +16 -0
- package/dist/types/src/application/queue-manager/queries.d.ts +24 -0
- package/dist/types/src/application/queue-manager/repeat.d.ts +4 -0
- package/dist/types/src/application/queue-manager/services.d.ts +19 -0
- package/dist/types/src/application/queue-manager/state.d.ts +96 -0
- package/dist/types/src/application/queue-manager/stats.d.ts +28 -0
- package/dist/types/src/application/queueManager.d.ts +5 -0
- package/dist/types/src/application/queueStatsAggregator.d.ts +23 -0
- package/dist/types/src/application/queueTelemetryJournal.d.ts +24 -0
- package/dist/types/src/application/repeatJobs.d.ts +7 -0
- package/dist/types/src/application/stallDetection.d.ts +10 -0
- package/dist/types/src/application/statsManager.d.ts +59 -0
- package/dist/types/src/application/taskErrorTracking.d.ts +22 -0
- package/dist/types/src/application/throughputTracker.d.ts +34 -0
- package/dist/types/src/application/types/ack.d.ts +136 -0
- package/dist/types/src/application/types/background.d.ts +18 -0
- package/dist/types/src/application/types/config.d.ts +41 -0
- package/dist/types/src/application/types/contextFactory.d.ts +87 -0
- package/dist/types/src/application/types/contexts.d.ts +114 -0
- package/dist/types/src/application/types/index.d.ts +7 -0
- package/dist/types/src/application/types/query.d.ts +23 -0
- package/dist/types/src/application/types/queueManager.d.ts +98 -0
- package/dist/types/src/application/webhookManager.d.ts +47 -0
- package/dist/types/src/application/workerManager.d.ts +61 -0
- package/dist/types/src/client/bunqueue/aging.d.ts +16 -0
- package/dist/types/src/client/bunqueue/batch.d.ts +16 -0
- package/dist/types/src/client/bunqueue/cancellation.d.ts +21 -0
- package/dist/types/src/client/bunqueue/circuitBreaker.d.ts +21 -0
- package/dist/types/src/client/bunqueue/dedupDebounce.d.ts +12 -0
- package/dist/types/src/client/bunqueue/dlqRateLimit.d.ts +26 -0
- package/dist/types/src/client/bunqueue/retry.d.ts +8 -0
- package/dist/types/src/client/bunqueue/runtime.d.ts +35 -0
- package/dist/types/src/client/bunqueue/triggers.d.ts +17 -0
- package/dist/types/src/client/bunqueue/ttl.d.ts +17 -0
- package/dist/types/src/client/bunqueue/types.d.ts +147 -0
- package/dist/types/src/client/bunqueue.d.ts +73 -0
- package/dist/types/src/client/dlqConversion.d.ts +5 -0
- package/dist/types/src/client/errors.d.ts +24 -0
- package/dist/types/src/client/events.d.ts +85 -0
- package/dist/types/src/client/flow.d.ts +70 -0
- package/dist/types/src/client/flowAtomic.d.ts +9 -0
- package/dist/types/src/client/flowJobCoreMethods.d.ts +28 -0
- package/dist/types/src/client/flowJobDependencies.d.ts +7 -0
- package/dist/types/src/client/flowJobFactory.d.ts +24 -0
- package/dist/types/src/client/flowJobMoveMethods.d.ts +16 -0
- package/dist/types/src/client/flowJobTypes.d.ts +29 -0
- package/dist/types/src/client/flowLegacyPlan.d.ts +16 -0
- package/dist/types/src/client/flowOptions.d.ts +10 -0
- package/dist/types/src/client/flowPlan.d.ts +16 -0
- package/dist/types/src/client/flowPush.d.ts +27 -0
- package/dist/types/src/client/flowReader.d.ts +10 -0
- package/dist/types/src/client/flowResults.d.ts +11 -0
- package/dist/types/src/client/flowTypes.d.ts +77 -0
- package/dist/types/src/client/forwarder.d.ts +74 -0
- package/dist/types/src/client/groupId.d.ts +1 -0
- package/dist/types/src/client/index.d.ts +46 -0
- package/dist/types/src/client/jobConversion.d.ts +10 -0
- package/dist/types/src/client/jobConversionHelpers.d.ts +28 -0
- package/dist/types/src/client/jobConversionTypes.d.ts +88 -0
- package/dist/types/src/client/jobDeduplication.d.ts +6 -0
- package/dist/types/src/client/jobHelpers.d.ts +31 -0
- package/dist/types/src/client/legacyConnectionOptions.d.ts +8 -0
- package/dist/types/src/client/manager.d.ts +15 -0
- package/dist/types/src/client/pro.d.ts +9 -0
- package/dist/types/src/client/queue/addBatcher.d.ts +59 -0
- package/dist/types/src/client/queue/bullmqCompat.d.ts +57 -0
- package/dist/types/src/client/queue/deduplication.d.ts +14 -0
- package/dist/types/src/client/queue/dlq.d.ts +61 -0
- package/dist/types/src/client/queue/dlqJobMethods.d.ts +9 -0
- package/dist/types/src/client/queue/dlqOps.d.ts +26 -0
- package/dist/types/src/client/queue/dlqStats.d.ts +3 -0
- package/dist/types/src/client/queue/failWire.d.ts +17 -0
- package/dist/types/src/client/queue/helpers.d.ts +19 -0
- package/dist/types/src/client/queue/job-proxy/dependencies.d.ts +9 -0
- package/dist/types/src/client/queue/job-proxy/reflection.d.ts +2 -0
- package/dist/types/src/client/queue/job-proxy/simple.d.ts +3 -0
- package/dist/types/src/client/queue/job-proxy/tcp.d.ts +4 -0
- package/dist/types/src/client/queue/jobMetadata.d.ts +10 -0
- package/dist/types/src/client/queue/jobMove.d.ts +32 -0
- package/dist/types/src/client/queue/jobProxy.d.ts +4 -0
- package/dist/types/src/client/queue/operations/add/bulk.d.ts +7 -0
- package/dist/types/src/client/queue/operations/add/payload.d.ts +25 -0
- package/dist/types/src/client/queue/operations/add/single.d.ts +3 -0
- package/dist/types/src/client/queue/operations/add.d.ts +2 -0
- package/dist/types/src/client/queue/operations/control.d.ts +42 -0
- package/dist/types/src/client/queue/operations/counts.d.ts +48 -0
- package/dist/types/src/client/queue/operations/groups.d.ts +24 -0
- package/dist/types/src/client/queue/operations/management.d.ts +51 -0
- package/dist/types/src/client/queue/operations/query.d.ts +50 -0
- package/dist/types/src/client/queue/operations/queryStates.d.ts +13 -0
- package/dist/types/src/client/queue/operations/queryTcpPages.d.ts +14 -0
- package/dist/types/src/client/queue/queue.d.ts +12 -0
- package/dist/types/src/client/queue/rateLimit.d.ts +46 -0
- package/dist/types/src/client/queue/runtime/compatibility.d.ts +13 -0
- package/dist/types/src/client/queue/runtime/configuration.d.ts +46 -0
- package/dist/types/src/client/queue/runtime/connection.d.ts +6 -0
- package/dist/types/src/client/queue/runtime/control.d.ts +41 -0
- package/dist/types/src/client/queue/runtime/queries.d.ts +66 -0
- package/dist/types/src/client/queue/runtime/scheduling.d.ts +33 -0
- package/dist/types/src/client/queue/runtime/state.d.ts +101 -0
- package/dist/types/src/client/queue/scheduler.d.ts +58 -0
- package/dist/types/src/client/queue/schedulerPagination.d.ts +7 -0
- package/dist/types/src/client/queue/stall.d.ts +20 -0
- package/dist/types/src/client/queue/types/add.d.ts +40 -0
- package/dist/types/src/client/queue/types/contexts.d.ts +33 -0
- package/dist/types/src/client/queue/types/index.d.ts +3 -0
- package/dist/types/src/client/queue/types/job.d.ts +50 -0
- package/dist/types/src/client/queue/types/runtime.d.ts +35 -0
- package/dist/types/src/client/queue/workers.d.ts +36 -0
- package/dist/types/src/client/queue-events/tcpSubscription.d.ts +23 -0
- package/dist/types/src/client/queue.d.ts +5 -0
- package/dist/types/src/client/queueGroup.d.ts +51 -0
- package/dist/types/src/client/resolveToken.d.ts +10 -0
- package/dist/types/src/client/sandboxed/index.d.ts +7 -0
- package/dist/types/src/client/sandboxed/queueOps.d.ts +24 -0
- package/dist/types/src/client/sandboxed/runtime/dispatch.d.ts +13 -0
- package/dist/types/src/client/sandboxed/runtime/lifecycle.d.ts +20 -0
- package/dist/types/src/client/sandboxed/runtime/log.d.ts +1 -0
- package/dist/types/src/client/sandboxed/runtime/pool.d.ts +11 -0
- package/dist/types/src/client/sandboxed/runtime/recovery.d.ts +11 -0
- package/dist/types/src/client/sandboxed/runtime/state.d.ts +39 -0
- package/dist/types/src/client/sandboxed/types/index.d.ts +2 -0
- package/dist/types/src/client/sandboxed/types/options.d.ts +27 -0
- package/dist/types/src/client/sandboxed/types/process.d.ts +39 -0
- package/dist/types/src/client/sandboxed/worker.d.ts +4 -0
- package/dist/types/src/client/sandboxed/wrapper.d.ts +12 -0
- package/dist/types/src/client/sandboxedWorker.d.ts +6 -0
- package/dist/types/src/client/tcp/client.d.ts +6 -0
- package/dist/types/src/client/tcp/commandQueue.d.ts +23 -0
- package/dist/types/src/client/tcp/connection.d.ts +4 -0
- package/dist/types/src/client/tcp/errors.d.ts +6 -0
- package/dist/types/src/client/tcp/health.d.ts +60 -0
- package/dist/types/src/client/tcp/index.d.ts +11 -0
- package/dist/types/src/client/tcp/reconnect.d.ts +47 -0
- package/dist/types/src/client/tcp/runtime/commands.d.ts +9 -0
- package/dist/types/src/client/tcp/runtime/connectivity.d.ts +13 -0
- package/dist/types/src/client/tcp/runtime/health.d.ts +14 -0
- package/dist/types/src/client/tcp/runtime/lifecycle.d.ts +8 -0
- package/dist/types/src/client/tcp/runtime/state.d.ts +50 -0
- package/dist/types/src/client/tcp/shared.d.ts +12 -0
- package/dist/types/src/client/tcp/transport.d.ts +18 -0
- package/dist/types/src/client/tcp/types/command.d.ts +9 -0
- package/dist/types/src/client/tcp/types/connection.d.ts +31 -0
- package/dist/types/src/client/tcp/types/index.d.ts +5 -0
- package/dist/types/src/client/tcp/types/socket.d.ts +8 -0
- package/dist/types/src/client/tcp/types/tls.d.ts +4 -0
- package/dist/types/src/client/tcp/types.d.ts +2 -0
- package/dist/types/src/client/tcpClient.d.ts +6 -0
- package/dist/types/src/client/tcpPool.d.ts +69 -0
- package/dist/types/src/client/types/connection.d.ts +30 -0
- package/dist/types/src/client/types/dlq.d.ts +45 -0
- package/dist/types/src/client/types/events.d.ts +54 -0
- package/dist/types/src/client/types/flow.d.ts +22 -0
- package/dist/types/src/client/types/index.d.ts +10 -0
- package/dist/types/src/client/types/job.d.ts +131 -0
- package/dist/types/src/client/types/metrics.d.ts +1 -0
- package/dist/types/src/client/types/options.d.ts +70 -0
- package/dist/types/src/client/types/worker.d.ts +54 -0
- package/dist/types/src/client/types.d.ts +2 -0
- package/dist/types/src/client/worker/ackBatcher.d.ts +55 -0
- package/dist/types/src/client/worker/ackFrontier.d.ts +21 -0
- package/dist/types/src/client/worker/ackOutcome.d.ts +8 -0
- package/dist/types/src/client/worker/batchExecution.d.ts +14 -0
- package/dist/types/src/client/worker/constants.d.ts +7 -0
- package/dist/types/src/client/worker/groupConcurrency.d.ts +49 -0
- package/dist/types/src/client/worker/handlers/completion.d.ts +29 -0
- package/dist/types/src/client/worker/handlers/dependencies.d.ts +11 -0
- package/dist/types/src/client/worker/handlers/mutations.d.ts +23 -0
- package/dist/types/src/client/worker/handlers/queries.d.ts +15 -0
- package/dist/types/src/client/worker/jobParser.d.ts +9 -0
- package/dist/types/src/client/worker/processor.d.ts +11 -0
- package/dist/types/src/client/worker/processorHandlers.d.ts +4 -0
- package/dist/types/src/client/worker/processorOutcome.d.ts +14 -0
- package/dist/types/src/client/worker/processorResult.d.ts +2 -0
- package/dist/types/src/client/worker/runtime/buffer.d.ts +8 -0
- package/dist/types/src/client/worker/runtime/control.d.ts +28 -0
- package/dist/types/src/client/worker/runtime/execution.d.ts +16 -0
- package/dist/types/src/client/worker/runtime/lifecycle.d.ts +7 -0
- package/dist/types/src/client/worker/runtime/manual.d.ts +10 -0
- package/dist/types/src/client/worker/runtime/options.d.ts +5 -0
- package/dist/types/src/client/worker/runtime/polling.d.ts +14 -0
- package/dist/types/src/client/worker/runtime/state.d.ts +121 -0
- package/dist/types/src/client/worker/types/index.d.ts +5 -0
- package/dist/types/src/client/worker/types/manual.d.ts +7 -0
- package/dist/types/src/client/worker/types/options.d.ts +26 -0
- package/dist/types/src/client/worker/types/outcome.d.ts +23 -0
- package/dist/types/src/client/worker/types/processor.d.ts +25 -0
- package/dist/types/src/client/worker/types/transport.d.ts +11 -0
- package/dist/types/src/client/worker/worker.d.ts +6 -0
- package/dist/types/src/client/worker/workerHeartbeat.d.ts +15 -0
- package/dist/types/src/client/worker/workerPull.d.ts +24 -0
- package/dist/types/src/client/worker/workerRateLimiter.d.ts +51 -0
- package/dist/types/src/client/worker.d.ts +6 -0
- package/dist/types/src/client/workflow/admission.d.ts +45 -0
- package/dist/types/src/client/workflow/clock.d.ts +60 -0
- package/dist/types/src/client/workflow/compensationChild.d.ts +33 -0
- package/dist/types/src/client/workflow/compensationClaim.d.ts +11 -0
- package/dist/types/src/client/workflow/compensationPass.d.ts +17 -0
- package/dist/types/src/client/workflow/compensationSupport.d.ts +24 -0
- package/dist/types/src/client/workflow/compensator.d.ts +34 -0
- package/dist/types/src/client/workflow/definitionGuard.d.ts +11 -0
- package/dist/types/src/client/workflow/emitter.d.ts +17 -0
- package/dist/types/src/client/workflow/engine.d.ts +66 -0
- package/dist/types/src/client/workflow/eventTypes.d.ts +44 -0
- package/dist/types/src/client/workflow/executionFence.d.ts +15 -0
- package/dist/types/src/client/workflow/executionTypes.d.ts +133 -0
- package/dist/types/src/client/workflow/executor.d.ts +52 -0
- package/dist/types/src/client/workflow/executorLifecycle.d.ts +19 -0
- package/dist/types/src/client/workflow/executorNodes.d.ts +18 -0
- package/dist/types/src/client/workflow/executorQueue.d.ts +9 -0
- package/dist/types/src/client/workflow/forEachRunner.d.ts +4 -0
- package/dist/types/src/client/workflow/identity.d.ts +48 -0
- package/dist/types/src/client/workflow/index.d.ts +23 -0
- package/dist/types/src/client/workflow/loops.d.ts +11 -0
- package/dist/types/src/client/workflow/mapRunner.d.ts +4 -0
- package/dist/types/src/client/workflow/recovery.d.ts +32 -0
- package/dist/types/src/client/workflow/rollbackControl.d.ts +37 -0
- package/dist/types/src/client/workflow/runner.d.ts +23 -0
- package/dist/types/src/client/workflow/runnerTiming.d.ts +14 -0
- package/dist/types/src/client/workflow/stepTypes.d.ts +171 -0
- package/dist/types/src/client/workflow/store.d.ts +83 -0
- package/dist/types/src/client/workflow/storeCodec.d.ts +7 -0
- package/dist/types/src/client/workflow/storeExecutionCodec.d.ts +11 -0
- package/dist/types/src/client/workflow/storeListing.d.ts +11 -0
- package/dist/types/src/client/workflow/storeMaintenance.d.ts +4 -0
- package/dist/types/src/client/workflow/storeSignals.d.ts +70 -0
- package/dist/types/src/client/workflow/subWorkflowRunner.d.ts +14 -0
- package/dist/types/src/client/workflow/types.d.ts +4 -0
- package/dist/types/src/client/workflow/unwindPlan.d.ts +87 -0
- package/dist/types/src/client/workflow/waitFor.d.ts +56 -0
- package/dist/types/src/client/workflow/workflow.d.ts +70 -0
- package/dist/types/src/client/workflow/workflowDecisions.d.ts +11 -0
- package/dist/types/src/client/workflow/workflowDefinition.d.ts +16 -0
- package/dist/types/src/client/workflow/workflowIntrospection.d.ts +5 -0
- package/dist/types/src/client/workflow/workflowValidation.d.ts +44 -0
- package/dist/types/src/config/index.d.ts +9 -0
- package/dist/types/src/config/loader.d.ts +7 -0
- package/dist/types/src/config/resolve.d.ts +59 -0
- package/dist/types/src/config/types.d.ts +88 -0
- package/dist/types/src/domain/job/constants.d.ts +12 -0
- package/dist/types/src/domain/job/create.d.ts +2 -0
- package/dist/types/src/domain/job/groupFifoOrder.d.ts +9 -0
- package/dist/types/src/domain/job/ids.d.ts +7 -0
- package/dist/types/src/domain/job/locks.d.ts +4 -0
- package/dist/types/src/domain/job/payload.d.ts +18 -0
- package/dist/types/src/domain/job/state.d.ts +8 -0
- package/dist/types/src/domain/job/terminal.d.ts +3 -0
- package/dist/types/src/domain/queue/dependencyTracker.d.ts +78 -0
- package/dist/types/src/domain/queue/dlqShard.d.ts +66 -0
- package/dist/types/src/domain/queue/groupLimiterManager.d.ts +30 -0
- package/dist/types/src/domain/queue/groupScheduler.d.ts +31 -0
- package/dist/types/src/domain/queue/groupSchedulerOrder.d.ts +6 -0
- package/dist/types/src/domain/queue/limiterManager.d.ts +68 -0
- package/dist/types/src/domain/queue/priorityQueue.d.ts +54 -0
- package/dist/types/src/domain/queue/priorityQueueOrder.d.ts +3 -0
- package/dist/types/src/domain/queue/shard/dependencies.d.ts +11 -0
- package/dist/types/src/domain/queue/shard/dlq.d.ts +26 -0
- package/dist/types/src/domain/queue/shard/keys.d.ts +19 -0
- package/dist/types/src/domain/queue/shard/lifecycle.d.ts +10 -0
- package/dist/types/src/domain/queue/shard/limits.d.ts +47 -0
- package/dist/types/src/domain/queue/shard/metrics.d.ts +32 -0
- package/dist/types/src/domain/queue/shard/state.d.ts +40 -0
- package/dist/types/src/domain/queue/shard.d.ts +7 -0
- package/dist/types/src/domain/queue/shardCounters.d.ts +35 -0
- package/dist/types/src/domain/queue/temporalIndex.d.ts +24 -0
- package/dist/types/src/domain/queue/temporalManager.d.ts +72 -0
- package/dist/types/src/domain/queue/uniqueKeyManager.d.ts +33 -0
- package/dist/types/src/domain/queue/waiterManager.d.ts +18 -0
- package/dist/types/src/domain/response/builders.d.ts +15 -0
- package/dist/types/src/domain/types/command.d.ts +2 -0
- package/dist/types/src/domain/types/commands/base.d.ts +5 -0
- package/dist/types/src/domain/types/commands/core.d.ts +110 -0
- package/dist/types/src/domain/types/commands/cron.d.ts +36 -0
- package/dist/types/src/domain/types/commands/dashboard.d.ts +13 -0
- package/dist/types/src/domain/types/commands/dlq.d.ts +44 -0
- package/dist/types/src/domain/types/commands/extended.d.ts +63 -0
- package/dist/types/src/domain/types/commands/index.d.ts +12 -0
- package/dist/types/src/domain/types/commands/limits.d.ts +108 -0
- package/dist/types/src/domain/types/commands/management.d.ts +73 -0
- package/dist/types/src/domain/types/commands/monitoring.d.ts +49 -0
- package/dist/types/src/domain/types/commands/protocol.d.ts +20 -0
- package/dist/types/src/domain/types/commands/query.d.ts +46 -0
- package/dist/types/src/domain/types/commands/union.d.ts +13 -0
- package/dist/types/src/domain/types/commands/workers.d.ts +39 -0
- package/dist/types/src/domain/types/cron.d.ts +91 -0
- package/dist/types/src/domain/types/deduplication.d.ts +43 -0
- package/dist/types/src/domain/types/dlq.d.ts +136 -0
- package/dist/types/src/domain/types/flow.d.ts +25 -0
- package/dist/types/src/domain/types/group.d.ts +26 -0
- package/dist/types/src/domain/types/job.d.ts +8 -0
- package/dist/types/src/domain/types/jobs/model.d.ts +153 -0
- package/dist/types/src/domain/types/metrics.d.ts +16 -0
- package/dist/types/src/domain/types/priorityQueue.d.ts +13 -0
- package/dist/types/src/domain/types/protocol.d.ts +5 -0
- package/dist/types/src/domain/types/queue.d.ts +110 -0
- package/dist/types/src/domain/types/response.d.ts +3 -0
- package/dist/types/src/domain/types/responses/model.d.ts +152 -0
- package/dist/types/src/domain/types/shard.d.ts +4 -0
- package/dist/types/src/domain/types/stall.d.ts +48 -0
- package/dist/types/src/domain/types/webhook.d.ts +42 -0
- package/dist/types/src/domain/types/worker.d.ts +40 -0
- package/dist/types/src/infrastructure/backup/backupTelemetry.d.ts +30 -0
- package/dist/types/src/infrastructure/backup/s3BackupConfig.d.ts +80 -0
- package/dist/types/src/infrastructure/cloud/types/config.d.ts +18 -0
- package/dist/types/src/infrastructure/cloud/types/event.d.ts +14 -0
- package/dist/types/src/infrastructure/cloud/types/snapshot.d.ts +52 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotCore.d.ts +125 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotJobs.d.ts +124 -0
- package/dist/types/src/infrastructure/cloud/types/snapshotTelemetry.d.ts +100 -0
- package/dist/types/src/infrastructure/cloud/types.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/batchInsert.d.ts +13 -0
- package/dist/types/src/infrastructure/persistence/completedJobCountSchema.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/dependencyCompletionSchema.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/dependencyCompletionStore.d.ts +40 -0
- package/dist/types/src/infrastructure/persistence/index.d.ts +5 -0
- package/dist/types/src/infrastructure/persistence/jobOptionsBlob.d.ts +19 -0
- package/dist/types/src/infrastructure/persistence/legacyNameMigration.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/migrationProgressSchema.d.ts +2 -0
- package/dist/types/src/infrastructure/persistence/migrations.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/schema.d.ts +8 -0
- package/dist/types/src/infrastructure/persistence/sqlite/admission.d.ts +9 -0
- package/dist/types/src/infrastructure/persistence/sqlite/completed.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/control.d.ts +48 -0
- package/dist/types/src/infrastructure/persistence/sqlite/flows.d.ts +26 -0
- package/dist/types/src/infrastructure/persistence/sqlite/jobLifecycle.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/jobs.d.ts +15 -0
- package/dist/types/src/infrastructure/persistence/sqlite/lifecycle.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/sqlite/mutations.d.ts +27 -0
- package/dist/types/src/infrastructure/persistence/sqlite/queries.d.ts +23 -0
- package/dist/types/src/infrastructure/persistence/sqlite/queueDeletionSql.d.ts +3 -0
- package/dist/types/src/infrastructure/persistence/sqlite/records.d.ts +24 -0
- package/dist/types/src/infrastructure/persistence/sqlite/state.d.ts +42 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetry.d.ts +17 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetryStore.d.ts +30 -0
- package/dist/types/src/infrastructure/persistence/sqlite/telemetryWrites.d.ts +47 -0
- package/dist/types/src/infrastructure/persistence/sqlite.d.ts +6 -0
- package/dist/types/src/infrastructure/persistence/sqliteBatch.d.ts +4 -0
- package/dist/types/src/infrastructure/persistence/sqliteMigration.d.ts +5 -0
- package/dist/types/src/infrastructure/persistence/sqliteSerializer.d.ts +50 -0
- package/dist/types/src/infrastructure/persistence/statements.d.ts +86 -0
- package/dist/types/src/infrastructure/persistence/types/admission.d.ts +8 -0
- package/dist/types/src/infrastructure/persistence/types/batch.d.ts +12 -0
- package/dist/types/src/infrastructure/persistence/types/sqlite.d.ts +27 -0
- package/dist/types/src/infrastructure/persistence/writeBuffer.d.ts +48 -0
- package/dist/types/src/infrastructure/persistence/writeBufferPending.d.ts +11 -0
- package/dist/types/src/infrastructure/scheduler/cron/execution.d.ts +12 -0
- package/dist/types/src/infrastructure/scheduler/cron/persisted.d.ts +5 -0
- package/dist/types/src/infrastructure/scheduler/cron/runtime.d.ts +31 -0
- package/dist/types/src/infrastructure/scheduler/cron/validation.d.ts +3 -0
- package/dist/types/src/infrastructure/scheduler/cronParser.d.ts +45 -0
- package/dist/types/src/infrastructure/scheduler/cronScheduler.d.ts +5 -0
- package/dist/types/src/infrastructure/scheduler/types/cronScheduler.d.ts +16 -0
- package/dist/types/src/infrastructure/server/protocol/commands.d.ts +8 -0
- package/dist/types/src/infrastructure/server/protocol/frameParser.d.ts +16 -0
- package/dist/types/src/infrastructure/server/protocol/lineBuffer.d.ts +6 -0
- package/dist/types/src/infrastructure/server/protocol/validation.d.ts +10 -0
- package/dist/types/src/infrastructure/server/protocol.d.ts +6 -0
- package/dist/types/src/infrastructure/server/socketWriteQueue.d.ts +66 -0
- package/dist/types/src/infrastructure/server/types/protocol.d.ts +4 -0
- package/dist/types/src/require-bun.d.ts +13 -0
- package/dist/types/src/shared/asyncLock.d.ts +13 -0
- package/dist/types/src/shared/boundedMap.d.ts +30 -0
- package/dist/types/src/shared/boundedSet.d.ts +26 -0
- package/dist/types/src/shared/hash.d.ts +30 -0
- package/dist/types/src/shared/histogram.d.ts +23 -0
- package/dist/types/src/shared/lock.d.ts +13 -0
- package/dist/types/src/shared/lockError.d.ts +3 -0
- package/dist/types/src/shared/lockTimeout.d.ts +2 -0
- package/dist/types/src/shared/logger.d.ts +48 -0
- package/dist/types/src/shared/lru.d.ts +9 -0
- package/dist/types/src/shared/lruMap.d.ts +42 -0
- package/dist/types/src/shared/lruSet.d.ts +36 -0
- package/dist/types/src/shared/minHeap.d.ts +43 -0
- package/dist/types/src/shared/msgpack.d.ts +3 -0
- package/dist/types/src/shared/pausedView.d.ts +19 -0
- package/dist/types/src/shared/rwLock.d.ts +22 -0
- package/dist/types/src/shared/serialization.d.ts +24 -0
- package/dist/types/src/shared/skipList.d.ts +97 -0
- package/dist/types/src/shared/skipListNodes.d.ts +6 -0
- package/dist/types/src/shared/storageHealth.d.ts +9 -0
- package/dist/types/src/shared/ttlMap.d.ts +81 -0
- package/dist/types/src/shared/types/lock.d.ts +7 -0
- package/dist/types/src/shared/types/skipList.d.ts +4 -0
- package/dist/types/src/shared/version.d.ts +4 -0
- package/dist/types/src/shared/webhookValidation.d.ts +6 -0
- package/package.json +27 -9
- package/src/ack-batcher.ts +8 -5
- package/src/bunqueue/bunqueue-api.ts +1 -1
- package/src/bunqueue/bunqueue.ts +2 -1
- package/src/canonical-transport/bun-sqlite-types.ts +22 -0
- package/src/canonical-transport/dlq.ts +12 -0
- package/src/canonical-transport/embedded.ts +55 -0
- package/src/canonical-transport/runtime.ts +49 -0
- package/src/canonical-transport/thread-worker.ts +83 -0
- package/src/canonical-transport/transport.ts +153 -0
- package/src/connection.ts +25 -30
- package/src/errors.ts +3 -0
- package/src/flow-commit.ts +45 -0
- package/src/flow-plan-legacy.ts +117 -0
- package/src/flow-plan.ts +209 -0
- package/src/flow-types.ts +4 -0
- package/src/flow.ts +31 -163
- package/src/frame.ts +5 -2
- package/src/index.ts +7 -75
- package/src/job.ts +43 -9
- package/src/legacy.ts +91 -0
- package/src/observability.ts +59 -1
- package/src/queue-admin.ts +5 -5
- package/src/queue-control.ts +8 -6
- package/src/queue.ts +10 -6
- package/src/serialization.ts +93 -0
- package/src/terminal-outcome.ts +58 -0
- package/src/types.ts +3 -6
- package/src/worker-base.ts +9 -6
- package/src/worker-slot-signal.ts +23 -0
- package/src/worker.ts +11 -5
- package/dist/backpressure.js +0 -39
- package/dist/bunqueue/aging.js +0 -53
- package/dist/bunqueue/batch.js +0 -60
- package/dist/bunqueue/bunqueue-api.js +0 -116
- package/dist/bunqueue/bunqueue.js +0 -194
- package/dist/bunqueue/cancellation.js +0 -48
- package/dist/bunqueue/circuit-breaker.js +0 -69
- package/dist/bunqueue/dedup-debounce.js +0 -37
- package/dist/bunqueue/dlq-rate-limit.js +0 -65
- package/dist/bunqueue/rate-gate.js +0 -61
- package/dist/bunqueue/retry.js +0 -56
- package/dist/bunqueue/triggers.js +0 -42
- package/dist/bunqueue/ttl.js +0 -31
- package/dist/bunqueue/types.js +0 -6
- package/dist/connection-pool.js +0 -60
- package/dist/connection-types.js +0 -2
- package/dist/connection.js +0 -281
- package/dist/errors.js +0 -25
- package/dist/flow-types.js +0 -2
- package/dist/flow.js +0 -212
- package/dist/job.js +0 -155
- package/dist/observability.js +0 -110
- package/dist/queue-admin.js +0 -158
- package/dist/queue-control.js +0 -107
- package/dist/queue-query.js +0 -187
- package/dist/queue.js +0 -92
- package/dist/responses.js +0 -10
- package/dist/socket-factory.js +0 -47
- package/dist/types.js +0 -50
- package/dist/worker-base.js +0 -159
- package/dist/worker-types.js +0 -5
- package/dist/worker.js +0 -211
- /package/dist/{backpressure.d.ts → types/sdk/typescript/src/backpressure.d.ts} +0 -0
- /package/dist/{bunqueue → types/sdk/typescript/src/bunqueue}/cancellation.d.ts +0 -0
package/dist/bunqueue/batch.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — batch processing.
|
|
3
|
-
* 1:1 port of src/client/bunqueue/batch.ts: accumulates jobs and processes
|
|
4
|
-
* them in groups; flushes on size, on timeout, and on destroy (close).
|
|
5
|
-
*/
|
|
6
|
-
export class BatchAccumulator {
|
|
7
|
-
buffer = [];
|
|
8
|
-
timer = null;
|
|
9
|
-
config;
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
}
|
|
13
|
-
/** Build a Processor that buffers jobs into batches. */
|
|
14
|
-
buildProcessor() {
|
|
15
|
-
return (job) => {
|
|
16
|
-
return new Promise((resolve, reject) => {
|
|
17
|
-
this.buffer.push({ job, resolve, reject });
|
|
18
|
-
if (this.buffer.length >= this.config.size) {
|
|
19
|
-
this.flush();
|
|
20
|
-
}
|
|
21
|
-
else if (!this.timer) {
|
|
22
|
-
const timeout = this.config.timeout ?? 5000;
|
|
23
|
-
this.timer = setTimeout(() => {
|
|
24
|
-
this.flush();
|
|
25
|
-
}, timeout);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
flush() {
|
|
31
|
-
if (this.timer) {
|
|
32
|
-
clearTimeout(this.timer);
|
|
33
|
-
this.timer = null;
|
|
34
|
-
}
|
|
35
|
-
const batch = this.buffer.splice(0);
|
|
36
|
-
if (batch.length === 0)
|
|
37
|
-
return;
|
|
38
|
-
const jobs = batch.map((b) => b.job);
|
|
39
|
-
this.config.processor(jobs).then((results) => {
|
|
40
|
-
for (let i = 0; i < batch.length; i++) {
|
|
41
|
-
batch[i].resolve(results[i] ?? undefined);
|
|
42
|
-
}
|
|
43
|
-
}, (err) => {
|
|
44
|
-
const error = err instanceof Error ? err : new Error(String(err));
|
|
45
|
-
for (const b of batch) {
|
|
46
|
-
b.reject(error);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
destroy() {
|
|
51
|
-
if (this.timer) {
|
|
52
|
-
clearTimeout(this.timer);
|
|
53
|
-
this.timer = null;
|
|
54
|
-
}
|
|
55
|
-
// Flush remaining
|
|
56
|
-
if (this.buffer.length > 0) {
|
|
57
|
-
this.flush();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — delegation API surface (cron, cancellation, circuit
|
|
3
|
-
* breaker, TTL, DLQ, rate limit, events, control). Merged onto the Bunqueue
|
|
4
|
-
* prototype by bunqueue.ts; split out to keep files small.
|
|
5
|
-
*/
|
|
6
|
-
export const bunqueueApi = {
|
|
7
|
-
// --------------------------------------------------------------------- cron
|
|
8
|
-
async cron(id, pattern, data, opts) {
|
|
9
|
-
await this.queue.upsertJobScheduler(id, { pattern, tz: opts?.timezone, limit: opts?.limit }, { name: id, data, opts: opts?.jobOpts });
|
|
10
|
-
return this.queue.getJobScheduler(id);
|
|
11
|
-
},
|
|
12
|
-
async every(id, intervalMs, data, opts) {
|
|
13
|
-
await this.queue.upsertJobScheduler(id, { every: intervalMs, limit: opts?.limit }, { name: id, data, opts: opts?.jobOpts });
|
|
14
|
-
return this.queue.getJobScheduler(id);
|
|
15
|
-
},
|
|
16
|
-
removeCron(id) {
|
|
17
|
-
return this.queue.removeJobScheduler(id);
|
|
18
|
-
},
|
|
19
|
-
listCrons() {
|
|
20
|
-
return this.queue.getJobSchedulers();
|
|
21
|
-
},
|
|
22
|
-
// ------------------------------------------------------------- cancellation
|
|
23
|
-
cancel(jobId, gracePeriodMs = 0) {
|
|
24
|
-
this.cancellation.cancel(jobId, gracePeriodMs);
|
|
25
|
-
},
|
|
26
|
-
isCancelled(jobId) {
|
|
27
|
-
return this.cancellation.isCancelled(jobId);
|
|
28
|
-
},
|
|
29
|
-
getSignal(jobId) {
|
|
30
|
-
return this.cancellation.getSignal(jobId);
|
|
31
|
-
},
|
|
32
|
-
// ---------------------------------------------------------- circuit breaker
|
|
33
|
-
getCircuitState() {
|
|
34
|
-
return this.cb?.currentState ?? 'closed';
|
|
35
|
-
},
|
|
36
|
-
resetCircuit() {
|
|
37
|
-
this.cb?.reset();
|
|
38
|
-
},
|
|
39
|
-
// ----------------------------------------------------------------- triggers
|
|
40
|
-
trigger(rule) {
|
|
41
|
-
this.triggerMgr.add(rule);
|
|
42
|
-
return this;
|
|
43
|
-
},
|
|
44
|
-
// ---------------------------------------------------------------------- ttl
|
|
45
|
-
setDefaultTtl(ttlMs) {
|
|
46
|
-
this.ttlChecker?.setDefaultTtl(ttlMs);
|
|
47
|
-
},
|
|
48
|
-
setNameTtl(name, ttlMs) {
|
|
49
|
-
this.ttlChecker?.setNameTtl(name, ttlMs);
|
|
50
|
-
},
|
|
51
|
-
// ---------------------------------------------------------------------- dlq
|
|
52
|
-
setDlqConfig(config) {
|
|
53
|
-
return this.dlqrl.setDlqConfig(config);
|
|
54
|
-
},
|
|
55
|
-
getDlqConfig() {
|
|
56
|
-
return this.dlqrl.getDlqConfig();
|
|
57
|
-
},
|
|
58
|
-
getDlq(filter) {
|
|
59
|
-
return this.dlqrl.getDlq(filter);
|
|
60
|
-
},
|
|
61
|
-
getDlqStats() {
|
|
62
|
-
return this.dlqrl.getDlqStats();
|
|
63
|
-
},
|
|
64
|
-
retryDlq(id) {
|
|
65
|
-
return this.dlqrl.retryDlq(id);
|
|
66
|
-
},
|
|
67
|
-
purgeDlq() {
|
|
68
|
-
return this.dlqrl.purgeDlq();
|
|
69
|
-
},
|
|
70
|
-
// ------------------------------------------------------------ rate limiting
|
|
71
|
-
setGlobalRateLimit(max, duration) {
|
|
72
|
-
return this.dlqrl.setGlobalRateLimit(max, duration);
|
|
73
|
-
},
|
|
74
|
-
removeGlobalRateLimit() {
|
|
75
|
-
return this.dlqrl.removeGlobalRateLimit();
|
|
76
|
-
},
|
|
77
|
-
// ------------------------------------------------------------------- events
|
|
78
|
-
on(event, listener) {
|
|
79
|
-
this.worker.on(event, listener);
|
|
80
|
-
return this;
|
|
81
|
-
},
|
|
82
|
-
once(event, listener) {
|
|
83
|
-
this.worker.once(event, listener);
|
|
84
|
-
return this;
|
|
85
|
-
},
|
|
86
|
-
off(event, listener) {
|
|
87
|
-
this.worker.off(event, listener);
|
|
88
|
-
return this;
|
|
89
|
-
},
|
|
90
|
-
// ------------------------------------------------------------------ control
|
|
91
|
-
pause() {
|
|
92
|
-
void this.queue.pause().catch(() => { });
|
|
93
|
-
this.worker.pause();
|
|
94
|
-
},
|
|
95
|
-
resume() {
|
|
96
|
-
void this.queue.resume().catch(() => { });
|
|
97
|
-
this.worker.resume();
|
|
98
|
-
},
|
|
99
|
-
async close(force = false) {
|
|
100
|
-
this.ager?.destroy();
|
|
101
|
-
this.cb?.destroy();
|
|
102
|
-
this.batchAcc?.destroy();
|
|
103
|
-
this.cancellation.destroyAll();
|
|
104
|
-
await this.worker.close(force);
|
|
105
|
-
this.queue.close();
|
|
106
|
-
},
|
|
107
|
-
isRunning() {
|
|
108
|
-
return this.worker.isRunning();
|
|
109
|
-
},
|
|
110
|
-
isPaused() {
|
|
111
|
-
return this.worker.isPaused();
|
|
112
|
-
},
|
|
113
|
-
isClosed() {
|
|
114
|
-
return this.worker.isClosed();
|
|
115
|
-
},
|
|
116
|
-
};
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue — simplified all-in-one Queue + Worker (Simple Mode).
|
|
3
|
-
* 1:1 port of src/client/bunqueue.ts from the official client, TCP mode only
|
|
4
|
-
* (the embedded mode requires the in-process Bun runtime). The delegation
|
|
5
|
-
* API (cron, DLQ, events, control, …) lives in bunqueue-api.ts and is merged
|
|
6
|
-
* onto the prototype below.
|
|
7
|
-
*/
|
|
8
|
-
import { Queue } from '../queue.js';
|
|
9
|
-
import { Worker } from '../worker.js';
|
|
10
|
-
import { PriorityAger } from './aging.js';
|
|
11
|
-
import { BatchAccumulator } from './batch.js';
|
|
12
|
-
import { bunqueueApi } from './bunqueue-api.js';
|
|
13
|
-
import { CancellationManager } from './cancellation.js';
|
|
14
|
-
import { WorkerCircuitBreaker } from './circuit-breaker.js';
|
|
15
|
-
import { DedupDebounceMerger } from './dedup-debounce.js';
|
|
16
|
-
import { DlqRateLimitManager } from './dlq-rate-limit.js';
|
|
17
|
-
import { RateGate } from './rate-gate.js';
|
|
18
|
-
import { executeWithRetry } from './retry.js';
|
|
19
|
-
import { TriggerManager } from './triggers.js';
|
|
20
|
-
import { TtlChecker } from './ttl.js';
|
|
21
|
-
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: prototype-mixin composition — Object.assign below installs exactly the methods BunqueueApi declares
|
|
22
|
-
export class Bunqueue {
|
|
23
|
-
name;
|
|
24
|
-
queue;
|
|
25
|
-
worker;
|
|
26
|
-
/** @internal */ cancellation = new CancellationManager();
|
|
27
|
-
/** @internal */ cb;
|
|
28
|
-
/** @internal */ triggerMgr;
|
|
29
|
-
/** @internal */ ager;
|
|
30
|
-
/** @internal */ ttlChecker;
|
|
31
|
-
/** @internal */ batchAcc;
|
|
32
|
-
/** @internal */ dlqrl;
|
|
33
|
-
middlewares = [];
|
|
34
|
-
baseProcessor;
|
|
35
|
-
retryConfig;
|
|
36
|
-
merger;
|
|
37
|
-
rateGate;
|
|
38
|
-
defaultJobOptions;
|
|
39
|
-
constructor(name, opts) {
|
|
40
|
-
if (opts.embedded || opts.dataPath) {
|
|
41
|
-
throw new Error('Bunqueue (bunqueue-client) is TCP-only: embedded mode requires the Bun runtime — use the official "bunqueue" package on Bun instead');
|
|
42
|
-
}
|
|
43
|
-
const modes = [opts.processor, opts.routes, opts.batch].filter(Boolean).length;
|
|
44
|
-
if (modes === 0)
|
|
45
|
-
throw new Error('Bunqueue requires "processor", "routes", or "batch"');
|
|
46
|
-
if (modes > 1)
|
|
47
|
-
throw new Error('Bunqueue: use only one of "processor", "routes", or "batch"');
|
|
48
|
-
this.name = (opts.prefixKey ?? '') + name;
|
|
49
|
-
this.retryConfig = opts.retry ?? null;
|
|
50
|
-
this.ttlChecker = opts.ttl ? new TtlChecker(opts.ttl) : null;
|
|
51
|
-
this.merger = new DedupDebounceMerger(opts.deduplication ?? null, opts.debounce ?? null);
|
|
52
|
-
const limiter = opts.rateLimit ?? opts.limiter;
|
|
53
|
-
this.rateGate = limiter ? new RateGate(limiter) : null;
|
|
54
|
-
this.defaultJobOptions = this.buildDefaultJobOptions(opts);
|
|
55
|
-
// Build base processor
|
|
56
|
-
if (opts.batch) {
|
|
57
|
-
this.batchAcc = new BatchAccumulator(opts.batch);
|
|
58
|
-
this.baseProcessor = this.batchAcc.buildProcessor();
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
this.batchAcc = null;
|
|
62
|
-
this.baseProcessor = opts.routes
|
|
63
|
-
? this.buildRouteProcessor(opts.routes)
|
|
64
|
-
: opts.processor;
|
|
65
|
-
}
|
|
66
|
-
const wrappedProcessor = (job) => this.processJob(job);
|
|
67
|
-
const conn = opts.connection ?? {};
|
|
68
|
-
this.queue = new Queue(this.name, conn);
|
|
69
|
-
this.worker = new Worker(this.name, wrappedProcessor, {
|
|
70
|
-
...conn,
|
|
71
|
-
concurrency: opts.concurrency,
|
|
72
|
-
autorun: opts.autorun,
|
|
73
|
-
heartbeatIntervalS: opts.heartbeatInterval !== undefined ? opts.heartbeatInterval / 1000 : undefined,
|
|
74
|
-
batchSize: opts.batchSize,
|
|
75
|
-
pollTimeoutMs: opts.pollTimeout,
|
|
76
|
-
});
|
|
77
|
-
// DLQ & rate limit manager
|
|
78
|
-
this.dlqrl = new DlqRateLimitManager(this.queue);
|
|
79
|
-
// Fire-and-forget config push: without the catch, an unreachable server at
|
|
80
|
-
// construction time becomes an unhandled rejection that kills the process.
|
|
81
|
-
// Route the failure to the worker's 'error' event (the channel every other
|
|
82
|
-
// background command failure uses); with no listener attached, swallow it
|
|
83
|
-
// like pause()/resume() do — an unlistened 'error' emit would itself throw.
|
|
84
|
-
if (opts.dlq) {
|
|
85
|
-
void this.dlqrl.setDlqConfig(opts.dlq).catch((err) => {
|
|
86
|
-
if (this.worker.listenerCount('error') > 0) {
|
|
87
|
-
this.worker.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
// Subsystems
|
|
92
|
-
this.cb = opts.circuitBreaker
|
|
93
|
-
? new WorkerCircuitBreaker(opts.circuitBreaker, this.worker)
|
|
94
|
-
: null;
|
|
95
|
-
this.triggerMgr = new TriggerManager(this.queue, this.worker);
|
|
96
|
-
this.ager = opts.priorityAging ? new PriorityAger(opts.priorityAging, this.queue) : null;
|
|
97
|
-
this.ager?.start();
|
|
98
|
-
}
|
|
99
|
-
buildRouteProcessor(routes) {
|
|
100
|
-
const routeMap = routes;
|
|
101
|
-
return (job) => {
|
|
102
|
-
const handler = routeMap[job.name ?? ''];
|
|
103
|
-
if (!handler)
|
|
104
|
-
throw new Error(`No route for job "${job.name}" in queue "${this.name}"`);
|
|
105
|
-
return handler(job);
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
buildDefaultJobOptions(opts) {
|
|
109
|
-
const base = { ...opts.defaultJobOptions };
|
|
110
|
-
if (opts.removeOnComplete !== undefined)
|
|
111
|
-
base.removeOnComplete ??= opts.removeOnComplete;
|
|
112
|
-
if (opts.removeOnFail !== undefined)
|
|
113
|
-
base.removeOnFail ??= opts.removeOnFail;
|
|
114
|
-
return Object.keys(base).length > 0 ? base : undefined;
|
|
115
|
-
}
|
|
116
|
-
// ------------------------------------------------- core processing pipeline
|
|
117
|
-
async processJob(job) {
|
|
118
|
-
if (this.rateGate) {
|
|
119
|
-
this.rateGate.prune(); // evict fully-expired groups (high-cardinality groupKey)
|
|
120
|
-
await this.rateGate.acquire(this.rateGate.groupFor(job.data));
|
|
121
|
-
}
|
|
122
|
-
// Circuit breaker check
|
|
123
|
-
if (this.cb?.isOpen()) {
|
|
124
|
-
throw new Error('Circuit breaker is open');
|
|
125
|
-
}
|
|
126
|
-
// TTL check
|
|
127
|
-
if (this.ttlChecker?.isExpired(job.name ?? '', job.timestamp)) {
|
|
128
|
-
throw new Error(`Job expired (age: ${Date.now() - job.timestamp}ms)`);
|
|
129
|
-
}
|
|
130
|
-
// Register cancellation
|
|
131
|
-
const ac = this.cancellation.register(job.id);
|
|
132
|
-
const runChain = () => this.runMiddlewareChain(job, ac);
|
|
133
|
-
const execute = this.retryConfig ? executeWithRetry(runChain, this.retryConfig) : runChain();
|
|
134
|
-
return execute.then((result) => {
|
|
135
|
-
this.cb?.onSuccess();
|
|
136
|
-
this.cancellation.unregister(job.id);
|
|
137
|
-
return result;
|
|
138
|
-
}, (err) => {
|
|
139
|
-
this.cb?.onFailure();
|
|
140
|
-
this.cancellation.unregister(job.id);
|
|
141
|
-
throw err;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
runMiddlewareChain(job, ac) {
|
|
145
|
-
if (this.middlewares.length === 0) {
|
|
146
|
-
const result = this.baseProcessor(job);
|
|
147
|
-
return result instanceof Promise ? result : Promise.resolve(result);
|
|
148
|
-
}
|
|
149
|
-
let index = 0;
|
|
150
|
-
const mws = this.middlewares;
|
|
151
|
-
const base = this.baseProcessor;
|
|
152
|
-
const next = () => {
|
|
153
|
-
if (ac.signal.aborted)
|
|
154
|
-
return Promise.reject(new Error('Job cancelled'));
|
|
155
|
-
if (index < mws.length)
|
|
156
|
-
return mws[index++](job, next);
|
|
157
|
-
const result = base(job);
|
|
158
|
-
return result instanceof Promise ? result : Promise.resolve(result);
|
|
159
|
-
};
|
|
160
|
-
return next();
|
|
161
|
-
}
|
|
162
|
-
// --------------------------------------------------------------- middleware
|
|
163
|
-
use(middleware) {
|
|
164
|
-
this.middlewares.push(middleware);
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
// --------------------------------------------------------- queue operations
|
|
168
|
-
add(name, data, opts) {
|
|
169
|
-
const merged = { ...this.defaultJobOptions, ...opts };
|
|
170
|
-
return this.queue.add(name, data, this.merger.merge(name, merged, data));
|
|
171
|
-
}
|
|
172
|
-
addBulk(jobs) {
|
|
173
|
-
return this.queue.addBulk(jobs.map((j) => ({
|
|
174
|
-
...j,
|
|
175
|
-
opts: this.merger.merge(j.name, { ...this.defaultJobOptions, ...j.opts }, j.data),
|
|
176
|
-
})));
|
|
177
|
-
}
|
|
178
|
-
getJob(id) {
|
|
179
|
-
return this.queue.getJob(id);
|
|
180
|
-
}
|
|
181
|
-
getJobCounts() {
|
|
182
|
-
return this.queue.getJobCounts();
|
|
183
|
-
}
|
|
184
|
-
getJobCountsAsync() {
|
|
185
|
-
return this.queue.getJobCounts();
|
|
186
|
-
}
|
|
187
|
-
count() {
|
|
188
|
-
return this.queue.count();
|
|
189
|
-
}
|
|
190
|
-
countAsync() {
|
|
191
|
-
return this.queue.count();
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
Object.assign(Bunqueue.prototype, bunqueueApi);
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — graceful job cancellation.
|
|
3
|
-
* 1:1 port of src/client/bunqueue/cancellation.ts: AbortController-based
|
|
4
|
-
* cancellation with optional grace period.
|
|
5
|
-
*/
|
|
6
|
-
export class CancellationManager {
|
|
7
|
-
controllers = new Map();
|
|
8
|
-
/** Register a new AbortController for a job. */
|
|
9
|
-
register(jobId) {
|
|
10
|
-
const ac = new AbortController();
|
|
11
|
-
this.controllers.set(jobId, ac);
|
|
12
|
-
return ac;
|
|
13
|
-
}
|
|
14
|
-
/** Remove a job's controller (on completion). */
|
|
15
|
-
unregister(jobId) {
|
|
16
|
-
this.controllers.delete(jobId);
|
|
17
|
-
}
|
|
18
|
-
/** Cancel a job with optional grace period. */
|
|
19
|
-
cancel(jobId, gracePeriodMs = 0) {
|
|
20
|
-
const ac = this.controllers.get(jobId);
|
|
21
|
-
if (!ac)
|
|
22
|
-
return;
|
|
23
|
-
if (gracePeriodMs > 0) {
|
|
24
|
-
setTimeout(() => {
|
|
25
|
-
ac.abort();
|
|
26
|
-
}, gracePeriodMs);
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
ac.abort();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/** Check if a job is cancelled. */
|
|
33
|
-
isCancelled(jobId) {
|
|
34
|
-
const ac = this.controllers.get(jobId);
|
|
35
|
-
return ac ? ac.signal.aborted : false;
|
|
36
|
-
}
|
|
37
|
-
/** Get the AbortSignal for a job. */
|
|
38
|
-
getSignal(jobId) {
|
|
39
|
-
return this.controllers.get(jobId)?.signal ?? null;
|
|
40
|
-
}
|
|
41
|
-
/** Cancel all and clear. */
|
|
42
|
-
destroyAll() {
|
|
43
|
-
for (const ac of this.controllers.values()) {
|
|
44
|
-
ac.abort();
|
|
45
|
-
}
|
|
46
|
-
this.controllers.clear();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — circuit breaker for worker protection.
|
|
3
|
-
* 1:1 port of src/client/bunqueue/circuitBreaker.ts.
|
|
4
|
-
*/
|
|
5
|
-
export class WorkerCircuitBreaker {
|
|
6
|
-
state = 'closed';
|
|
7
|
-
failures = 0;
|
|
8
|
-
timer = null;
|
|
9
|
-
config;
|
|
10
|
-
worker;
|
|
11
|
-
constructor(config, worker) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.worker = worker;
|
|
14
|
-
}
|
|
15
|
-
get currentState() {
|
|
16
|
-
return this.state;
|
|
17
|
-
}
|
|
18
|
-
isOpen() {
|
|
19
|
-
return this.state === 'open';
|
|
20
|
-
}
|
|
21
|
-
onSuccess() {
|
|
22
|
-
if (this.state === 'half-open') {
|
|
23
|
-
this.state = 'closed';
|
|
24
|
-
this.failures = 0;
|
|
25
|
-
this.config.onClose?.();
|
|
26
|
-
}
|
|
27
|
-
else if (this.state === 'closed') {
|
|
28
|
-
this.failures = 0;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
onFailure() {
|
|
32
|
-
this.failures++;
|
|
33
|
-
const threshold = this.config.threshold ?? 5;
|
|
34
|
-
if (this.state === 'half-open' || this.failures >= threshold) {
|
|
35
|
-
this.open();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
open() {
|
|
39
|
-
this.state = 'open';
|
|
40
|
-
this.config.onOpen?.(this.failures);
|
|
41
|
-
this.worker.pause();
|
|
42
|
-
const resetTimeout = this.config.resetTimeout ?? 30000;
|
|
43
|
-
if (this.timer)
|
|
44
|
-
clearTimeout(this.timer);
|
|
45
|
-
this.timer = setTimeout(() => {
|
|
46
|
-
this.state = 'half-open';
|
|
47
|
-
this.config.onHalfOpen?.();
|
|
48
|
-
this.worker.resume();
|
|
49
|
-
}, resetTimeout);
|
|
50
|
-
this.timer.unref?.();
|
|
51
|
-
}
|
|
52
|
-
reset() {
|
|
53
|
-
this.state = 'closed';
|
|
54
|
-
this.failures = 0;
|
|
55
|
-
if (this.timer) {
|
|
56
|
-
clearTimeout(this.timer);
|
|
57
|
-
this.timer = null;
|
|
58
|
-
}
|
|
59
|
-
if (this.worker.isPaused()) {
|
|
60
|
-
this.worker.resume();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
destroy() {
|
|
64
|
-
if (this.timer) {
|
|
65
|
-
clearTimeout(this.timer);
|
|
66
|
-
this.timer = null;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — deduplication and debounce defaults merger.
|
|
3
|
-
* 1:1 port of src/client/bunqueue/dedupDebounce.ts, including the dedup id
|
|
4
|
-
* derivation algorithm: `${name}:${JSON.stringify(data)}`.
|
|
5
|
-
*/
|
|
6
|
-
export class DedupDebounceMerger {
|
|
7
|
-
dedup;
|
|
8
|
-
debounce;
|
|
9
|
-
constructor(dedup, debounce) {
|
|
10
|
-
this.dedup = dedup;
|
|
11
|
-
this.debounce = debounce;
|
|
12
|
-
}
|
|
13
|
-
get active() {
|
|
14
|
-
return this.dedup !== null || this.debounce !== null;
|
|
15
|
-
}
|
|
16
|
-
merge(name, opts, data) {
|
|
17
|
-
if (!this.active)
|
|
18
|
-
return opts;
|
|
19
|
-
const merged = { ...opts };
|
|
20
|
-
if (this.dedup && !merged.deduplication) {
|
|
21
|
-
const dataKey = data !== undefined ? JSON.stringify(data) : '';
|
|
22
|
-
merged.deduplication = {
|
|
23
|
-
id: `${name}:${dataKey}`,
|
|
24
|
-
ttl: this.dedup.ttl ?? 3600000,
|
|
25
|
-
extend: this.dedup.extend,
|
|
26
|
-
replace: this.dedup.replace,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
if (this.debounce && !merged.debounce) {
|
|
30
|
-
merged.debounce = {
|
|
31
|
-
id: name,
|
|
32
|
-
ttl: this.debounce.ttl,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
return merged;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — DLQ and rate limit helpers.
|
|
3
|
-
* Port of src/client/bunqueue/dlqRateLimit.ts. Delegates to the TCP Queue;
|
|
4
|
-
* the DLQ filter and stats are computed client-side from the fetched entries
|
|
5
|
-
* (the embedded original reads them in-process).
|
|
6
|
-
*/
|
|
7
|
-
function entryReason(entry) {
|
|
8
|
-
return String(entry.reason ?? entry.entry?.reason ?? 'unknown');
|
|
9
|
-
}
|
|
10
|
-
function entryName(entry) {
|
|
11
|
-
const data = (entry.data ?? entry.entry?.data);
|
|
12
|
-
return data?.name === undefined ? undefined : String(data.name);
|
|
13
|
-
}
|
|
14
|
-
export class DlqRateLimitManager {
|
|
15
|
-
queue;
|
|
16
|
-
constructor(queue) {
|
|
17
|
-
this.queue = queue;
|
|
18
|
-
}
|
|
19
|
-
// ------------------------------------------------------------------- dlq
|
|
20
|
-
async setDlqConfig(config) {
|
|
21
|
-
await this.queue.setDlqConfig(config);
|
|
22
|
-
}
|
|
23
|
-
getDlqConfig() {
|
|
24
|
-
return this.queue.getDlqConfig();
|
|
25
|
-
}
|
|
26
|
-
async getDlq(filter) {
|
|
27
|
-
const entries = await this.queue.getDlq();
|
|
28
|
-
if (!filter)
|
|
29
|
-
return entries;
|
|
30
|
-
return entries.filter((entry) => {
|
|
31
|
-
if (filter.reason && entryReason(entry) !== filter.reason)
|
|
32
|
-
return false;
|
|
33
|
-
if (filter.jobName && entryName(entry) !== filter.jobName)
|
|
34
|
-
return false;
|
|
35
|
-
if (filter.since !== undefined) {
|
|
36
|
-
const at = Number(entry.enteredAt ?? entry.failedAt ?? 0);
|
|
37
|
-
if (at < filter.since)
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async getDlqStats() {
|
|
44
|
-
const entries = await this.queue.getDlq();
|
|
45
|
-
const byReason = {};
|
|
46
|
-
for (const entry of entries) {
|
|
47
|
-
const reason = entryReason(entry);
|
|
48
|
-
byReason[reason] = (byReason[reason] ?? 0) + 1;
|
|
49
|
-
}
|
|
50
|
-
return { total: entries.length, byReason };
|
|
51
|
-
}
|
|
52
|
-
retryDlq(id) {
|
|
53
|
-
return this.queue.retryDlq(id);
|
|
54
|
-
}
|
|
55
|
-
purgeDlq() {
|
|
56
|
-
return this.queue.purgeDlq();
|
|
57
|
-
}
|
|
58
|
-
// ----------------------------------------------------------- rate limiting
|
|
59
|
-
async setGlobalRateLimit(max, duration) {
|
|
60
|
-
await this.queue.setGlobalRateLimit(max, duration);
|
|
61
|
-
}
|
|
62
|
-
async removeGlobalRateLimit() {
|
|
63
|
-
await this.queue.removeGlobalRateLimit();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — client-side rate limiter for the worker.
|
|
3
|
-
*
|
|
4
|
-
* The official client passes `rateLimit`/`limiter` to the embedded Worker,
|
|
5
|
-
* which throttles job starts to `max` per `duration` window, optionally per
|
|
6
|
-
* group (`groupKey` names a field of job.data). This SDK reproduces the same
|
|
7
|
-
* semantics as a gate awaited before each job runs: a job whose window is
|
|
8
|
-
* full waits (holding its concurrency slot) until the window frees.
|
|
9
|
-
*/
|
|
10
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
11
|
-
export class RateGate {
|
|
12
|
-
max;
|
|
13
|
-
duration;
|
|
14
|
-
groupKey;
|
|
15
|
-
windows = new Map();
|
|
16
|
-
constructor(options) {
|
|
17
|
-
this.max = options.max;
|
|
18
|
-
this.duration = options.duration;
|
|
19
|
-
this.groupKey = options.groupKey;
|
|
20
|
-
}
|
|
21
|
-
/** Resolve the rate-limit group for a job's data. */
|
|
22
|
-
groupFor(data) {
|
|
23
|
-
if (!this.groupKey)
|
|
24
|
-
return '';
|
|
25
|
-
if (typeof data === 'object' && data !== null) {
|
|
26
|
-
const value = data[this.groupKey];
|
|
27
|
-
if (value !== undefined && value !== null)
|
|
28
|
-
return String(value);
|
|
29
|
-
}
|
|
30
|
-
return '';
|
|
31
|
-
}
|
|
32
|
-
/** Wait until the group's window has room, then record the start. */
|
|
33
|
-
async acquire(group) {
|
|
34
|
-
for (;;) {
|
|
35
|
-
const now = Date.now();
|
|
36
|
-
const window = this.windows.get(group) ?? [];
|
|
37
|
-
const fresh = window.filter((t) => now - t < this.duration);
|
|
38
|
-
if (fresh.length < this.max) {
|
|
39
|
-
fresh.push(now);
|
|
40
|
-
this.windows.set(group, fresh);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.windows.set(group, fresh);
|
|
44
|
-
const oldest = fresh[0];
|
|
45
|
-
await sleep(Math.max(oldest + this.duration - now, 10));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Drop groups whose window is fully expired. Called on each acquire cycle
|
|
50
|
-
* boundary by the owner; without it a high-cardinality groupKey (e.g. one
|
|
51
|
-
* group per user id) grows the map forever.
|
|
52
|
-
*/
|
|
53
|
-
prune() {
|
|
54
|
-
const now = Date.now();
|
|
55
|
-
for (const [group, window] of this.windows) {
|
|
56
|
-
if (window.length === 0 || now - window[window.length - 1] >= this.duration) {
|
|
57
|
-
this.windows.delete(group);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|