@blokjs/runner 0.2.2 → 0.4.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/dist/Configuration.d.ts +18 -0
- package/dist/Configuration.js +151 -4
- package/dist/Configuration.js.map +1 -1
- package/dist/PayloadTooLargeError.d.ts +19 -0
- package/dist/PayloadTooLargeError.js +29 -0
- package/dist/PayloadTooLargeError.js.map +1 -0
- package/dist/RunCancelledError.d.ts +17 -0
- package/dist/RunCancelledError.js +25 -0
- package/dist/RunCancelledError.js.map +1 -0
- package/dist/RunnerSteps.js +330 -33
- package/dist/RunnerSteps.js.map +1 -1
- package/dist/SubworkflowNode.d.ts +75 -0
- package/dist/SubworkflowNode.js +221 -0
- package/dist/SubworkflowNode.js.map +1 -0
- package/dist/TriggerBase.d.ts +128 -0
- package/dist/TriggerBase.js +773 -4
- package/dist/TriggerBase.js.map +1 -1
- package/dist/WaitDispatchRequest.d.ts +38 -0
- package/dist/WaitDispatchRequest.js +13 -0
- package/dist/WaitDispatchRequest.js.map +1 -0
- package/dist/WaitNode.d.ts +23 -0
- package/dist/WaitNode.js +26 -0
- package/dist/WaitNode.js.map +1 -0
- package/dist/concurrency/ConcurrencyBackend.d.ts +61 -0
- package/dist/concurrency/ConcurrencyBackend.js +20 -0
- package/dist/concurrency/ConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/ConcurrencyLimitError.d.ts +37 -0
- package/dist/concurrency/ConcurrencyLimitError.js +16 -0
- package/dist/concurrency/ConcurrencyLimitError.js.map +1 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.d.ts +64 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.js +297 -0
- package/dist/concurrency/NatsKvConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/QueueExpiredError.d.ts +40 -0
- package/dist/concurrency/QueueExpiredError.js +15 -0
- package/dist/concurrency/QueueExpiredError.js.map +1 -0
- package/dist/concurrency/createConcurrencyBackend.d.ts +23 -0
- package/dist/concurrency/createConcurrencyBackend.js +34 -0
- package/dist/concurrency/createConcurrencyBackend.js.map +1 -0
- package/dist/concurrency/readConcurrencyConfig.d.ts +60 -0
- package/dist/concurrency/readConcurrencyConfig.js +60 -0
- package/dist/concurrency/readConcurrencyConfig.js.map +1 -0
- package/dist/idempotency/resolveIdempotencyKey.d.ts +20 -0
- package/dist/idempotency/resolveIdempotencyKey.js +37 -0
- package/dist/idempotency/resolveIdempotencyKey.js.map +1 -0
- package/dist/index.d.ts +23 -3
- package/dist/index.js +47 -2
- package/dist/index.js.map +1 -1
- package/dist/monitoring/ConcurrencyMetrics.d.ts +56 -0
- package/dist/monitoring/ConcurrencyMetrics.js +107 -0
- package/dist/monitoring/ConcurrencyMetrics.js.map +1 -0
- package/dist/monitoring/JanitorMetrics.d.ts +27 -0
- package/dist/monitoring/JanitorMetrics.js +48 -0
- package/dist/monitoring/JanitorMetrics.js.map +1 -0
- package/dist/scheduling/DebounceCoordinator.d.ts +88 -0
- package/dist/scheduling/DebounceCoordinator.js +141 -0
- package/dist/scheduling/DebounceCoordinator.js.map +1 -0
- package/dist/scheduling/DeferredDispatchSignal.d.ts +50 -0
- package/dist/scheduling/DeferredDispatchSignal.js +14 -0
- package/dist/scheduling/DeferredDispatchSignal.js.map +1 -0
- package/dist/scheduling/DeferredRunScheduler.d.ts +68 -0
- package/dist/scheduling/DeferredRunScheduler.js +154 -0
- package/dist/scheduling/DeferredRunScheduler.js.map +1 -0
- package/dist/scheduling/readSchedulingConfig.d.ts +24 -0
- package/dist/scheduling/readSchedulingConfig.js +52 -0
- package/dist/scheduling/readSchedulingConfig.js.map +1 -0
- package/dist/timeouts/StepTimeoutError.d.ts +22 -0
- package/dist/timeouts/StepTimeoutError.js +31 -0
- package/dist/timeouts/StepTimeoutError.js.map +1 -0
- package/dist/tracing/InMemoryRunStore.d.ts +28 -1
- package/dist/tracing/InMemoryRunStore.js +150 -0
- package/dist/tracing/InMemoryRunStore.js.map +1 -1
- package/dist/tracing/Janitor.d.ts +70 -0
- package/dist/tracing/Janitor.js +150 -0
- package/dist/tracing/Janitor.js.map +1 -0
- package/dist/tracing/PostgresRunStore.d.ts +30 -0
- package/dist/tracing/PostgresRunStore.js +435 -3
- package/dist/tracing/PostgresRunStore.js.map +1 -1
- package/dist/tracing/RunStore.d.ts +100 -1
- package/dist/tracing/RunTracker.d.ts +238 -9
- package/dist/tracing/RunTracker.js +571 -1
- package/dist/tracing/RunTracker.js.map +1 -1
- package/dist/tracing/SqliteRunStore.d.ts +23 -1
- package/dist/tracing/SqliteRunStore.js +405 -6
- package/dist/tracing/SqliteRunStore.js.map +1 -1
- package/dist/tracing/TraceRouter.d.ts +20 -2
- package/dist/tracing/TraceRouter.js +249 -5
- package/dist/tracing/TraceRouter.js.map +1 -1
- package/dist/tracing/sanitize.d.ts +11 -0
- package/dist/tracing/sanitize.js +29 -0
- package/dist/tracing/sanitize.js.map +1 -1
- package/dist/tracing/types.d.ts +348 -2
- package/dist/utils/createChildContext.d.ts +32 -0
- package/dist/utils/createChildContext.js +113 -0
- package/dist/utils/createChildContext.js.map +1 -0
- package/dist/workflow/WorkflowNormalizer.d.ts +29 -41
- package/dist/workflow/WorkflowNormalizer.js +182 -0
- package/dist/workflow/WorkflowNormalizer.js.map +1 -1
- package/dist/workflow/WorkflowRegistry.d.ts +64 -0
- package/dist/workflow/WorkflowRegistry.js +81 -0
- package/dist/workflow/WorkflowRegistry.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -46,10 +46,28 @@ import { GraphQLSchemaGenerator } from "./graphql/GraphQLSchemaGenerator";
|
|
|
46
46
|
import { NodeDependencyGraph } from "./visualization/NodeDependencyGraph";
|
|
47
47
|
import { WorkflowVisualizer } from "./visualization/WorkflowVisualizer";
|
|
48
48
|
import { PerformanceProfiler } from "./monitoring/PerformanceProfiler";
|
|
49
|
+
import { Janitor } from "./tracing/Janitor";
|
|
49
50
|
import { RunTracker } from "./tracing/RunTracker";
|
|
50
51
|
import { registerTraceRoutes } from "./tracing/TraceRouter";
|
|
51
52
|
import { TracingLogger } from "./tracing/TracingLogger";
|
|
52
|
-
import { sanitize as traceSanitize } from "./tracing/sanitize";
|
|
53
|
+
import { redactSensitive as traceRedactSensitive, sanitize as traceSanitize } from "./tracing/sanitize";
|
|
54
|
+
import { type RegisteredWorkflow, WorkflowRegistry } from "./workflow/WorkflowRegistry";
|
|
55
|
+
import { ConcurrencyLimitError, type ConcurrencyLimitInfo, isConcurrencyLimitError } from "./concurrency/ConcurrencyLimitError";
|
|
56
|
+
import { QueueExpiredError, type QueueExpiredInfo, isQueueExpiredError } from "./concurrency/QueueExpiredError";
|
|
57
|
+
import type { ConcurrencyBackend } from "./concurrency/ConcurrencyBackend";
|
|
58
|
+
import { NatsKvConcurrencyBackend, type NatsKvConcurrencyConfig, readNatsKvConfigFromEnv } from "./concurrency/NatsKvConcurrencyBackend";
|
|
59
|
+
import { createConcurrencyBackend } from "./concurrency/createConcurrencyBackend";
|
|
60
|
+
import { CONCURRENCY_DEFAULTS, type NormalizedConcurrencyConfig, readConcurrencyConfig } from "./concurrency/readConcurrencyConfig";
|
|
61
|
+
import { StepTimeoutError, isStepTimeoutError } from "./timeouts/StepTimeoutError";
|
|
62
|
+
import { RunCancelledError, isRunCancelledError } from "./RunCancelledError";
|
|
63
|
+
import { PayloadTooLargeError, isPayloadTooLargeError } from "./PayloadTooLargeError";
|
|
64
|
+
import { WaitDispatchRequest, isWaitDispatchRequest } from "./WaitDispatchRequest";
|
|
65
|
+
import { ConcurrencyMetrics } from "./monitoring/ConcurrencyMetrics";
|
|
66
|
+
import { JanitorMetrics } from "./monitoring/JanitorMetrics";
|
|
67
|
+
import { DebounceCoordinator } from "./scheduling/DebounceCoordinator";
|
|
68
|
+
import { type DeferredDispatchInfo, DeferredDispatchSignal, isDeferredDispatchSignal } from "./scheduling/DeferredDispatchSignal";
|
|
69
|
+
import { DeferredRunScheduler, type DeferredScheduleOptions } from "./scheduling/DeferredRunScheduler";
|
|
70
|
+
import { type NormalizedDebounceConfig, type NormalizedSchedulingConfig, SCHEDULING_DEFAULTS, readSchedulingConfig } from "./scheduling/readSchedulingConfig";
|
|
53
71
|
import { CostEstimator } from "./cost/CostEstimator";
|
|
54
72
|
import { DEFAULT_DURATIONS, DEFAULT_MEMORY, PRICING, getRuntimeCategory } from "./cost/pricing";
|
|
55
73
|
import { SentryIntegration } from "./integrations/SentryIntegration";
|
|
@@ -77,9 +95,10 @@ import Trigger from "./types/Trigger";
|
|
|
77
95
|
import TriggerHttp from "./types/TriggerHttp";
|
|
78
96
|
import TriggerResponse from "./types/TriggerResponse";
|
|
79
97
|
import Triggers from "./types/Triggers";
|
|
80
|
-
export { Configuration, Runner, ConfigurationResolver, DefaultLogger, LocalStorage, ResolverBase, TriggerBase, RuntimeRegistry, RuntimeAdapterNode, NodeJsRuntimeAdapter, DockerRuntimeAdapter, HttpRuntimeAdapter, BunRuntimeAdapter, WasmRuntimeAdapter, GrpcRuntimeAdapter, GrpcClientPool, buildCredentials, buildChannelOptions, NodeRuntimeService, encodeExecuteRequest, decodeExecuteResponse, jsonToBuffer, bufferToJson, GRPC_STATUS_MAP, GRPC_DEFAULTS, DEFAULT_GRPC_PORTS, DEFAULT_HEALTH_SERVICE_CONFIG, categoryToGrpcStatus, isServiceError, grpcToBlokError, resolveTransportForKind, defineNode, FunctionNode, HealthCheck, RateLimiter, CircuitBreaker, CircuitOpenError, TriggerMetricsCollector, PrometheusMetricsBridge, bootstrapPrometheus, resetPrometheusBootstrap, RuntimeCatalog, RuntimeDiscovery, RuntimeHealthMonitor, RuntimeMetricsDashboard, RuntimeAutoScaler, FileWatcher, HotReloadManager, HmrDevConsole, AuthMiddleware, JWTAuthProvider, APIKeyAuthProvider, RBAC, createDefaultRBAC, ABACEngine, createDefaultABAC, AuditLogger, ConsoleAuditSink, FileAuditSink, InMemoryAuditSink, OAuthOIDCProvider, TokenCache, SecretManager, EnvironmentSecretProvider, InMemorySecretProvider, VaultSecretProvider, AWSSecretsProvider, GCPSecretProvider, OpenAPIGenerator, GraphQLSchemaGenerator, WorkflowVisualizer, NodeDependencyGraph, PerformanceProfiler, RunTracker, registerTraceRoutes, TracingLogger, traceSanitize, CostEstimator, PRICING, DEFAULT_DURATIONS, DEFAULT_MEMORY, getRuntimeCategory, SentryIntegration, InMemoryCache, NodeResultCache, NodeTestHarness, WorkflowTestRunner, TestLogger, Condition, Conditions, Config, Flow, Inputs, Node, Properties, Targets, Trigger, TriggerHttp, Triggers, ParamsDictionary, GlobalOptions, NodeMap, JsonLikeObject, BlokService, BlokResponse, IBlokResponse, RunnerSteps, Average, TriggerResponse, };
|
|
98
|
+
export { Configuration, Runner, ConfigurationResolver, DefaultLogger, LocalStorage, ResolverBase, TriggerBase, RuntimeRegistry, RuntimeAdapterNode, NodeJsRuntimeAdapter, DockerRuntimeAdapter, HttpRuntimeAdapter, BunRuntimeAdapter, WasmRuntimeAdapter, GrpcRuntimeAdapter, GrpcClientPool, buildCredentials, buildChannelOptions, NodeRuntimeService, encodeExecuteRequest, decodeExecuteResponse, jsonToBuffer, bufferToJson, GRPC_STATUS_MAP, GRPC_DEFAULTS, DEFAULT_GRPC_PORTS, DEFAULT_HEALTH_SERVICE_CONFIG, categoryToGrpcStatus, isServiceError, grpcToBlokError, resolveTransportForKind, defineNode, FunctionNode, HealthCheck, RateLimiter, CircuitBreaker, CircuitOpenError, TriggerMetricsCollector, PrometheusMetricsBridge, bootstrapPrometheus, resetPrometheusBootstrap, RuntimeCatalog, RuntimeDiscovery, RuntimeHealthMonitor, RuntimeMetricsDashboard, RuntimeAutoScaler, FileWatcher, HotReloadManager, HmrDevConsole, AuthMiddleware, JWTAuthProvider, APIKeyAuthProvider, RBAC, createDefaultRBAC, ABACEngine, createDefaultABAC, AuditLogger, ConsoleAuditSink, FileAuditSink, InMemoryAuditSink, OAuthOIDCProvider, TokenCache, SecretManager, EnvironmentSecretProvider, InMemorySecretProvider, VaultSecretProvider, AWSSecretsProvider, GCPSecretProvider, OpenAPIGenerator, GraphQLSchemaGenerator, WorkflowVisualizer, NodeDependencyGraph, PerformanceProfiler, RunTracker, Janitor, registerTraceRoutes, WorkflowRegistry, type RegisteredWorkflow, ConcurrencyLimitError, type ConcurrencyLimitInfo, isConcurrencyLimitError, QueueExpiredError, type QueueExpiredInfo, isQueueExpiredError, readConcurrencyConfig, type NormalizedConcurrencyConfig, CONCURRENCY_DEFAULTS, type ConcurrencyBackend, createConcurrencyBackend, NatsKvConcurrencyBackend, type NatsKvConcurrencyConfig, readNatsKvConfigFromEnv, StepTimeoutError, isStepTimeoutError, RunCancelledError, isRunCancelledError, PayloadTooLargeError, isPayloadTooLargeError, WaitDispatchRequest, isWaitDispatchRequest, ConcurrencyMetrics, JanitorMetrics, DeferredDispatchSignal, type DeferredDispatchInfo, isDeferredDispatchSignal, DeferredRunScheduler, type DeferredScheduleOptions, DebounceCoordinator, readSchedulingConfig, type NormalizedDebounceConfig, type NormalizedSchedulingConfig, SCHEDULING_DEFAULTS, TracingLogger, traceSanitize, traceRedactSensitive, CostEstimator, PRICING, DEFAULT_DURATIONS, DEFAULT_MEMORY, getRuntimeCategory, SentryIntegration, InMemoryCache, NodeResultCache, NodeTestHarness, WorkflowTestRunner, TestLogger, Condition, Conditions, Config, Flow, Inputs, Node, Properties, Targets, Trigger, TriggerHttp, Triggers, ParamsDictionary, GlobalOptions, NodeMap, JsonLikeObject, BlokService, BlokResponse, IBlokResponse, RunnerSteps, Average, TriggerResponse, };
|
|
81
99
|
export type { RuntimeAdapter, RuntimeKind, ExecutionResult, FnNodeDefinition };
|
|
82
100
|
export type { HttpRuntimeAdapterOptions } from "./adapters/HttpRuntimeAdapter";
|
|
101
|
+
export type { TraceAuthorizeFn, TraceRouterOptions } from "./tracing/TraceRouter";
|
|
83
102
|
export type { GrpcAdapterConfig, KeepaliveConfig, TlsConfig, Transport, } from "./adapters/grpc/types";
|
|
84
103
|
export type { DecodedExecuteResponse, DecodedLogLine, DecodedMetrics, DecodedNodeError, ExecuteRequestProto, ExecuteResponseProto, LogLineProto, MetricsProto, NodeErrorProto, NodeRefProto, RuntimeStateProto, StepInfoProto, TriggerInfoProto, WorkflowInfoProto, ExecuteOptionsProto, } from "./adapters/grpc/GrpcCodec";
|
|
85
104
|
export type { GrpcErrorContext } from "./adapters/grpc/GrpcErrors";
|
|
@@ -114,6 +133,7 @@ export type { CacheProvider, CacheEntry, CacheSetOptions, CacheStats, InMemoryCa
|
|
|
114
133
|
export type { LogEntry } from "./testing/TestLogger";
|
|
115
134
|
export type { TestContextOverrides, TestResult, TestMetrics } from "./testing/TestHarness";
|
|
116
135
|
export type { WorkflowTestConfig, WorkflowTestResult, ExecutionTrace, WorkflowExecuteOptions, } from "./testing/WorkflowTestRunner";
|
|
117
|
-
export type { WorkflowRun, WorkflowRunStatus, NodeRun, NodeRunStatus, RunEvent, RunEventType, TraceLogEntry, WorkflowSummary as TraceWorkflowSummary, WorkflowDetail as TraceWorkflowDetail, PaginatedResult, StartRunOptions, StartNodeOptions, } from "./tracing/types";
|
|
136
|
+
export type { WorkflowRun, WorkflowRunStatus, NodeRun, NodeRunStatus, RunEvent, RunEventType, TraceLogEntry, WorkflowSummary as TraceWorkflowSummary, WorkflowDetail as TraceWorkflowDetail, PaginatedResult, StartRunOptions, StartNodeOptions, ScheduledDispatchRow, } from "./tracing/types";
|
|
137
|
+
export type { JanitorStats } from "./tracing/Janitor";
|
|
118
138
|
export { createStore, InMemoryRunStore, SqliteRunStore } from "./tracing";
|
|
119
139
|
export type { CreateStoreOptions, StoreType } from "./tracing";
|
package/dist/index.js
CHANGED
|
@@ -56,10 +56,37 @@ import { WorkflowVisualizer } from "./visualization/WorkflowVisualizer";
|
|
|
56
56
|
// Performance Profiling
|
|
57
57
|
import { PerformanceProfiler } from "./monitoring/PerformanceProfiler";
|
|
58
58
|
// Tracing (Blok Studio)
|
|
59
|
+
import { Janitor } from "./tracing/Janitor";
|
|
59
60
|
import { RunTracker } from "./tracing/RunTracker";
|
|
60
61
|
import { registerTraceRoutes } from "./tracing/TraceRouter";
|
|
61
62
|
import { TracingLogger } from "./tracing/TracingLogger";
|
|
62
|
-
import { sanitize as traceSanitize } from "./tracing/sanitize";
|
|
63
|
+
import { redactSensitive as traceRedactSensitive, sanitize as traceSanitize } from "./tracing/sanitize";
|
|
64
|
+
// Workflow registry (Tier 2 sub-workflow primitive)
|
|
65
|
+
import { WorkflowRegistry } from "./workflow/WorkflowRegistry";
|
|
66
|
+
// Concurrency gate (Tier 2 #6)
|
|
67
|
+
import { ConcurrencyLimitError, isConcurrencyLimitError, } from "./concurrency/ConcurrencyLimitError";
|
|
68
|
+
// Queue-mode TTL expiry (PR 1-5 polish · 410 Gone vs 429)
|
|
69
|
+
import { QueueExpiredError, isQueueExpiredError } from "./concurrency/QueueExpiredError";
|
|
70
|
+
import { NatsKvConcurrencyBackend, readNatsKvConfigFromEnv, } from "./concurrency/NatsKvConcurrencyBackend";
|
|
71
|
+
import { createConcurrencyBackend } from "./concurrency/createConcurrencyBackend";
|
|
72
|
+
import { CONCURRENCY_DEFAULTS, readConcurrencyConfig, } from "./concurrency/readConcurrencyConfig";
|
|
73
|
+
// Per-step timeout (Tier 2 quick-wins)
|
|
74
|
+
import { StepTimeoutError, isStepTimeoutError } from "./timeouts/StepTimeoutError";
|
|
75
|
+
// Cooperative cancellation (Tier 2 follow-up)
|
|
76
|
+
import { RunCancelledError, isRunCancelledError } from "./RunCancelledError";
|
|
77
|
+
// Durable-scheduler payload size cap (PR 2 A4)
|
|
78
|
+
import { PayloadTooLargeError, isPayloadTooLargeError } from "./PayloadTooLargeError";
|
|
79
|
+
// Wait step primitive (PR 4)
|
|
80
|
+
import { WaitDispatchRequest, isWaitDispatchRequest } from "./WaitDispatchRequest";
|
|
81
|
+
// Concurrency / scheduling OTel metrics (Tier 2 follow-up)
|
|
82
|
+
import { ConcurrencyMetrics } from "./monitoring/ConcurrencyMetrics";
|
|
83
|
+
// Janitor sweep OTel metrics (PR 3 D3)
|
|
84
|
+
import { JanitorMetrics } from "./monitoring/JanitorMetrics";
|
|
85
|
+
// Scheduling — delay / TTL / debounce (Tier 2 #5 + #7)
|
|
86
|
+
import { DebounceCoordinator } from "./scheduling/DebounceCoordinator";
|
|
87
|
+
import { DeferredDispatchSignal, isDeferredDispatchSignal, } from "./scheduling/DeferredDispatchSignal";
|
|
88
|
+
import { DeferredRunScheduler } from "./scheduling/DeferredRunScheduler";
|
|
89
|
+
import { SCHEDULING_DEFAULTS, readSchedulingConfig, } from "./scheduling/readSchedulingConfig";
|
|
63
90
|
// Cost Estimation
|
|
64
91
|
import { CostEstimator } from "./cost/CostEstimator";
|
|
65
92
|
import { DEFAULT_DURATIONS, DEFAULT_MEMORY, PRICING, getRuntimeCategory } from "./cost/pricing";
|
|
@@ -104,7 +131,25 @@ WorkflowVisualizer, NodeDependencyGraph,
|
|
|
104
131
|
// Performance Profiling
|
|
105
132
|
PerformanceProfiler,
|
|
106
133
|
// Tracing (Blok Studio)
|
|
107
|
-
RunTracker,
|
|
134
|
+
RunTracker, Janitor, registerTraceRoutes, WorkflowRegistry,
|
|
135
|
+
// Concurrency gate (Tier 2 #6)
|
|
136
|
+
ConcurrencyLimitError, isConcurrencyLimitError,
|
|
137
|
+
// Queue-mode TTL expiry (PR 1-5 polish)
|
|
138
|
+
QueueExpiredError, isQueueExpiredError, readConcurrencyConfig, CONCURRENCY_DEFAULTS, createConcurrencyBackend, NatsKvConcurrencyBackend, readNatsKvConfigFromEnv,
|
|
139
|
+
// Per-step timeout (Tier 2 quick-wins)
|
|
140
|
+
StepTimeoutError, isStepTimeoutError,
|
|
141
|
+
// Cooperative cancellation (Tier 2 follow-up)
|
|
142
|
+
RunCancelledError, isRunCancelledError,
|
|
143
|
+
// Durable-scheduler payload size cap (PR 2 A4)
|
|
144
|
+
PayloadTooLargeError, isPayloadTooLargeError,
|
|
145
|
+
// Wait step primitive (PR 4)
|
|
146
|
+
WaitDispatchRequest, isWaitDispatchRequest,
|
|
147
|
+
// Concurrency / scheduling OTel metrics (Tier 2 follow-up)
|
|
148
|
+
ConcurrencyMetrics,
|
|
149
|
+
// Janitor sweep OTel metrics (PR 3 D3)
|
|
150
|
+
JanitorMetrics,
|
|
151
|
+
// Scheduling — delay / TTL / debounce (Tier 2 #5 + #7)
|
|
152
|
+
DeferredDispatchSignal, isDeferredDispatchSignal, DeferredRunScheduler, DebounceCoordinator, readSchedulingConfig, SCHEDULING_DEFAULTS, TracingLogger, traceSanitize, traceRedactSensitive,
|
|
108
153
|
// Cost Estimation
|
|
109
154
|
CostEstimator, PRICING, DEFAULT_DURATIONS, DEFAULT_MEMORY, getRuntimeCategory,
|
|
110
155
|
// Integrations
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAC5C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,YAAY,MAAM,gBAAgB,CAAC;AAC1C,OAAO,MAAM,MAAM,UAAU,CAAC;AAC9B,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,mBAAmB;AACnB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,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B,gBAAgB;AAEhB,+BAA+B;AAC/B,qBAAqB,EAErB,uBAAuB;AACvB,wCAAwC;AACxC,iBAAiB,EAEjB,mBAAmB,EACnB,qBAAqB,EAErB,oBAAoB,EAGpB,wBAAwB,EACxB,wBAAwB,EAExB,uBAAuB;AACvB,uCAAuC;AACvC,gBAAgB,EAChB,kBAAkB;AAClB,8CAA8C;AAC9C,iBAAiB,EACjB,mBAAmB;AACnB,+CAA+C;AAC/C,oBAAoB,EACpB,sBAAsB;AACtB,6BAA6B;AAC7B,mBAAmB,EACnB,qBAAqB;AACrB,2DAA2D;AAC3D,kBAAkB;AAClB,uCAAuC;AACvC,cAAc;AACd,uDAAuD;AACvD,sBAAsB,EAEtB,wBAAwB,EACxB,oBAAoB,EAEpB,mBAAmB,EACnB,oBAAoB,EAGpB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,oBAAoB;AACpB,kBAAkB;AAClB,aAAa,EACb,OAAO,EACP,iBAAiB,EACjB,cAAc,EACd,kBAAkB;AAClB,eAAe;AACf,iBAAiB;AACjB,QAAQ;AACR,aAAa,EACb,eAAe;AACf,UAAU;AACV,eAAe,EACf,kBAAkB,EAClB,UAAU,EAeV,OAAO,EAEP,WAAW,EACX,YAAY,EAEZ,WAAW,GAGX,CAAC;AAsRF,iEAAiE;AACjE,qEAAqE;AACrE,kDAAkD;AAClD,sEAAsE;AACtE,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier 2 follow-up · OpenTelemetry counters for concurrency + scheduling
|
|
3
|
+
* resource lifecycle events.
|
|
4
|
+
*
|
|
5
|
+
* Wired into:
|
|
6
|
+
* - `TriggerBase.run`'s concurrency gate — `recordAcquired` /
|
|
7
|
+
* `recordDenied` / `recordReleased` per slot operation.
|
|
8
|
+
* - `HttpTrigger.recoverDispatches` — `recordDispatchRecovered` /
|
|
9
|
+
* `recordDispatchExpired` for boot-recovery observability.
|
|
10
|
+
* - The scheduler / debounce coordinator — `recordDispatchFired`
|
|
11
|
+
* when a deferred timer fires successfully.
|
|
12
|
+
*
|
|
13
|
+
* Singleton; lazy-instantiated. No-ops cleanly when OTel isn't
|
|
14
|
+
* configured (the meter API silently swallows recordings without
|
|
15
|
+
* an exporter).
|
|
16
|
+
*/
|
|
17
|
+
interface ConcurrencyAttributes {
|
|
18
|
+
workflow_name: string;
|
|
19
|
+
concurrency_key?: string;
|
|
20
|
+
}
|
|
21
|
+
interface SchedulingAttributes {
|
|
22
|
+
workflow_name: string;
|
|
23
|
+
trigger_type: string;
|
|
24
|
+
dispatch_status?: string;
|
|
25
|
+
}
|
|
26
|
+
export declare class ConcurrencyMetrics {
|
|
27
|
+
private static instance;
|
|
28
|
+
private readonly acquiredCounter;
|
|
29
|
+
private readonly deniedCounter;
|
|
30
|
+
private readonly releasedCounter;
|
|
31
|
+
private readonly dispatchRecoveredCounter;
|
|
32
|
+
private readonly dispatchExpiredCounter;
|
|
33
|
+
private readonly dispatchFiredCounter;
|
|
34
|
+
private readonly backendInstallCounter;
|
|
35
|
+
private readonly occRetriesHistogram;
|
|
36
|
+
private constructor();
|
|
37
|
+
static getInstance(): ConcurrencyMetrics;
|
|
38
|
+
/** Test-only — drop the singleton so re-import gets fresh meters. */
|
|
39
|
+
static resetInstance(): void;
|
|
40
|
+
recordAcquired(attrs: ConcurrencyAttributes): void;
|
|
41
|
+
recordDenied(attrs: ConcurrencyAttributes & {
|
|
42
|
+
mode: "throw" | "queue";
|
|
43
|
+
}): void;
|
|
44
|
+
recordReleased(attrs: ConcurrencyAttributes): void;
|
|
45
|
+
recordDispatchRecovered(attrs: SchedulingAttributes): void;
|
|
46
|
+
recordDispatchExpired(attrs: SchedulingAttributes): void;
|
|
47
|
+
recordDispatchFired(attrs: SchedulingAttributes): void;
|
|
48
|
+
recordBackendInstall(attrs: {
|
|
49
|
+
backend: string;
|
|
50
|
+
status: "success" | "failure";
|
|
51
|
+
}): void;
|
|
52
|
+
recordOccRetries(attrs: ConcurrencyAttributes & {
|
|
53
|
+
outcome: "success" | "denied" | "fail-closed";
|
|
54
|
+
}, attempts: number): void;
|
|
55
|
+
}
|
|
56
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier 2 follow-up · OpenTelemetry counters for concurrency + scheduling
|
|
3
|
+
* resource lifecycle events.
|
|
4
|
+
*
|
|
5
|
+
* Wired into:
|
|
6
|
+
* - `TriggerBase.run`'s concurrency gate — `recordAcquired` /
|
|
7
|
+
* `recordDenied` / `recordReleased` per slot operation.
|
|
8
|
+
* - `HttpTrigger.recoverDispatches` — `recordDispatchRecovered` /
|
|
9
|
+
* `recordDispatchExpired` for boot-recovery observability.
|
|
10
|
+
* - The scheduler / debounce coordinator — `recordDispatchFired`
|
|
11
|
+
* when a deferred timer fires successfully.
|
|
12
|
+
*
|
|
13
|
+
* Singleton; lazy-instantiated. No-ops cleanly when OTel isn't
|
|
14
|
+
* configured (the meter API silently swallows recordings without
|
|
15
|
+
* an exporter).
|
|
16
|
+
*/
|
|
17
|
+
import { metrics } from "@opentelemetry/api";
|
|
18
|
+
export class ConcurrencyMetrics {
|
|
19
|
+
static instance = null;
|
|
20
|
+
acquiredCounter = metrics.getMeter("blok").createCounter("blok_concurrency_acquired_total", {
|
|
21
|
+
description: "Total concurrency slots acquired (per workflow + key).",
|
|
22
|
+
unit: "1",
|
|
23
|
+
});
|
|
24
|
+
deniedCounter = metrics.getMeter("blok").createCounter("blok_concurrency_denied_total", {
|
|
25
|
+
description: "Total concurrency slot denials (limit hit; throttled or queued).",
|
|
26
|
+
unit: "1",
|
|
27
|
+
});
|
|
28
|
+
releasedCounter = metrics.getMeter("blok").createCounter("blok_concurrency_released_total", {
|
|
29
|
+
description: "Total concurrency slots released (run reached terminal state).",
|
|
30
|
+
unit: "1",
|
|
31
|
+
});
|
|
32
|
+
dispatchRecoveredCounter = metrics
|
|
33
|
+
.getMeter("blok")
|
|
34
|
+
.createCounter("blok_scheduling_dispatch_recovered_total", {
|
|
35
|
+
description: "Scheduled dispatches re-registered on boot recovery (HttpTrigger).",
|
|
36
|
+
unit: "1",
|
|
37
|
+
});
|
|
38
|
+
dispatchExpiredCounter = metrics
|
|
39
|
+
.getMeter("blok")
|
|
40
|
+
.createCounter("blok_scheduling_dispatch_expired_total", {
|
|
41
|
+
description: "Scheduled dispatches marked expired on boot recovery (TTL elapsed).",
|
|
42
|
+
unit: "1",
|
|
43
|
+
});
|
|
44
|
+
dispatchFiredCounter = metrics
|
|
45
|
+
.getMeter("blok")
|
|
46
|
+
.createCounter("blok_scheduling_dispatch_fired_total", {
|
|
47
|
+
description: "Scheduled dispatches fired by the in-process scheduler.",
|
|
48
|
+
unit: "1",
|
|
49
|
+
});
|
|
50
|
+
// PR 3 D1 — backend install observability. Operators who misconfigure
|
|
51
|
+
// the cross-process backend (NATS KV unreachable / auth failure) get a
|
|
52
|
+
// silent fallback to the in-process backend. This counter surfaces
|
|
53
|
+
// install attempts so misconfiguration is visible in metrics.
|
|
54
|
+
backendInstallCounter = metrics
|
|
55
|
+
.getMeter("blok")
|
|
56
|
+
.createCounter("blok_concurrency_backend_install_total", {
|
|
57
|
+
description: "Concurrency backend install attempts (success / failure).",
|
|
58
|
+
unit: "1",
|
|
59
|
+
});
|
|
60
|
+
// PR 3 D2 — OCC retry depth histogram. The 95% fail-close rate at
|
|
61
|
+
// 200-way contention seen in LOAD-TESTS.md is invisible without a
|
|
62
|
+
// histogram. Recorded per acquireSlot exit point with bucket
|
|
63
|
+
// boundaries [0, 1, 2, 3, 5, 10] — OCC retry budget caps at 10.
|
|
64
|
+
occRetriesHistogram = metrics.getMeter("blok").createHistogram("blok_concurrency_occ_retries", {
|
|
65
|
+
description: "OCC retry attempts on cross-process concurrency backends.",
|
|
66
|
+
unit: "{retries}",
|
|
67
|
+
advice: { explicitBucketBoundaries: [0, 1, 2, 3, 5, 10] },
|
|
68
|
+
});
|
|
69
|
+
constructor() { }
|
|
70
|
+
static getInstance() {
|
|
71
|
+
if (!ConcurrencyMetrics.instance) {
|
|
72
|
+
ConcurrencyMetrics.instance = new ConcurrencyMetrics();
|
|
73
|
+
}
|
|
74
|
+
return ConcurrencyMetrics.instance;
|
|
75
|
+
}
|
|
76
|
+
/** Test-only — drop the singleton so re-import gets fresh meters. */
|
|
77
|
+
static resetInstance() {
|
|
78
|
+
ConcurrencyMetrics.instance = null;
|
|
79
|
+
}
|
|
80
|
+
recordAcquired(attrs) {
|
|
81
|
+
this.acquiredCounter.add(1, attrs);
|
|
82
|
+
}
|
|
83
|
+
recordDenied(attrs) {
|
|
84
|
+
this.deniedCounter.add(1, attrs);
|
|
85
|
+
}
|
|
86
|
+
recordReleased(attrs) {
|
|
87
|
+
this.releasedCounter.add(1, attrs);
|
|
88
|
+
}
|
|
89
|
+
recordDispatchRecovered(attrs) {
|
|
90
|
+
this.dispatchRecoveredCounter.add(1, attrs);
|
|
91
|
+
}
|
|
92
|
+
recordDispatchExpired(attrs) {
|
|
93
|
+
this.dispatchExpiredCounter.add(1, attrs);
|
|
94
|
+
}
|
|
95
|
+
recordDispatchFired(attrs) {
|
|
96
|
+
this.dispatchFiredCounter.add(1, attrs);
|
|
97
|
+
}
|
|
98
|
+
// PR 3 D1 — backend install attempt outcome.
|
|
99
|
+
recordBackendInstall(attrs) {
|
|
100
|
+
this.backendInstallCounter.add(1, attrs);
|
|
101
|
+
}
|
|
102
|
+
// PR 3 D2 — OCC retry depth + outcome (success | denied | fail-closed).
|
|
103
|
+
recordOccRetries(attrs, attempts) {
|
|
104
|
+
this.occRetriesHistogram.record(attempts, attrs);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=ConcurrencyMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConcurrencyMetrics.js","sourceRoot":"","sources":["../../src/monitoring/ConcurrencyMetrics.ts"],"names":[],"mapp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CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,EAAE,KAA0C,CAAC,CAAC;IAChF,CAAC;IAED,mBAAmB,CAAC,KAA2B;QAC9C,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC,EAAE,KAA0C,CAAC,CAAC;IAC9E,CAAC;IAED,6CAA6C;IAC7C,oBAAoB,CAAC,KAAyD;QAC7E,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC,EAAE,KAA0C,CAAC,CAAC;IAC/E,CAAC;IAED,wEAAwE;IACxE,gBAAgB,CACf,KAAgF,EAChF,QAAgB;QAEhB,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,QAAQ,EAAE,KAA0C,CAAC,CAAC;IACvF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR 3 D3 — OpenTelemetry metrics for the Janitor sweep.
|
|
3
|
+
*
|
|
4
|
+
* Operators tuning `BLOK_JANITOR_INTERVAL_MS` need real numbers per
|
|
5
|
+
* sweep: how long does each table's purge take, how many rows did it
|
|
6
|
+
* remove? This singleton exposes a histogram for sweep duration and a
|
|
7
|
+
* counter for purged rows, both labeled by the table being swept.
|
|
8
|
+
*
|
|
9
|
+
* Wired into `Janitor.runOnce` per-table after each purge call.
|
|
10
|
+
*
|
|
11
|
+
* No-op cleanly when OTel isn't configured (the meter API silently
|
|
12
|
+
* swallows recordings without an exporter).
|
|
13
|
+
*/
|
|
14
|
+
interface JanitorAttributes {
|
|
15
|
+
table: "idempotency_cache" | "concurrency_locks" | "scheduled_dispatches";
|
|
16
|
+
}
|
|
17
|
+
export declare class JanitorMetrics {
|
|
18
|
+
private static instance;
|
|
19
|
+
private readonly sweepDurationHistogram;
|
|
20
|
+
private readonly purgedCounter;
|
|
21
|
+
private constructor();
|
|
22
|
+
static getInstance(): JanitorMetrics;
|
|
23
|
+
/** Test-only — drop the singleton so re-import gets fresh meters. */
|
|
24
|
+
static resetInstance(): void;
|
|
25
|
+
recordSweep(attrs: JanitorAttributes, durationMs: number, rowsPurged: number): void;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PR 3 D3 — OpenTelemetry metrics for the Janitor sweep.
|
|
3
|
+
*
|
|
4
|
+
* Operators tuning `BLOK_JANITOR_INTERVAL_MS` need real numbers per
|
|
5
|
+
* sweep: how long does each table's purge take, how many rows did it
|
|
6
|
+
* remove? This singleton exposes a histogram for sweep duration and a
|
|
7
|
+
* counter for purged rows, both labeled by the table being swept.
|
|
8
|
+
*
|
|
9
|
+
* Wired into `Janitor.runOnce` per-table after each purge call.
|
|
10
|
+
*
|
|
11
|
+
* No-op cleanly when OTel isn't configured (the meter API silently
|
|
12
|
+
* swallows recordings without an exporter).
|
|
13
|
+
*/
|
|
14
|
+
import { metrics } from "@opentelemetry/api";
|
|
15
|
+
export class JanitorMetrics {
|
|
16
|
+
static instance = null;
|
|
17
|
+
sweepDurationHistogram = metrics.getMeter("blok").createHistogram("blok_janitor_sweep_duration_ms", {
|
|
18
|
+
description: "Janitor sweep duration per table.",
|
|
19
|
+
unit: "ms",
|
|
20
|
+
advice: { explicitBucketBoundaries: [1, 5, 10, 50, 100, 500, 1000, 5000, 30000] },
|
|
21
|
+
});
|
|
22
|
+
purgedCounter = metrics.getMeter("blok").createCounter("blok_janitor_purged_total", {
|
|
23
|
+
description: "Total rows purged by the Janitor per table.",
|
|
24
|
+
unit: "1",
|
|
25
|
+
});
|
|
26
|
+
constructor() { }
|
|
27
|
+
static getInstance() {
|
|
28
|
+
if (!JanitorMetrics.instance) {
|
|
29
|
+
JanitorMetrics.instance = new JanitorMetrics();
|
|
30
|
+
}
|
|
31
|
+
return JanitorMetrics.instance;
|
|
32
|
+
}
|
|
33
|
+
/** Test-only — drop the singleton so re-import gets fresh meters. */
|
|
34
|
+
static resetInstance() {
|
|
35
|
+
JanitorMetrics.instance = null;
|
|
36
|
+
}
|
|
37
|
+
recordSweep(attrs, durationMs, rowsPurged) {
|
|
38
|
+
this.sweepDurationHistogram.record(durationMs, attrs);
|
|
39
|
+
// Review fix-up · GAP-2. Always record the counter, even when zero.
|
|
40
|
+
// Without zero-row recordings, operators can't distinguish
|
|
41
|
+
// "Janitor running, table clean" from "Janitor not running" by
|
|
42
|
+
// looking at the counter alone. The duration histogram captures
|
|
43
|
+
// liveness too, but pairing them under the same emit cadence
|
|
44
|
+
// keeps dashboards consistent.
|
|
45
|
+
this.purgedCounter.add(rowsPurged, attrs);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=JanitorMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JanitorMetrics.js","sourceRoot":"","sources":["../../src/monitoring/JanitorMetrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAM7C,MAAM,OAAO,cAAc;IAClB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAErC,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,gCAAgC,EAAE;QACpH,WAAW,EAAE,mCAAmC;QAChD,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,EAAE,wBAAwB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE;KACjF,CAAC,CAAC;IAEc,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,2BAA2B,EAAE;QACpG,WAAW,EAAE,6CAA6C;QAC1D,IAAI,EAAE,GAAG;KACT,CAAC,CAAC;IAEH,gBAAuB,CAAC;IAExB,MAAM,CAAC,WAAW;QACjB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC9B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QAChD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,qEAAqE;IACrE,MAAM,CAAC,aAAa;QACnB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IAChC,CAAC;IAED,WAAW,CAAC,KAAwB,EAAE,UAAkB,EAAE,UAAkB;QAC3E,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,UAAU,EAAE,KAA0C,CAAC,CAAC;QAC3F,oEAAoE;QACpE,2DAA2D;QAC3D,+DAA+D;QAC/D,gEAAgE;QAChE,6DAA6D;QAC7D,+BAA+B;QAC/B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,KAA0C,CAAC,CAAC;IAChF,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tier 2 #7 — in-memory debounce coordinator.
|
|
3
|
+
*
|
|
4
|
+
* Coalesces rapid same-key triggers into a single delayed run. Modes:
|
|
5
|
+
*
|
|
6
|
+
* - `"trailing"` (default): each ping resets a timer; the run fires
|
|
7
|
+
* after `delayMs` of silence. Latest payload wins. `maxDelayMs`
|
|
8
|
+
* bounds tail latency — even with continuous pings, the run fires
|
|
9
|
+
* after `maxDelayMs` from the FIRST ping.
|
|
10
|
+
* - `"leading"`: the first ping fires immediately. Subsequent pings
|
|
11
|
+
* within `delayMs` are dropped. Window resets after `delayMs` of
|
|
12
|
+
* silence.
|
|
13
|
+
*
|
|
14
|
+
* Process-wide singleton. In-memory only for v1 — cross-process
|
|
15
|
+
* debounce keys are a deferred follow-up.
|
|
16
|
+
*/
|
|
17
|
+
export type DebounceDispatchFn = () => Promise<void>;
|
|
18
|
+
export type DebounceMode = "leading" | "trailing";
|
|
19
|
+
export interface DebounceRegisterOpts {
|
|
20
|
+
workflowName: string;
|
|
21
|
+
debounceKey: string;
|
|
22
|
+
mode: DebounceMode;
|
|
23
|
+
delayMs: number;
|
|
24
|
+
maxDelayMs?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Run id allocated by the caller for THIS ping. On a fresh window
|
|
27
|
+
* this becomes the active run id; on a coalesce it's a "loser" and
|
|
28
|
+
* the caller marks it `debounced` terminal.
|
|
29
|
+
*/
|
|
30
|
+
runId: string;
|
|
31
|
+
/**
|
|
32
|
+
* Callback the coordinator invokes when the trailing-mode window
|
|
33
|
+
* closes. Captures ctx + runId via closure. NOT called for leading
|
|
34
|
+
* mode (the caller runs the first ping synchronously) or for
|
|
35
|
+
* coalesce pings (those are dropped by definition).
|
|
36
|
+
*/
|
|
37
|
+
onFire: DebounceDispatchFn;
|
|
38
|
+
/**
|
|
39
|
+
* Test-only override of "now" for deterministic tests. Production
|
|
40
|
+
* code does not pass this.
|
|
41
|
+
*/
|
|
42
|
+
__now?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The outcome of `register`. Branches the caller's behavior.
|
|
46
|
+
*
|
|
47
|
+
* - `"fire-immediate"` (leading + fresh window) — caller runs the
|
|
48
|
+
* workflow synchronously. The window is now open; subsequent pings
|
|
49
|
+
* in `delayMs` are suppressed.
|
|
50
|
+
* - `"schedule-trailing"` (trailing + fresh window) — caller marks the
|
|
51
|
+
* run `debounced` (transient) and throws `DeferredDispatchSignal`.
|
|
52
|
+
* The coordinator's timer will invoke `onFire` after the window.
|
|
53
|
+
* - `"coalesce"` (leading or trailing + existing window) — caller marks
|
|
54
|
+
* the run `debounced` (terminal, with `intoRunId = activeRunId`) and
|
|
55
|
+
* throws `DeferredDispatchSignal`. The active run absorbs the ping.
|
|
56
|
+
*/
|
|
57
|
+
export interface DebounceRegisterResult {
|
|
58
|
+
outcome: "fire-immediate" | "schedule-trailing" | "coalesce";
|
|
59
|
+
/**
|
|
60
|
+
* The runId of the run that owns the active window. Equal to
|
|
61
|
+
* `opts.runId` on `fire-immediate` and `schedule-trailing`; equal to
|
|
62
|
+
* the EXISTING window's runId on `coalesce` (so the caller knows
|
|
63
|
+
* which run absorbed the ping).
|
|
64
|
+
*/
|
|
65
|
+
activeRunId: string;
|
|
66
|
+
/** Dispatch time for trailing windows; undefined on `fire-immediate`. */
|
|
67
|
+
scheduledAt?: number;
|
|
68
|
+
/** Pings absorbed by the active window so far (including this one). */
|
|
69
|
+
pingCount: number;
|
|
70
|
+
}
|
|
71
|
+
export declare class DebounceCoordinator {
|
|
72
|
+
private static instance;
|
|
73
|
+
private states;
|
|
74
|
+
static getInstance(): DebounceCoordinator;
|
|
75
|
+
/** Test-only — reset the singleton + clear all state. */
|
|
76
|
+
static resetInstance(): void;
|
|
77
|
+
private bucket;
|
|
78
|
+
register(opts: DebounceRegisterOpts): DebounceRegisterResult;
|
|
79
|
+
private fireTrailing;
|
|
80
|
+
/** Cancel an active window without firing. Returns true if cancelled. */
|
|
81
|
+
cancel(workflowName: string, debounceKey: string): boolean;
|
|
82
|
+
/** Number of active debounce windows. Tests + observability. */
|
|
83
|
+
size(): number;
|
|
84
|
+
/** True if a window is open for `(workflow, key)`. */
|
|
85
|
+
has(workflowName: string, debounceKey: string): boolean;
|
|
86
|
+
/** Cancel everything without firing. */
|
|
87
|
+
clear(): void;
|
|
88
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
export class DebounceCoordinator {
|
|
2
|
+
static instance = null;
|
|
3
|
+
states = new Map();
|
|
4
|
+
static getInstance() {
|
|
5
|
+
if (!DebounceCoordinator.instance) {
|
|
6
|
+
DebounceCoordinator.instance = new DebounceCoordinator();
|
|
7
|
+
}
|
|
8
|
+
return DebounceCoordinator.instance;
|
|
9
|
+
}
|
|
10
|
+
/** Test-only — reset the singleton + clear all state. */
|
|
11
|
+
static resetInstance() {
|
|
12
|
+
DebounceCoordinator.instance?.clear();
|
|
13
|
+
DebounceCoordinator.instance = null;
|
|
14
|
+
}
|
|
15
|
+
bucket(workflowName, debounceKey) {
|
|
16
|
+
return `${workflowName}\x1f${debounceKey}`;
|
|
17
|
+
}
|
|
18
|
+
register(opts) {
|
|
19
|
+
const now = opts.__now ?? Date.now();
|
|
20
|
+
const bucketKey = this.bucket(opts.workflowName, opts.debounceKey);
|
|
21
|
+
const existing = this.states.get(bucketKey);
|
|
22
|
+
// === Leading mode ===
|
|
23
|
+
if (opts.mode === "leading") {
|
|
24
|
+
if (existing) {
|
|
25
|
+
// Window active — coalesce this ping (drop the run).
|
|
26
|
+
existing.pingCount += 1;
|
|
27
|
+
existing.lastPingAt = now;
|
|
28
|
+
return {
|
|
29
|
+
outcome: "coalesce",
|
|
30
|
+
activeRunId: existing.activeRunId,
|
|
31
|
+
pingCount: existing.pingCount,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
// Open a new window. Caller fires synchronously; coordinator just
|
|
35
|
+
// tracks state to suppress follow-ups for `delayMs`.
|
|
36
|
+
const state = {
|
|
37
|
+
bucketKey,
|
|
38
|
+
mode: "leading",
|
|
39
|
+
delayMs: opts.delayMs,
|
|
40
|
+
maxDelayMs: opts.maxDelayMs,
|
|
41
|
+
firstPingAt: now,
|
|
42
|
+
lastPingAt: now,
|
|
43
|
+
pingCount: 1,
|
|
44
|
+
activeRunId: opts.runId,
|
|
45
|
+
};
|
|
46
|
+
// Auto-close the window after delayMs of silence — clear state so
|
|
47
|
+
// subsequent pings start fresh.
|
|
48
|
+
state.timer = setTimeout(() => {
|
|
49
|
+
const cur = this.states.get(bucketKey);
|
|
50
|
+
if (cur && cur.lastPingAt + opts.delayMs <= Date.now()) {
|
|
51
|
+
this.states.delete(bucketKey);
|
|
52
|
+
}
|
|
53
|
+
}, opts.delayMs);
|
|
54
|
+
this.states.set(bucketKey, state);
|
|
55
|
+
return { outcome: "fire-immediate", activeRunId: opts.runId, pingCount: 1 };
|
|
56
|
+
}
|
|
57
|
+
// === Trailing mode ===
|
|
58
|
+
if (existing) {
|
|
59
|
+
// Extend the window: cancel the old timer, set a new one. Latest
|
|
60
|
+
// payload wins via the captured `onFire`.
|
|
61
|
+
if (existing.timer)
|
|
62
|
+
clearTimeout(existing.timer);
|
|
63
|
+
existing.pingCount += 1;
|
|
64
|
+
existing.lastPingAt = now;
|
|
65
|
+
existing.onFire = opts.onFire;
|
|
66
|
+
const naiveDeadline = now + opts.delayMs;
|
|
67
|
+
const dispatchAt = existing.maxDelayDeadline !== undefined ? Math.min(naiveDeadline, existing.maxDelayDeadline) : naiveDeadline;
|
|
68
|
+
const wait = Math.max(0, dispatchAt - now);
|
|
69
|
+
existing.timer = setTimeout(() => this.fireTrailing(bucketKey), wait);
|
|
70
|
+
return {
|
|
71
|
+
outcome: "coalesce",
|
|
72
|
+
activeRunId: existing.activeRunId,
|
|
73
|
+
scheduledAt: dispatchAt,
|
|
74
|
+
pingCount: existing.pingCount,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
// New trailing window.
|
|
78
|
+
const state = {
|
|
79
|
+
bucketKey,
|
|
80
|
+
mode: "trailing",
|
|
81
|
+
delayMs: opts.delayMs,
|
|
82
|
+
maxDelayMs: opts.maxDelayMs,
|
|
83
|
+
firstPingAt: now,
|
|
84
|
+
lastPingAt: now,
|
|
85
|
+
pingCount: 1,
|
|
86
|
+
activeRunId: opts.runId,
|
|
87
|
+
maxDelayDeadline: opts.maxDelayMs !== undefined ? now + opts.maxDelayMs : undefined,
|
|
88
|
+
onFire: opts.onFire,
|
|
89
|
+
};
|
|
90
|
+
const naiveDeadline = now + opts.delayMs;
|
|
91
|
+
const dispatchAt = state.maxDelayDeadline !== undefined ? Math.min(naiveDeadline, state.maxDelayDeadline) : naiveDeadline;
|
|
92
|
+
const wait = Math.max(0, dispatchAt - now);
|
|
93
|
+
state.timer = setTimeout(() => this.fireTrailing(bucketKey), wait);
|
|
94
|
+
this.states.set(bucketKey, state);
|
|
95
|
+
return {
|
|
96
|
+
outcome: "schedule-trailing",
|
|
97
|
+
activeRunId: opts.runId,
|
|
98
|
+
scheduledAt: dispatchAt,
|
|
99
|
+
pingCount: 1,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
fireTrailing(bucketKey) {
|
|
103
|
+
const state = this.states.get(bucketKey);
|
|
104
|
+
if (!state)
|
|
105
|
+
return;
|
|
106
|
+
this.states.delete(bucketKey);
|
|
107
|
+
if (state.onFire) {
|
|
108
|
+
void state.onFire().catch((err) => {
|
|
109
|
+
console.error(`[blok][scheduling] DebounceCoordinator trailing-fire failed for key ${bucketKey}:`, err instanceof Error ? err.stack || err.message : err);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Cancel an active window without firing. Returns true if cancelled. */
|
|
114
|
+
cancel(workflowName, debounceKey) {
|
|
115
|
+
const bucketKey = this.bucket(workflowName, debounceKey);
|
|
116
|
+
const state = this.states.get(bucketKey);
|
|
117
|
+
if (!state)
|
|
118
|
+
return false;
|
|
119
|
+
if (state.timer)
|
|
120
|
+
clearTimeout(state.timer);
|
|
121
|
+
this.states.delete(bucketKey);
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
/** Number of active debounce windows. Tests + observability. */
|
|
125
|
+
size() {
|
|
126
|
+
return this.states.size;
|
|
127
|
+
}
|
|
128
|
+
/** True if a window is open for `(workflow, key)`. */
|
|
129
|
+
has(workflowName, debounceKey) {
|
|
130
|
+
return this.states.has(this.bucket(workflowName, debounceKey));
|
|
131
|
+
}
|
|
132
|
+
/** Cancel everything without firing. */
|
|
133
|
+
clear() {
|
|
134
|
+
for (const state of this.states.values()) {
|
|
135
|
+
if (state.timer)
|
|
136
|
+
clearTimeout(state.timer);
|
|
137
|
+
}
|
|
138
|
+
this.states.clear();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=DebounceCoordinator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebounceCoordinator.js","sourceRoot":"","sources":["../../src/scheduling/DebounceCoordinator.ts"],"names":[],"mappings":"AA4FA,MAAM,OAAO,mBAAmB;IACvB,MAAM,CAAC,QA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