bunqueue-client 0.1.9 → 0.2.1
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 +165 -0
- package/LEGACY.md +460 -0
- package/README.md +204 -349
- package/dist/ack-batcher.js +7 -67
- package/dist/canonical-manifest.json +934 -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 +16510 -0
- package/dist/frame.js +14 -57
- package/dist/index.d.ts +1 -27
- package/dist/index.js +10953 -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/clientOwnership.d.ts +65 -0
- package/dist/types/src/application/clientTracking.d.ts +40 -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 +45 -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/orphanRecovery.d.ts +25 -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 +98 -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 +26 -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 +89 -0
- package/dist/types/src/application/types/contexts.d.ts +117 -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 +100 -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 +75 -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 +72 -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 +14 -0
- package/dist/types/src/domain/job/create.d.ts +9 -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 +16 -0
- package/dist/types/src/domain/job/payload.d.ts +18 -0
- package/dist/types/src/domain/job/state.d.ts +23 -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 +107 -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 +89 -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 +150 -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/src/legacy.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bunqueue-client — cross-runtime TypeScript SDK for bunqueue (TCP mode).
|
|
3
|
+
* Works on Node.js ≥20, Bun and Deno ≥2 (uses only node: builtins + msgpackr).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Simple Mode (Bunqueue): all-in-one Queue + Worker, 1:1 with the official client
|
|
7
|
+
export { Bunqueue } from './bunqueue/bunqueue.js';
|
|
8
|
+
export type { DlqFilter, DlqStats } from './bunqueue/dlq-rate-limit.js';
|
|
9
|
+
export type {
|
|
10
|
+
BatchConfig,
|
|
11
|
+
BatchProcessor,
|
|
12
|
+
BunqueueConnection,
|
|
13
|
+
BunqueueDebounceConfig,
|
|
14
|
+
BunqueueDeduplicationConfig,
|
|
15
|
+
BunqueueDlqConfig,
|
|
16
|
+
BunqueueMiddleware,
|
|
17
|
+
BunqueueOptions,
|
|
18
|
+
CircuitBreakerConfig,
|
|
19
|
+
CircuitState,
|
|
20
|
+
JobTtlConfig,
|
|
21
|
+
PriorityAgingConfig,
|
|
22
|
+
RateLimiterOptions,
|
|
23
|
+
RetryConfig,
|
|
24
|
+
RetryStrategy,
|
|
25
|
+
TriggerRule,
|
|
26
|
+
} from './bunqueue/types.js';
|
|
27
|
+
export type { Command, ConnectionOptions, Response, TlsOption } from './connection.js';
|
|
28
|
+
export { Connection } from './connection.js';
|
|
29
|
+
export { ConnectionPool } from './connection-pool.js';
|
|
30
|
+
export type { ConnectionLike } from './connection-types.js';
|
|
31
|
+
export {
|
|
32
|
+
AuthError,
|
|
33
|
+
BunqueueError,
|
|
34
|
+
CommandError,
|
|
35
|
+
CommandTimeoutError,
|
|
36
|
+
ConnectionClosedError,
|
|
37
|
+
SerializationError,
|
|
38
|
+
UnrecoverableError,
|
|
39
|
+
} from './errors.js';
|
|
40
|
+
export { FlowProducer } from './flow.js';
|
|
41
|
+
export type {
|
|
42
|
+
FlowJob,
|
|
43
|
+
FlowOptions,
|
|
44
|
+
FlowProducerOptions,
|
|
45
|
+
FlowStep,
|
|
46
|
+
GetFlowOptions,
|
|
47
|
+
JobNode,
|
|
48
|
+
} from './flow-types.js';
|
|
49
|
+
export { MAX_FRAME_SIZE, PROTOCOL_VERSION } from './frame.js';
|
|
50
|
+
export type { JobRaw } from './job.js';
|
|
51
|
+
export { Job } from './job.js';
|
|
52
|
+
export type {
|
|
53
|
+
Logger,
|
|
54
|
+
LogLevel,
|
|
55
|
+
Observability,
|
|
56
|
+
TelemetryErrorOperation,
|
|
57
|
+
TelemetryEvent,
|
|
58
|
+
TelemetryHandler,
|
|
59
|
+
} from './observability.js';
|
|
60
|
+
export { consoleLogger, noopLogger } from './observability.js';
|
|
61
|
+
export type { BulkJobEntry, QueueOptions } from './queue.js';
|
|
62
|
+
export { Queue } from './queue.js';
|
|
63
|
+
export type { SchedulerOptions } from './queue-admin.js';
|
|
64
|
+
export type {
|
|
65
|
+
BatchResponse,
|
|
66
|
+
CountResponse,
|
|
67
|
+
DataResponse,
|
|
68
|
+
JobCountsResponse,
|
|
69
|
+
JobResponse,
|
|
70
|
+
JobsResponse,
|
|
71
|
+
OkResponse,
|
|
72
|
+
PausedResponse,
|
|
73
|
+
ProgressResponse,
|
|
74
|
+
PulledJobResponse,
|
|
75
|
+
PulledJobsResponse,
|
|
76
|
+
ResultResponse,
|
|
77
|
+
StateResponse,
|
|
78
|
+
WaitJobResponse,
|
|
79
|
+
} from './responses.js';
|
|
80
|
+
export type {
|
|
81
|
+
BackoffOptions,
|
|
82
|
+
DeduplicationOptions,
|
|
83
|
+
JobCounts,
|
|
84
|
+
JobOptions,
|
|
85
|
+
JobStateName,
|
|
86
|
+
RepeatOptions,
|
|
87
|
+
} from './types.js';
|
|
88
|
+
export { Worker } from './worker.js';
|
|
89
|
+
export type { AckBatchOptions, Processor, WorkerEventMap, WorkerOptions } from './worker-types.js';
|
|
90
|
+
|
|
91
|
+
export const __version__ = '0.2.1';
|
package/src/observability.ts
CHANGED
|
@@ -45,6 +45,8 @@ export function consoleLogger(min: LogLevel = 'info'): Logger {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
/** A single telemetry data point. A discriminated union keyed on `type`. */
|
|
48
|
+
export type TelemetryErrorOperation = 'connect' | 'socket' | 'write' | 'serialization';
|
|
49
|
+
|
|
48
50
|
export type TelemetryEvent =
|
|
49
51
|
| { type: 'command'; cmd: string; reqId: string; durationMs: number; ok: boolean }
|
|
50
52
|
| { type: 'command_timeout'; cmd: string; reqId: string }
|
|
@@ -52,7 +54,14 @@ export type TelemetryEvent =
|
|
|
52
54
|
| { type: 'disconnect'; host: string; port: number; generation: number }
|
|
53
55
|
| { type: 'reconnect_scheduled'; host: string; port: number; attempt: number; delayMs: number }
|
|
54
56
|
| { type: 'auth'; ok: boolean }
|
|
55
|
-
| { type: 'backpressure'; inFlight: number; maxInFlight: number }
|
|
57
|
+
| { type: 'backpressure'; inFlight: number; maxInFlight: number }
|
|
58
|
+
| {
|
|
59
|
+
type: 'error';
|
|
60
|
+
operation: TelemetryErrorOperation;
|
|
61
|
+
errorType: string;
|
|
62
|
+
message: string;
|
|
63
|
+
code?: string;
|
|
64
|
+
};
|
|
56
65
|
|
|
57
66
|
export type TelemetryHandler = (event: TelemetryEvent) => void;
|
|
58
67
|
|
|
@@ -74,6 +83,13 @@ export interface Observability {
|
|
|
74
83
|
/** High-resolution monotonic clock (Node/Bun/Deno all expose `performance`). */
|
|
75
84
|
export const nowMs = (): number => performance.now();
|
|
76
85
|
|
|
86
|
+
const ERROR_MESSAGES: Record<TelemetryErrorOperation, string> = {
|
|
87
|
+
connect: 'connection failed',
|
|
88
|
+
socket: 'socket failed',
|
|
89
|
+
write: 'socket write failed',
|
|
90
|
+
serialization: 'command serialization failed',
|
|
91
|
+
};
|
|
92
|
+
|
|
77
93
|
/**
|
|
78
94
|
* Fans a telemetry event out to (1) the telemetry sink, (2) the logger, and
|
|
79
95
|
* (3) — for lifecycle events — the owning EventEmitter, so users can both
|
|
@@ -147,6 +163,48 @@ export class Telemetry {
|
|
|
147
163
|
this.dispatch({ type: 'backpressure', inFlight, maxInFlight });
|
|
148
164
|
}
|
|
149
165
|
|
|
166
|
+
/**
|
|
167
|
+
* Report transport failures without forwarding raw messages: those can
|
|
168
|
+
* contain remote-controlled text or application data in third-party errors.
|
|
169
|
+
*/
|
|
170
|
+
error(operation: TelemetryErrorOperation, error: unknown): void {
|
|
171
|
+
const errorType =
|
|
172
|
+
error instanceof Error && /^[A-Za-z][A-Za-z0-9]{0,63}$/.test(error.name)
|
|
173
|
+
? error.name
|
|
174
|
+
: 'Error';
|
|
175
|
+
const rawCode =
|
|
176
|
+
typeof error === 'object' && error !== null && 'code' in error ? error.code : undefined;
|
|
177
|
+
const code =
|
|
178
|
+
typeof rawCode === 'string' && /^[A-Z0-9_]{1,32}$/.test(rawCode) ? rawCode : undefined;
|
|
179
|
+
const event: TelemetryEvent = {
|
|
180
|
+
type: 'error',
|
|
181
|
+
operation,
|
|
182
|
+
errorType,
|
|
183
|
+
message: ERROR_MESSAGES[operation],
|
|
184
|
+
...(code ? { code } : {}),
|
|
185
|
+
};
|
|
186
|
+
this.logger.error(event.message, { operation, errorType, ...(code ? { code } : {}) });
|
|
187
|
+
this.dispatch(event);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
capture<T>(operation: TelemetryErrorOperation, fn: () => T): T {
|
|
191
|
+
try {
|
|
192
|
+
return fn();
|
|
193
|
+
} catch (error) {
|
|
194
|
+
this.error(operation, error);
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
async captureAsync<T>(operation: TelemetryErrorOperation, promise: Promise<T>): Promise<T> {
|
|
200
|
+
try {
|
|
201
|
+
return await promise;
|
|
202
|
+
} catch (error) {
|
|
203
|
+
this.error(operation, error);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
150
208
|
private dispatch(event: TelemetryEvent): void {
|
|
151
209
|
// A throwing sink or lifecycle listener must never break the transport:
|
|
152
210
|
// dispatch runs inside socket 'data' handlers and the connect path.
|
package/src/queue-admin.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { CommandError } from './errors.js';
|
|
7
7
|
import { compact } from './frame.js';
|
|
8
8
|
import type { Queue } from './queue.js';
|
|
9
|
-
import { type JobOptions,
|
|
9
|
+
import { type JobOptions, wireJobOptions } from './types.js';
|
|
10
10
|
|
|
11
11
|
type Ctx = Queue<unknown>;
|
|
12
12
|
type Raw = Record<string, unknown>;
|
|
@@ -70,9 +70,8 @@ export const adminMethods = {
|
|
|
70
70
|
|
|
71
71
|
// -------------------------------------------------- rate limit / concurrency
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
await this.call({ cmd: 'RateLimit', queue: this.name, limit: max });
|
|
73
|
+
async setGlobalRateLimit(this: Ctx, max: number, duration?: number): Promise<void> {
|
|
74
|
+
await this.call({ cmd: 'RateLimit', queue: this.name, limit: max, duration });
|
|
76
75
|
},
|
|
77
76
|
|
|
78
77
|
async removeGlobalRateLimit(this: Ctx): Promise<void> {
|
|
@@ -104,8 +103,9 @@ export const adminMethods = {
|
|
|
104
103
|
compact({
|
|
105
104
|
cmd: 'Cron',
|
|
106
105
|
name: schedulerId,
|
|
106
|
+
jobName: template.name ?? schedulerId,
|
|
107
107
|
queue: this.name,
|
|
108
|
-
data:
|
|
108
|
+
data: 'data' in template ? template.data : {},
|
|
109
109
|
schedule: repeat.pattern,
|
|
110
110
|
repeatEvery: repeat.every,
|
|
111
111
|
priority: template.opts?.priority,
|
package/src/queue-control.ts
CHANGED
|
@@ -110,16 +110,18 @@ export const controlMethods = {
|
|
|
110
110
|
await this.call({ cmd: 'ChangePriority', id, priority: opts.priority, lifo: opts.lifo });
|
|
111
111
|
},
|
|
112
112
|
|
|
113
|
-
async changeJobDelay(this: Ctx, id: string, delayMs: number): Promise<void> {
|
|
114
|
-
await this.call({ cmd: 'ChangeDelay', id, delay: delayMs });
|
|
113
|
+
async changeJobDelay(this: Ctx, id: string, delayMs: number, token?: string): Promise<void> {
|
|
114
|
+
await this.call(compact({ cmd: 'ChangeDelay', id, delay: delayMs, token }) as { cmd: string });
|
|
115
115
|
},
|
|
116
116
|
|
|
117
|
-
async moveJobToWait(this: Ctx, id: string): Promise<void> {
|
|
118
|
-
await this.call({ cmd: 'MoveToWait', id });
|
|
117
|
+
async moveJobToWait(this: Ctx, id: string, token?: string): Promise<void> {
|
|
118
|
+
await this.call(compact({ cmd: 'MoveToWait', id, token }) as { cmd: string });
|
|
119
119
|
},
|
|
120
120
|
|
|
121
|
-
async moveJobToDelayed(this: Ctx, id: string, delayMs: number): Promise<void> {
|
|
122
|
-
await this.call(
|
|
121
|
+
async moveJobToDelayed(this: Ctx, id: string, delayMs: number, token?: string): Promise<void> {
|
|
122
|
+
await this.call(
|
|
123
|
+
compact({ cmd: 'MoveToDelayed', id, delay: delayMs, token }) as { cmd: string }
|
|
124
|
+
);
|
|
123
125
|
},
|
|
124
126
|
|
|
125
127
|
async extendJobLock(this: Ctx, id: string, token: string, durationMs: number): Promise<void> {
|
package/src/queue.ts
CHANGED
|
@@ -41,7 +41,7 @@ export interface BulkJobEntry<T = unknown> {
|
|
|
41
41
|
opts?: JobOptions;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
//
|
|
44
|
+
// oxlint-disable-next-line typescript/no-unsafe-declaration-merging -- prototype-mixin composition installs the declared methods with Object.assign below
|
|
45
45
|
export class Queue<T = unknown> {
|
|
46
46
|
readonly name: string;
|
|
47
47
|
readonly connection: ConnectionLike;
|
|
@@ -83,10 +83,10 @@ export class Queue<T = unknown> {
|
|
|
83
83
|
const response = await this.call({
|
|
84
84
|
cmd: 'PUSH',
|
|
85
85
|
queue: this.name,
|
|
86
|
-
|
|
86
|
+
...payload,
|
|
87
87
|
...wireJobOptions(opts),
|
|
88
88
|
});
|
|
89
|
-
return new Job<T>({ id: response.id, queue: this.name,
|
|
89
|
+
return new Job<T>({ id: response.id, queue: this.name, ...payload }, this.connection);
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/** Add many jobs in one round-trip; returns Job stubs. */
|
|
@@ -101,12 +101,16 @@ export class Queue<T = unknown> {
|
|
|
101
101
|
opts.customId = opts.jobId;
|
|
102
102
|
delete opts.jobId;
|
|
103
103
|
}
|
|
104
|
-
return {
|
|
104
|
+
return { ...jobPayload(entry.name, entry.data), ...opts };
|
|
105
105
|
});
|
|
106
106
|
const response = await this.call({ cmd: 'PUSHB', queue: this.name, jobs: inputs });
|
|
107
107
|
const ids = (response.ids ?? []) as string[];
|
|
108
108
|
return ids.map(
|
|
109
|
-
(id, i) =>
|
|
109
|
+
(id, i) =>
|
|
110
|
+
new Job<T>(
|
|
111
|
+
{ id, queue: this.name, name: inputs[i].name, data: inputs[i].data },
|
|
112
|
+
this.connection
|
|
113
|
+
)
|
|
110
114
|
);
|
|
111
115
|
}
|
|
112
116
|
|
|
@@ -134,6 +138,6 @@ export class Queue<T = unknown> {
|
|
|
134
138
|
* The declaration merging is intentional and safe: Object.assign below
|
|
135
139
|
* installs exactly the methods the interface declares. The unused type
|
|
136
140
|
* parameter is required — merged interfaces must repeat the class generics. */
|
|
137
|
-
//
|
|
141
|
+
// oxlint-disable-next-line no-unused-vars -- generic must match the class declaration
|
|
138
142
|
export interface Queue<T = unknown> extends QueueQueryApi, QueueControlApi, QueueAdminApi {}
|
|
139
143
|
Object.assign(Queue.prototype, queryMethods, controlMethods, adminMethods);
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** Safe command serialization for the bunqueue wire protocol. */
|
|
2
|
+
|
|
3
|
+
import { pack } from 'msgpackr';
|
|
4
|
+
import type { Command } from './connection-types.js';
|
|
5
|
+
import { SerializationError } from './errors.js';
|
|
6
|
+
import { frame } from './frame.js';
|
|
7
|
+
|
|
8
|
+
const invalid = (reason: string): never => {
|
|
9
|
+
throw new SerializationError(`cannot serialize command as MessagePack: ${reason}`);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function normalizeWireValue(value: unknown, active: WeakSet<object>): unknown {
|
|
13
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') return value;
|
|
14
|
+
if (typeof value === 'number') {
|
|
15
|
+
if (!Number.isFinite(value)) invalid('numbers must be finite');
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (typeof value === 'bigint') invalid('BigInt is not JavaScript-safe on the broker');
|
|
19
|
+
if (typeof value === 'undefined') invalid('nested undefined values are not portable');
|
|
20
|
+
if (typeof value === 'symbol' || typeof value === 'function') {
|
|
21
|
+
invalid(`${typeof value} values are unsupported`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof value !== 'object') invalid('unsupported value');
|
|
24
|
+
const objectValue = value as object;
|
|
25
|
+
|
|
26
|
+
if (value instanceof Date) {
|
|
27
|
+
if (!Number.isFinite(value.getTime())) invalid('invalid Date');
|
|
28
|
+
return new Date(value.getTime());
|
|
29
|
+
}
|
|
30
|
+
if (value instanceof Uint8Array || value instanceof ArrayBuffer) return value;
|
|
31
|
+
if (active.has(objectValue)) invalid('cyclic structures are unsupported');
|
|
32
|
+
active.add(objectValue);
|
|
33
|
+
try {
|
|
34
|
+
if (Array.isArray(value)) {
|
|
35
|
+
return Array.from(value, (entry) => normalizeWireValue(entry, active));
|
|
36
|
+
}
|
|
37
|
+
if (value instanceof Map) {
|
|
38
|
+
const normalized = new Map<string, unknown>();
|
|
39
|
+
for (const [key, entry] of value) {
|
|
40
|
+
if (typeof key !== 'string') invalid('map keys must be strings');
|
|
41
|
+
normalized.set(key as string, normalizeWireValue(entry, active));
|
|
42
|
+
}
|
|
43
|
+
return normalized;
|
|
44
|
+
}
|
|
45
|
+
const prototype = Object.getPrototypeOf(objectValue);
|
|
46
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
47
|
+
invalid('only plain objects, arrays, maps, dates, and binary values are supported');
|
|
48
|
+
}
|
|
49
|
+
const normalized = Object.create(null) as Record<string, unknown>;
|
|
50
|
+
for (const key of Reflect.ownKeys(objectValue)) {
|
|
51
|
+
if (typeof key !== 'string') invalid('symbol object keys are unsupported');
|
|
52
|
+
const stringKey = key as string;
|
|
53
|
+
const descriptor = Object.getOwnPropertyDescriptor(objectValue, stringKey);
|
|
54
|
+
if (!descriptor?.enumerable) continue;
|
|
55
|
+
if (!('value' in descriptor)) invalid('accessor properties are unsupported');
|
|
56
|
+
normalized[stringKey] = normalizeWireValue(descriptor.value, active);
|
|
57
|
+
}
|
|
58
|
+
return normalized;
|
|
59
|
+
} finally {
|
|
60
|
+
active.delete(objectValue);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function prepareCommand(command: Command, reqId: string): Record<string, unknown> {
|
|
65
|
+
const envelope = Object.create(null) as Record<string, unknown>;
|
|
66
|
+
for (const key of Reflect.ownKeys(command)) {
|
|
67
|
+
if (typeof key !== 'string') invalid('symbol command keys are unsupported');
|
|
68
|
+
const stringKey = key as string;
|
|
69
|
+
const descriptor = Object.getOwnPropertyDescriptor(command, stringKey);
|
|
70
|
+
if (!descriptor?.enumerable) continue;
|
|
71
|
+
if (!('value' in descriptor)) invalid('accessor command properties are unsupported');
|
|
72
|
+
if (descriptor.value === undefined) continue;
|
|
73
|
+
envelope[stringKey] = descriptor.value;
|
|
74
|
+
}
|
|
75
|
+
envelope.reqId = reqId;
|
|
76
|
+
return normalizeWireValue(envelope, new WeakSet()) as Record<string, unknown>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Encode and frame a command before it occupies an in-flight request slot.
|
|
81
|
+
*
|
|
82
|
+
* MessagePack may reject values such as cyclic objects. Normalize every such
|
|
83
|
+
* encoder failure to the public SDK error hierarchy; `frame()` already uses
|
|
84
|
+
* the same typed error for an oversized encoded body.
|
|
85
|
+
*/
|
|
86
|
+
export function serializeCommand(command: Command, reqId: string): Buffer {
|
|
87
|
+
try {
|
|
88
|
+
return frame(pack(prepareCommand(command, reqId)));
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (error instanceof SerializationError) throw error;
|
|
91
|
+
throw new SerializationError('cannot serialize command as MessagePack');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
interface AckEntry {
|
|
2
|
+
readonly id: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
function record(value: unknown): Record<string, unknown> | null {
|
|
6
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
7
|
+
? (value as Record<string, unknown>)
|
|
8
|
+
: null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function validatedIndices(value: unknown, size: number): number[] {
|
|
12
|
+
if (!Array.isArray(value)) throw new Error('Invalid ACKB ignoredIndices response');
|
|
13
|
+
const seen = new Set<number>();
|
|
14
|
+
for (const index of value) {
|
|
15
|
+
if (!Number.isInteger(index) || index < 0 || index >= size || seen.has(index)) {
|
|
16
|
+
throw new Error('Invalid ACKB ignoredIndices response');
|
|
17
|
+
}
|
|
18
|
+
seen.add(index);
|
|
19
|
+
}
|
|
20
|
+
return [...seen];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function validatedIds(value: unknown): string[] {
|
|
24
|
+
if (!Array.isArray(value) || value.some((id) => typeof id !== 'string')) {
|
|
25
|
+
throw new Error('Invalid ACKB ignoredIds response');
|
|
26
|
+
}
|
|
27
|
+
return value as string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Parse structured ACKB evidence while preserving duplicate job-ID positions. */
|
|
31
|
+
export function ignoredAckIndices(data: unknown, batch: readonly AckEntry[]): ReadonlySet<number> {
|
|
32
|
+
if (data === undefined) return new Set();
|
|
33
|
+
const payload = record(data);
|
|
34
|
+
if (!payload) throw new Error('Invalid ACKB response data');
|
|
35
|
+
const hasIndices = Object.hasOwn(payload, 'ignoredIndices');
|
|
36
|
+
const hasIds = Object.hasOwn(payload, 'ignoredIds');
|
|
37
|
+
if (!hasIndices) throw new Error('Invalid ACKB ignoredIndices response');
|
|
38
|
+
|
|
39
|
+
const ids = hasIds ? validatedIds(payload.ignoredIds) : null;
|
|
40
|
+
const indices = validatedIndices(payload.ignoredIndices, batch.length);
|
|
41
|
+
if (ids) {
|
|
42
|
+
if (ids.length !== indices.length) throw new Error('Mismatched ACKB ignored evidence');
|
|
43
|
+
for (let offset = 0; offset < indices.length; offset++) {
|
|
44
|
+
if (batch[indices[offset]]?.id !== ids[offset]) {
|
|
45
|
+
throw new Error('Mismatched ACKB ignored evidence');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return new Set(indices);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Parse a single ACK/FAIL response; historical applied responses have no data. */
|
|
53
|
+
export function terminalOutcomeWasApplied(data: unknown): boolean {
|
|
54
|
+
if (data === undefined) return true;
|
|
55
|
+
const payload = record(data);
|
|
56
|
+
if (payload?.applied === false && payload.reason === 'already-finalized') return false;
|
|
57
|
+
throw new Error('Invalid terminal outcome response data');
|
|
58
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -104,12 +104,9 @@ export function wireJobOptions(opts: JobOptions = {}): Record<string, unknown> {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
export function jobPayload(name: string, data: unknown):
|
|
109
|
-
|
|
110
|
-
return { name, ...(data as Record<string, unknown>) };
|
|
111
|
-
}
|
|
112
|
-
return data === undefined || data === null ? { name } : { name, payload: data };
|
|
107
|
+
/** Build the protocol-owned name field without changing user data. */
|
|
108
|
+
export function jobPayload(name: string, data: unknown): { name: string; data: unknown } {
|
|
109
|
+
return { name, data };
|
|
113
110
|
}
|
|
114
111
|
|
|
115
112
|
export interface JobCounts {
|
package/src/worker-base.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
7
7
|
import { EventEmitter } from 'node:events';
|
|
8
8
|
import { hostname } from 'node:os';
|
|
9
9
|
import { Connection } from './connection.js';
|
|
10
|
+
import type { Response } from './connection-types.js';
|
|
10
11
|
import {
|
|
11
12
|
MAX_POLL_TIMEOUT_MS,
|
|
12
13
|
sleep,
|
|
@@ -182,13 +183,15 @@ export class WorkerBase<T = unknown, R = unknown> extends EventEmitter {
|
|
|
182
183
|
this.emit('closed');
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
/** Dispatch a command
|
|
186
|
-
*
|
|
187
|
-
|
|
188
|
-
|
|
186
|
+
/** Dispatch a command and route failures to 'error'. The optional outcome
|
|
187
|
+
* parser decides whether a successful response authorizes local effects. */
|
|
188
|
+
protected async safeCall(
|
|
189
|
+
command: Record<string, unknown> & { cmd: string },
|
|
190
|
+
outcome: (response: Response) => boolean = () => true
|
|
191
|
+
): Promise<boolean> {
|
|
189
192
|
try {
|
|
190
|
-
await this.connection.call(command);
|
|
191
|
-
return
|
|
193
|
+
const response = await this.connection.call(command);
|
|
194
|
+
return outcome(response);
|
|
192
195
|
} catch (err) {
|
|
193
196
|
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
194
197
|
return false;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** One-shot wake-up used by the pull loop while every worker slot is busy. */
|
|
2
|
+
export class SlotSignal {
|
|
3
|
+
private waiter: (() => void) | null = null;
|
|
4
|
+
|
|
5
|
+
wait(timeoutMs: number): Promise<void> {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
let settled = false;
|
|
8
|
+
const finish = () => {
|
|
9
|
+
if (settled) return;
|
|
10
|
+
settled = true;
|
|
11
|
+
clearTimeout(timer);
|
|
12
|
+
if (this.waiter === finish) this.waiter = null;
|
|
13
|
+
resolve();
|
|
14
|
+
};
|
|
15
|
+
const timer = setTimeout(finish, timeoutMs);
|
|
16
|
+
this.waiter = finish;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
notify(): void {
|
|
21
|
+
this.waiter?.();
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/worker.ts
CHANGED
|
@@ -12,7 +12,9 @@ import { CommandTimeoutError, ConnectionClosedError, UnrecoverableError } from '
|
|
|
12
12
|
import { compact } from './frame.js';
|
|
13
13
|
import { Job } from './job.js';
|
|
14
14
|
import type { PulledJobsResponse } from './responses.js';
|
|
15
|
+
import { terminalOutcomeWasApplied } from './terminal-outcome.js';
|
|
15
16
|
import { WorkerBase } from './worker-base.js';
|
|
17
|
+
import { SlotSignal } from './worker-slot-signal.js';
|
|
16
18
|
import {
|
|
17
19
|
MAX_STACK_LINES,
|
|
18
20
|
type Processor,
|
|
@@ -24,6 +26,7 @@ import {
|
|
|
24
26
|
export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
25
27
|
private readonly processor: Processor<T, R>;
|
|
26
28
|
private readonly ackBatcher: AckBatcher | null;
|
|
29
|
+
private readonly slotSignal = new SlotSignal();
|
|
27
30
|
|
|
28
31
|
constructor(queue: string, processor: Processor<T, R>, opts: WorkerOptions = {}) {
|
|
29
32
|
super(queue, opts);
|
|
@@ -83,7 +86,7 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
|
83
86
|
private async pollOnce(): Promise<void> {
|
|
84
87
|
const free = this.concurrency - this.active.size;
|
|
85
88
|
if (free <= 0) {
|
|
86
|
-
await
|
|
89
|
+
await this.slotSignal.wait(20);
|
|
87
90
|
return;
|
|
88
91
|
}
|
|
89
92
|
|
|
@@ -140,11 +143,11 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
|
140
143
|
id: job.id,
|
|
141
144
|
token,
|
|
142
145
|
result: result ?? undefined,
|
|
143
|
-
onSettled: (err) => {
|
|
146
|
+
onSettled: (err, applied) => {
|
|
144
147
|
this.finishJob(job.id);
|
|
145
148
|
if (err) {
|
|
146
149
|
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
147
|
-
} else {
|
|
150
|
+
} else if (applied) {
|
|
148
151
|
this.processed += 1;
|
|
149
152
|
this.emit('completed', job, result);
|
|
150
153
|
}
|
|
@@ -153,7 +156,8 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
|
153
156
|
return;
|
|
154
157
|
}
|
|
155
158
|
const acked = await this.safeCall(
|
|
156
|
-
compact({ cmd: 'ACK', id: job.id, token, result: result ?? undefined }) as { cmd: string }
|
|
159
|
+
compact({ cmd: 'ACK', id: job.id, token, result: result ?? undefined }) as { cmd: string },
|
|
160
|
+
(response) => terminalOutcomeWasApplied(response.data)
|
|
157
161
|
);
|
|
158
162
|
// Free the slot BEFORE emitting: a throwing 'completed' listener must
|
|
159
163
|
// not leak the active slot (same rationale as the batched path).
|
|
@@ -177,7 +181,8 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
|
177
181
|
error: error.message || error.name,
|
|
178
182
|
stack,
|
|
179
183
|
unrecoverable: err instanceof UnrecoverableError ? true : undefined,
|
|
180
|
-
}) as { cmd: string }
|
|
184
|
+
}) as { cmd: string },
|
|
185
|
+
(response) => terminalOutcomeWasApplied(response.data)
|
|
181
186
|
);
|
|
182
187
|
this.finishJob(job.id);
|
|
183
188
|
// Same asymmetry guard as the ACK path: if the FAIL never reached the
|
|
@@ -192,6 +197,7 @@ export class Worker<T = unknown, R = unknown> extends WorkerBase<T, R> {
|
|
|
192
197
|
private finishJob(id: string): void {
|
|
193
198
|
this.active.delete(id);
|
|
194
199
|
this.cancelledJobs.delete(id);
|
|
200
|
+
this.slotSignal.notify();
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
// --------------------------------------------------------------- heartbeat
|
package/dist/backpressure.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Backpressure gate: bounds the number of in-flight commands on a connection.
|
|
3
|
-
*
|
|
4
|
-
* When the in-flight count reaches `max`, `acquire()` parks the caller until a
|
|
5
|
-
* slot frees (a pending command settles). This turns unbounded memory growth
|
|
6
|
-
* under a fast producer / slow server into cooperative flow control. `max <= 0`
|
|
7
|
-
* disables the gate (unbounded, the default).
|
|
8
|
-
*/
|
|
9
|
-
export class Backpressure {
|
|
10
|
-
max;
|
|
11
|
-
onWait;
|
|
12
|
-
waiters = [];
|
|
13
|
-
constructor(max, onWait) {
|
|
14
|
-
this.max = max;
|
|
15
|
-
this.onWait = onWait;
|
|
16
|
-
}
|
|
17
|
-
/** Resolve immediately if under the limit, else park until a slot frees. */
|
|
18
|
-
acquire(inFlight) {
|
|
19
|
-
if (this.max <= 0 || inFlight < this.max)
|
|
20
|
-
return;
|
|
21
|
-
this.onWait?.();
|
|
22
|
-
return new Promise((resolve) => {
|
|
23
|
-
this.waiters.push(resolve);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/** Release one parked caller (call when a pending command settles). */
|
|
27
|
-
release() {
|
|
28
|
-
this.waiters.shift()?.();
|
|
29
|
-
}
|
|
30
|
-
/** Release every parked caller (call on teardown so none hang forever). */
|
|
31
|
-
clear() {
|
|
32
|
-
while (this.waiters.length > 0)
|
|
33
|
-
this.waiters.shift()?.();
|
|
34
|
-
}
|
|
35
|
-
/** Number of callers currently parked. */
|
|
36
|
-
get waiting() {
|
|
37
|
-
return this.waiters.length;
|
|
38
|
-
}
|
|
39
|
-
}
|
package/dist/bunqueue/aging.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bunqueue Simple Mode — priority aging.
|
|
3
|
-
* Port of src/client/bunqueue/aging.ts: automatically boosts the priority of
|
|
4
|
-
* old waiting jobs. Same semantics; the job scan goes over TCP (GetJobs on
|
|
5
|
-
* the waiting and prioritized states) instead of the embedded manager.
|
|
6
|
-
*/
|
|
7
|
-
export class PriorityAger {
|
|
8
|
-
timer = null;
|
|
9
|
-
config;
|
|
10
|
-
queue;
|
|
11
|
-
constructor(config, queue) {
|
|
12
|
-
this.config = config;
|
|
13
|
-
this.queue = queue;
|
|
14
|
-
}
|
|
15
|
-
start() {
|
|
16
|
-
const interval = this.config.interval ?? 60000;
|
|
17
|
-
this.timer = setInterval(() => {
|
|
18
|
-
void this.tick();
|
|
19
|
-
}, interval);
|
|
20
|
-
this.timer.unref?.();
|
|
21
|
-
}
|
|
22
|
-
async tick() {
|
|
23
|
-
const minAge = this.config.minAge ?? 60000;
|
|
24
|
-
const boost = this.config.boost ?? 1;
|
|
25
|
-
const maxPriority = this.config.maxPriority ?? 100;
|
|
26
|
-
const maxScan = this.config.maxScan ?? 100;
|
|
27
|
-
// Both waiting and prioritized jobs (priority > 0 means "prioritized")
|
|
28
|
-
const [waiting, prioritized] = await Promise.all([
|
|
29
|
-
this.queue.getJobs({ state: 'waiting', start: 0, end: maxScan }),
|
|
30
|
-
this.queue.getJobs({ state: 'prioritized', start: 0, end: maxScan }),
|
|
31
|
-
]);
|
|
32
|
-
const jobs = [...waiting, ...prioritized];
|
|
33
|
-
const now = Date.now();
|
|
34
|
-
for (const job of jobs) {
|
|
35
|
-
const age = now - job.timestamp;
|
|
36
|
-
if (age >= minAge && job.priority < maxPriority) {
|
|
37
|
-
const newPriority = Math.min(job.priority + boost, maxPriority);
|
|
38
|
-
try {
|
|
39
|
-
await this.queue.changeJobPriority(job.id, { priority: newPriority });
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
// Best-effort — the job may have been processed meanwhile
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
destroy() {
|
|
48
|
-
if (this.timer) {
|
|
49
|
-
clearInterval(this.timer);
|
|
50
|
-
this.timer = null;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|