@trigger.dev/redis-worker 4.5.0-rc.3 → 4.5.0-rc.5

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/index.d.cts CHANGED
@@ -2147,6 +2147,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2147
2147
  status: z.ZodEnum<["QUEUED", "DRAINING", "FAILED"]>;
2148
2148
  attempts: z.ZodEffects<z.ZodString, number, string>;
2149
2149
  createdAt: z.ZodEffects<z.ZodString, Date, string>;
2150
+ createdAtMicros: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
2151
+ materialised: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodLiteral<"true">, z.ZodLiteral<"false">]>, boolean, "true" | "false">>;
2152
+ idempotencyLookupKey: z.ZodDefault<z.ZodOptional<z.ZodString>>;
2153
+ metadataVersion: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
2150
2154
  lastError: z.ZodOptional<z.ZodEffects<z.ZodString, {
2151
2155
  message: string;
2152
2156
  code: string;
@@ -2159,6 +2163,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2159
2163
  envId: string;
2160
2164
  orgId: string;
2161
2165
  attempts: number;
2166
+ createdAtMicros: number;
2167
+ materialised: boolean;
2168
+ idempotencyLookupKey: string;
2169
+ metadataVersion: number;
2162
2170
  lastError?: {
2163
2171
  message: string;
2164
2172
  code: string;
@@ -2171,6 +2179,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2171
2179
  envId: string;
2172
2180
  orgId: string;
2173
2181
  attempts: string;
2182
+ createdAtMicros?: string | undefined;
2183
+ materialised?: "true" | "false" | undefined;
2184
+ idempotencyLookupKey?: string | undefined;
2185
+ metadataVersion?: string | undefined;
2174
2186
  lastError?: string | undefined;
2175
2187
  }>;
2176
2188
  type BufferEntry = z.infer<typeof BufferEntrySchema>;
@@ -2179,31 +2191,114 @@ declare function deserialiseSnapshot<T = unknown>(serialised: string): T;
2179
2191
 
2180
2192
  type MollifierBufferOptions = {
2181
2193
  redisOptions: RedisOptions;
2182
- entryTtlSeconds: number;
2183
2194
  logger?: Logger;
2195
+ ackGraceTtlSeconds?: number;
2196
+ maxRetriesPerRequest?: number;
2197
+ reconnectStepMs?: number;
2198
+ reconnectMaxMs?: number;
2199
+ };
2200
+ type SnapshotPatch = {
2201
+ type: "append_tags";
2202
+ tags: string[];
2203
+ maxTags?: number;
2204
+ } | {
2205
+ type: "set_metadata";
2206
+ metadata: string;
2207
+ metadataType: string;
2208
+ } | {
2209
+ type: "set_delay";
2210
+ delayUntil: string;
2211
+ } | {
2212
+ type: "mark_cancelled";
2213
+ cancelledAt: string;
2214
+ cancelReason?: string;
2215
+ };
2216
+ type MutateSnapshotResult = "applied_to_snapshot" | "not_found" | "busy" | "limit_exceeded";
2217
+ type CasSetMetadataResult = {
2218
+ kind: "applied";
2219
+ newVersion: number;
2220
+ } | {
2221
+ kind: "version_conflict";
2222
+ currentVersion: number;
2223
+ } | {
2224
+ kind: "not_found";
2225
+ } | {
2226
+ kind: "busy";
2227
+ };
2228
+ type AcceptResult = {
2229
+ kind: "accepted";
2230
+ } | {
2231
+ kind: "duplicate_run_id";
2232
+ } | {
2233
+ kind: "duplicate_idempotency";
2234
+ existingRunId: string;
2235
+ };
2236
+ type IdempotencyLookupInput = {
2237
+ envId: string;
2238
+ taskIdentifier: string;
2239
+ idempotencyKey: string;
2240
+ };
2241
+ declare function idempotencyLookupKeyFor(input: IdempotencyLookupInput): string;
2242
+ declare function makeIdempotencyClaimKey(input: IdempotencyLookupInput): string;
2243
+ type IdempotencyClaimResult = {
2244
+ kind: "claimed";
2245
+ } | {
2246
+ kind: "pending";
2247
+ } | {
2248
+ kind: "resolved";
2249
+ runId: string;
2184
2250
  };
2185
2251
  declare class MollifierBuffer {
2186
2252
  #private;
2187
2253
  private readonly redis;
2188
- private readonly entryTtlSeconds;
2189
2254
  private readonly logger;
2255
+ private readonly ackGraceTtlSeconds;
2190
2256
  constructor(options: MollifierBufferOptions);
2191
2257
  accept(input: {
2192
2258
  runId: string;
2193
2259
  envId: string;
2194
2260
  orgId: string;
2195
2261
  payload: string;
2196
- }): Promise<boolean>;
2262
+ idempotencyKey?: string;
2263
+ taskIdentifier?: string;
2264
+ }): Promise<AcceptResult>;
2197
2265
  pop(envId: string): Promise<BufferEntry | null>;
2198
2266
  getEntry(runId: string): Promise<BufferEntry | null>;
2199
2267
  listOrgs(): Promise<string[]>;
2200
2268
  listEnvsForOrg(orgId: string): Promise<string[]>;
2269
+ listEntriesForEnv(envId: string, maxCount: number): Promise<BufferEntry[]>;
2270
+ mutateSnapshot(runId: string, patch: SnapshotPatch): Promise<MutateSnapshotResult>;
2271
+ casSetMetadata(input: {
2272
+ runId: string;
2273
+ expectedVersion: number;
2274
+ newMetadata: string;
2275
+ newMetadataType: string;
2276
+ }): Promise<CasSetMetadataResult>;
2277
+ claimIdempotency(input: IdempotencyLookupInput & {
2278
+ token: string;
2279
+ ttlSeconds: number;
2280
+ }): Promise<IdempotencyClaimResult>;
2281
+ publishClaim(input: IdempotencyLookupInput & {
2282
+ token: string;
2283
+ runId: string;
2284
+ ttlSeconds: number;
2285
+ }): Promise<boolean>;
2286
+ releaseClaim(input: IdempotencyLookupInput & {
2287
+ token: string;
2288
+ }): Promise<void>;
2289
+ readClaim(input: IdempotencyLookupInput): Promise<IdempotencyClaimResult | null>;
2290
+ lookupIdempotency(input: IdempotencyLookupInput): Promise<string | null>;
2291
+ resetIdempotency(input: IdempotencyLookupInput): Promise<{
2292
+ clearedRunId: string | null;
2293
+ }>;
2201
2294
  ack(runId: string): Promise<void>;
2202
2295
  requeue(runId: string): Promise<void>;
2203
2296
  fail(runId: string, error: {
2204
2297
  code: string;
2205
2298
  message: string;
2206
2299
  }): Promise<boolean>;
2300
+ getDrainingCount(): Promise<number>;
2301
+ listStaleDraining(olderThanMs: number, limit: number): Promise<string[]>;
2207
2302
  getEntryTtlSeconds(runId: string): Promise<number>;
2208
2303
  evaluateTrip(envId: string, options: {
2209
2304
  windowMs: number;
@@ -2217,10 +2312,18 @@ declare class MollifierBuffer {
2217
2312
  }
2218
2313
  declare module "@internal/redis" {
2219
2314
  interface RedisCommander<Context> {
2220
- acceptMollifierEntry(entryKey: string, queueKey: string, orgsKey: string, runId: string, envId: string, orgId: string, payload: string, createdAt: string, ttlSeconds: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2221
- popAndMarkDraining(queueKey: string, orgsKey: string, entryPrefix: string, envId: string, orgEnvsPrefix: string, callback?: Callback<string | null>): Result<string | null, Context>;
2222
- requeueMollifierEntry(entryKey: string, orgsKey: string, queuePrefix: string, runId: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2223
- failMollifierEntry(entryKey: string, errorPayload: string, callback?: Callback<number>): Result<number, Context>;
2315
+ acceptMollifierEntry(entryKey: string, queueKey: string, orgsKey: string, runId: string, envId: string, orgId: string, payload: string, createdAt: string, createdAtMicros: string, orgEnvsPrefix: string, idempotencyLookupKey: string, entryPrefix: string, callback?: Callback<number | string>): Result<number | string, Context>;
2316
+ popAndMarkDraining(queueKey: string, orgsKey: string, drainingSetKey: string, entryPrefix: string, envId: string, orgEnvsPrefix: string, callback?: Callback<string | null>): Result<string | null, Context>;
2317
+ requeueMollifierEntry(entryKey: string, orgsKey: string, drainingSetKey: string, queuePrefix: string, runId: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2318
+ mutateMollifierSnapshot(entryKey: string, patchJson: string, callback?: Callback<string>): Result<string, Context>;
2319
+ casSetMollifierMetadata(entryKey: string, expectedVersion: string, newMetadata: string, newMetadataType: string, callback?: Callback<string>): Result<string, Context>;
2320
+ resetMollifierIdempotency(lookupKey: string, entryPrefix: string, claimKey: string, callback?: Callback<string>): Result<string, Context>;
2321
+ claimMollifierIdempotency(claimKey: string, pendingMarker: string, pendingPrefix: string, ttlSeconds: string, callback?: Callback<string>): Result<string, Context>;
2322
+ publishMollifierClaim(claimKey: string, ownerMarker: string, runId: string, ttlSeconds: string, callback?: Callback<number>): Result<number, Context>;
2323
+ releaseMollifierClaim(claimKey: string, ownerMarker: string, callback?: Callback<number>): Result<number, Context>;
2324
+ ackMollifierEntry(entryKey: string, drainingSetKey: string, graceTtlSeconds: string, runId: string, callback?: Callback<number>): Result<number, Context>;
2325
+ failMollifierEntry(entryKey: string, drainingSetKey: string, errorPayload: string, runId: string, callback?: Callback<number>): Result<number, Context>;
2326
+ delMollifierKeyIfEquals(key: string, expected: string, callback?: Callback<number>): Result<number, Context>;
2224
2327
  mollifierEvaluateTrip(rateKey: string, trippedKey: string, windowMs: string, threshold: string, holdMs: string, callback?: Callback<[number, number]>): Result<[number, number], Context>;
2225
2328
  }
2226
2329
  }
@@ -2233,14 +2336,32 @@ type MollifierDrainerHandler<TPayload> = (input: {
2233
2336
  attempts: number;
2234
2337
  createdAt: Date;
2235
2338
  }) => Promise<void>;
2339
+ type MollifierDrainerTerminalFailureCause = "non-retryable" | "max-attempts-exhausted";
2340
+ type MollifierDrainerTerminalFailureHandler<TPayload> = (input: {
2341
+ runId: string;
2342
+ envId: string;
2343
+ orgId: string;
2344
+ payload: TPayload;
2345
+ attempts: number;
2346
+ createdAt: Date;
2347
+ error: {
2348
+ code: string;
2349
+ message: string;
2350
+ };
2351
+ cause: MollifierDrainerTerminalFailureCause;
2352
+ }) => Promise<void>;
2236
2353
  type MollifierDrainerOptions<TPayload> = {
2237
2354
  buffer: MollifierBuffer;
2238
2355
  handler: MollifierDrainerHandler<TPayload>;
2356
+ onTerminalFailure?: MollifierDrainerTerminalFailureHandler<TPayload>;
2239
2357
  concurrency: number;
2240
2358
  maxAttempts: number;
2241
2359
  isRetryable: (err: unknown) => boolean;
2242
2360
  pollIntervalMs?: number;
2243
2361
  maxOrgsPerTick?: number;
2362
+ drainBatchSize?: number;
2363
+ maxBackoffMs?: number;
2364
+ backoffFloorMs?: number;
2244
2365
  logger?: Logger;
2245
2366
  };
2246
2367
  type DrainResult = {
@@ -2250,12 +2371,16 @@ type DrainResult = {
2250
2371
  declare class MollifierDrainer<TPayload = unknown> {
2251
2372
  private readonly buffer;
2252
2373
  private readonly handler;
2374
+ private readonly onTerminalFailure?;
2253
2375
  private readonly maxAttempts;
2254
2376
  private readonly isRetryable;
2255
2377
  private readonly pollIntervalMs;
2256
2378
  private readonly maxOrgsPerTick;
2379
+ private readonly drainBatchSize;
2380
+ private readonly concurrency;
2381
+ private readonly maxBackoffMs;
2382
+ private readonly backoffFloorMs;
2257
2383
  private readonly logger;
2258
- private readonly limit;
2259
2384
  private orgCursor;
2260
2385
  private perOrgEnvCursors;
2261
2386
  private isRunning;
@@ -2272,8 +2397,7 @@ declare class MollifierDrainer<TPayload = unknown> {
2272
2397
  private delay;
2273
2398
  private takeOrgSlice;
2274
2399
  private pickEnvForOrg;
2275
- private processOneFromEnv;
2276
2400
  private processEntry;
2277
2401
  }
2278
2402
 
2279
- export { type AnyMessageCatalog, type AnyQueueItem, BaseScheduler, type BatchConfig, BatchedSpanManager, type BatchedSpanManagerOptions, type BufferEntry, BufferEntryError, BufferEntrySchema, BufferEntryStatus, CallbackFairQueueKeyProducer, type ClaimResult, type ConcurrencyCheckResult, type ConcurrencyGroupConfig, ConcurrencyManager, type ConcurrencyManagerOptions, type ConcurrencyState, type ConsumerLoopState, type CooloffOptions, CronSchema, CustomRetry, DRRScheduler, type DRRSchedulerConfig, type DeadLetterMessage, DefaultFairQueueKeyProducer, type DispatchSchedulerContext, type DrainResult, type EnqueueBatchOptions, type EnqueueOptions, ExponentialBackoffRetry, FairQueue, FairQueueAttributes, type FairQueueKeyProducer, type FairQueueMetrics, type FairQueueOptions, FairQueueTelemetry, type FairScheduler, FixedDelayRetry, type GlobalRateLimiter, ImmediateRetry, type InFlightMessage, type JobHandler, type JobHandlerParams, LinearBackoffRetry, MasterQueue, type MasterQueueOptions, type MessageCatalogKey, type MessageCatalogSchema, type MessageCatalogValue, type MessageHandler, type MessageHandlerContext, MessagingAttributes, MollifierBuffer, type MollifierBufferOptions, MollifierDrainer, type MollifierDrainerHandler, type MollifierDrainerOptions, NoRetry, NoopScheduler, type QueueCooloffState, type QueueDescriptor, type QueueItem, type QueueMessage, type QueueWithScore, type ReclaimedMessageInfo, type RetryOptions, type RetryStrategy, RoundRobinScheduler, type SchedulerContext, SimpleQueue, type StoredMessage, type TelemetryOptions, TenantDispatch, type TenantDispatchOptions, type TenantQueues, type TenantWithScore, VisibilityManager, type VisibilityManagerOptions, WeightedScheduler, type WeightedSchedulerBiases, type WeightedSchedulerConfig, Worker, type WorkerCatalog, type WorkerConcurrencyOptions, WorkerQueueManager, type WorkerQueueManagerOptions, type WorkerQueueOptions, createDefaultRetryStrategy, defaultRetryOptions, deserialiseSnapshot, isAbortError, noopTelemetry, serialiseSnapshot };
2403
+ export { type AcceptResult, type AnyMessageCatalog, type AnyQueueItem, BaseScheduler, type BatchConfig, BatchedSpanManager, type BatchedSpanManagerOptions, type BufferEntry, BufferEntryError, BufferEntrySchema, BufferEntryStatus, CallbackFairQueueKeyProducer, type CasSetMetadataResult, type ClaimResult, type ConcurrencyCheckResult, type ConcurrencyGroupConfig, ConcurrencyManager, type ConcurrencyManagerOptions, type ConcurrencyState, type ConsumerLoopState, type CooloffOptions, CronSchema, CustomRetry, DRRScheduler, type DRRSchedulerConfig, type DeadLetterMessage, DefaultFairQueueKeyProducer, type DispatchSchedulerContext, type DrainResult, type EnqueueBatchOptions, type EnqueueOptions, ExponentialBackoffRetry, FairQueue, FairQueueAttributes, type FairQueueKeyProducer, type FairQueueMetrics, type FairQueueOptions, FairQueueTelemetry, type FairScheduler, FixedDelayRetry, type GlobalRateLimiter, type IdempotencyClaimResult, type IdempotencyLookupInput, ImmediateRetry, type InFlightMessage, type JobHandler, type JobHandlerParams, LinearBackoffRetry, MasterQueue, type MasterQueueOptions, type MessageCatalogKey, type MessageCatalogSchema, type MessageCatalogValue, type MessageHandler, type MessageHandlerContext, MessagingAttributes, MollifierBuffer, type MollifierBufferOptions, MollifierDrainer, type MollifierDrainerHandler, type MollifierDrainerOptions, type MollifierDrainerTerminalFailureCause, type MollifierDrainerTerminalFailureHandler, type MutateSnapshotResult, NoRetry, NoopScheduler, type QueueCooloffState, type QueueDescriptor, type QueueItem, type QueueMessage, type QueueWithScore, type ReclaimedMessageInfo, type RetryOptions, type RetryStrategy, RoundRobinScheduler, type SchedulerContext, SimpleQueue, type SnapshotPatch, type StoredMessage, type TelemetryOptions, TenantDispatch, type TenantDispatchOptions, type TenantQueues, type TenantWithScore, VisibilityManager, type VisibilityManagerOptions, WeightedScheduler, type WeightedSchedulerBiases, type WeightedSchedulerConfig, Worker, type WorkerCatalog, type WorkerConcurrencyOptions, WorkerQueueManager, type WorkerQueueManagerOptions, type WorkerQueueOptions, createDefaultRetryStrategy, defaultRetryOptions, deserialiseSnapshot, idempotencyLookupKeyFor, isAbortError, makeIdempotencyClaimKey, noopTelemetry, serialiseSnapshot };
package/dist/index.d.ts CHANGED
@@ -2147,6 +2147,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2147
2147
  status: z.ZodEnum<["QUEUED", "DRAINING", "FAILED"]>;
2148
2148
  attempts: z.ZodEffects<z.ZodString, number, string>;
2149
2149
  createdAt: z.ZodEffects<z.ZodString, Date, string>;
2150
+ createdAtMicros: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
2151
+ materialised: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodLiteral<"true">, z.ZodLiteral<"false">]>, boolean, "true" | "false">>;
2152
+ idempotencyLookupKey: z.ZodDefault<z.ZodOptional<z.ZodString>>;
2153
+ metadataVersion: z.ZodDefault<z.ZodEffects<z.ZodString, number, string>>;
2150
2154
  lastError: z.ZodOptional<z.ZodEffects<z.ZodString, {
2151
2155
  message: string;
2152
2156
  code: string;
@@ -2159,6 +2163,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2159
2163
  envId: string;
2160
2164
  orgId: string;
2161
2165
  attempts: number;
2166
+ createdAtMicros: number;
2167
+ materialised: boolean;
2168
+ idempotencyLookupKey: string;
2169
+ metadataVersion: number;
2162
2170
  lastError?: {
2163
2171
  message: string;
2164
2172
  code: string;
@@ -2171,6 +2179,10 @@ declare const BufferEntrySchema: z.ZodObject<{
2171
2179
  envId: string;
2172
2180
  orgId: string;
2173
2181
  attempts: string;
2182
+ createdAtMicros?: string | undefined;
2183
+ materialised?: "true" | "false" | undefined;
2184
+ idempotencyLookupKey?: string | undefined;
2185
+ metadataVersion?: string | undefined;
2174
2186
  lastError?: string | undefined;
2175
2187
  }>;
2176
2188
  type BufferEntry = z.infer<typeof BufferEntrySchema>;
@@ -2179,31 +2191,114 @@ declare function deserialiseSnapshot<T = unknown>(serialised: string): T;
2179
2191
 
2180
2192
  type MollifierBufferOptions = {
2181
2193
  redisOptions: RedisOptions;
2182
- entryTtlSeconds: number;
2183
2194
  logger?: Logger;
2195
+ ackGraceTtlSeconds?: number;
2196
+ maxRetriesPerRequest?: number;
2197
+ reconnectStepMs?: number;
2198
+ reconnectMaxMs?: number;
2199
+ };
2200
+ type SnapshotPatch = {
2201
+ type: "append_tags";
2202
+ tags: string[];
2203
+ maxTags?: number;
2204
+ } | {
2205
+ type: "set_metadata";
2206
+ metadata: string;
2207
+ metadataType: string;
2208
+ } | {
2209
+ type: "set_delay";
2210
+ delayUntil: string;
2211
+ } | {
2212
+ type: "mark_cancelled";
2213
+ cancelledAt: string;
2214
+ cancelReason?: string;
2215
+ };
2216
+ type MutateSnapshotResult = "applied_to_snapshot" | "not_found" | "busy" | "limit_exceeded";
2217
+ type CasSetMetadataResult = {
2218
+ kind: "applied";
2219
+ newVersion: number;
2220
+ } | {
2221
+ kind: "version_conflict";
2222
+ currentVersion: number;
2223
+ } | {
2224
+ kind: "not_found";
2225
+ } | {
2226
+ kind: "busy";
2227
+ };
2228
+ type AcceptResult = {
2229
+ kind: "accepted";
2230
+ } | {
2231
+ kind: "duplicate_run_id";
2232
+ } | {
2233
+ kind: "duplicate_idempotency";
2234
+ existingRunId: string;
2235
+ };
2236
+ type IdempotencyLookupInput = {
2237
+ envId: string;
2238
+ taskIdentifier: string;
2239
+ idempotencyKey: string;
2240
+ };
2241
+ declare function idempotencyLookupKeyFor(input: IdempotencyLookupInput): string;
2242
+ declare function makeIdempotencyClaimKey(input: IdempotencyLookupInput): string;
2243
+ type IdempotencyClaimResult = {
2244
+ kind: "claimed";
2245
+ } | {
2246
+ kind: "pending";
2247
+ } | {
2248
+ kind: "resolved";
2249
+ runId: string;
2184
2250
  };
2185
2251
  declare class MollifierBuffer {
2186
2252
  #private;
2187
2253
  private readonly redis;
2188
- private readonly entryTtlSeconds;
2189
2254
  private readonly logger;
2255
+ private readonly ackGraceTtlSeconds;
2190
2256
  constructor(options: MollifierBufferOptions);
2191
2257
  accept(input: {
2192
2258
  runId: string;
2193
2259
  envId: string;
2194
2260
  orgId: string;
2195
2261
  payload: string;
2196
- }): Promise<boolean>;
2262
+ idempotencyKey?: string;
2263
+ taskIdentifier?: string;
2264
+ }): Promise<AcceptResult>;
2197
2265
  pop(envId: string): Promise<BufferEntry | null>;
2198
2266
  getEntry(runId: string): Promise<BufferEntry | null>;
2199
2267
  listOrgs(): Promise<string[]>;
2200
2268
  listEnvsForOrg(orgId: string): Promise<string[]>;
2269
+ listEntriesForEnv(envId: string, maxCount: number): Promise<BufferEntry[]>;
2270
+ mutateSnapshot(runId: string, patch: SnapshotPatch): Promise<MutateSnapshotResult>;
2271
+ casSetMetadata(input: {
2272
+ runId: string;
2273
+ expectedVersion: number;
2274
+ newMetadata: string;
2275
+ newMetadataType: string;
2276
+ }): Promise<CasSetMetadataResult>;
2277
+ claimIdempotency(input: IdempotencyLookupInput & {
2278
+ token: string;
2279
+ ttlSeconds: number;
2280
+ }): Promise<IdempotencyClaimResult>;
2281
+ publishClaim(input: IdempotencyLookupInput & {
2282
+ token: string;
2283
+ runId: string;
2284
+ ttlSeconds: number;
2285
+ }): Promise<boolean>;
2286
+ releaseClaim(input: IdempotencyLookupInput & {
2287
+ token: string;
2288
+ }): Promise<void>;
2289
+ readClaim(input: IdempotencyLookupInput): Promise<IdempotencyClaimResult | null>;
2290
+ lookupIdempotency(input: IdempotencyLookupInput): Promise<string | null>;
2291
+ resetIdempotency(input: IdempotencyLookupInput): Promise<{
2292
+ clearedRunId: string | null;
2293
+ }>;
2201
2294
  ack(runId: string): Promise<void>;
2202
2295
  requeue(runId: string): Promise<void>;
2203
2296
  fail(runId: string, error: {
2204
2297
  code: string;
2205
2298
  message: string;
2206
2299
  }): Promise<boolean>;
2300
+ getDrainingCount(): Promise<number>;
2301
+ listStaleDraining(olderThanMs: number, limit: number): Promise<string[]>;
2207
2302
  getEntryTtlSeconds(runId: string): Promise<number>;
2208
2303
  evaluateTrip(envId: string, options: {
2209
2304
  windowMs: number;
@@ -2217,10 +2312,18 @@ declare class MollifierBuffer {
2217
2312
  }
2218
2313
  declare module "@internal/redis" {
2219
2314
  interface RedisCommander<Context> {
2220
- acceptMollifierEntry(entryKey: string, queueKey: string, orgsKey: string, runId: string, envId: string, orgId: string, payload: string, createdAt: string, ttlSeconds: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2221
- popAndMarkDraining(queueKey: string, orgsKey: string, entryPrefix: string, envId: string, orgEnvsPrefix: string, callback?: Callback<string | null>): Result<string | null, Context>;
2222
- requeueMollifierEntry(entryKey: string, orgsKey: string, queuePrefix: string, runId: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2223
- failMollifierEntry(entryKey: string, errorPayload: string, callback?: Callback<number>): Result<number, Context>;
2315
+ acceptMollifierEntry(entryKey: string, queueKey: string, orgsKey: string, runId: string, envId: string, orgId: string, payload: string, createdAt: string, createdAtMicros: string, orgEnvsPrefix: string, idempotencyLookupKey: string, entryPrefix: string, callback?: Callback<number | string>): Result<number | string, Context>;
2316
+ popAndMarkDraining(queueKey: string, orgsKey: string, drainingSetKey: string, entryPrefix: string, envId: string, orgEnvsPrefix: string, callback?: Callback<string | null>): Result<string | null, Context>;
2317
+ requeueMollifierEntry(entryKey: string, orgsKey: string, drainingSetKey: string, queuePrefix: string, runId: string, orgEnvsPrefix: string, callback?: Callback<number>): Result<number, Context>;
2318
+ mutateMollifierSnapshot(entryKey: string, patchJson: string, callback?: Callback<string>): Result<string, Context>;
2319
+ casSetMollifierMetadata(entryKey: string, expectedVersion: string, newMetadata: string, newMetadataType: string, callback?: Callback<string>): Result<string, Context>;
2320
+ resetMollifierIdempotency(lookupKey: string, entryPrefix: string, claimKey: string, callback?: Callback<string>): Result<string, Context>;
2321
+ claimMollifierIdempotency(claimKey: string, pendingMarker: string, pendingPrefix: string, ttlSeconds: string, callback?: Callback<string>): Result<string, Context>;
2322
+ publishMollifierClaim(claimKey: string, ownerMarker: string, runId: string, ttlSeconds: string, callback?: Callback<number>): Result<number, Context>;
2323
+ releaseMollifierClaim(claimKey: string, ownerMarker: string, callback?: Callback<number>): Result<number, Context>;
2324
+ ackMollifierEntry(entryKey: string, drainingSetKey: string, graceTtlSeconds: string, runId: string, callback?: Callback<number>): Result<number, Context>;
2325
+ failMollifierEntry(entryKey: string, drainingSetKey: string, errorPayload: string, runId: string, callback?: Callback<number>): Result<number, Context>;
2326
+ delMollifierKeyIfEquals(key: string, expected: string, callback?: Callback<number>): Result<number, Context>;
2224
2327
  mollifierEvaluateTrip(rateKey: string, trippedKey: string, windowMs: string, threshold: string, holdMs: string, callback?: Callback<[number, number]>): Result<[number, number], Context>;
2225
2328
  }
2226
2329
  }
@@ -2233,14 +2336,32 @@ type MollifierDrainerHandler<TPayload> = (input: {
2233
2336
  attempts: number;
2234
2337
  createdAt: Date;
2235
2338
  }) => Promise<void>;
2339
+ type MollifierDrainerTerminalFailureCause = "non-retryable" | "max-attempts-exhausted";
2340
+ type MollifierDrainerTerminalFailureHandler<TPayload> = (input: {
2341
+ runId: string;
2342
+ envId: string;
2343
+ orgId: string;
2344
+ payload: TPayload;
2345
+ attempts: number;
2346
+ createdAt: Date;
2347
+ error: {
2348
+ code: string;
2349
+ message: string;
2350
+ };
2351
+ cause: MollifierDrainerTerminalFailureCause;
2352
+ }) => Promise<void>;
2236
2353
  type MollifierDrainerOptions<TPayload> = {
2237
2354
  buffer: MollifierBuffer;
2238
2355
  handler: MollifierDrainerHandler<TPayload>;
2356
+ onTerminalFailure?: MollifierDrainerTerminalFailureHandler<TPayload>;
2239
2357
  concurrency: number;
2240
2358
  maxAttempts: number;
2241
2359
  isRetryable: (err: unknown) => boolean;
2242
2360
  pollIntervalMs?: number;
2243
2361
  maxOrgsPerTick?: number;
2362
+ drainBatchSize?: number;
2363
+ maxBackoffMs?: number;
2364
+ backoffFloorMs?: number;
2244
2365
  logger?: Logger;
2245
2366
  };
2246
2367
  type DrainResult = {
@@ -2250,12 +2371,16 @@ type DrainResult = {
2250
2371
  declare class MollifierDrainer<TPayload = unknown> {
2251
2372
  private readonly buffer;
2252
2373
  private readonly handler;
2374
+ private readonly onTerminalFailure?;
2253
2375
  private readonly maxAttempts;
2254
2376
  private readonly isRetryable;
2255
2377
  private readonly pollIntervalMs;
2256
2378
  private readonly maxOrgsPerTick;
2379
+ private readonly drainBatchSize;
2380
+ private readonly concurrency;
2381
+ private readonly maxBackoffMs;
2382
+ private readonly backoffFloorMs;
2257
2383
  private readonly logger;
2258
- private readonly limit;
2259
2384
  private orgCursor;
2260
2385
  private perOrgEnvCursors;
2261
2386
  private isRunning;
@@ -2272,8 +2397,7 @@ declare class MollifierDrainer<TPayload = unknown> {
2272
2397
  private delay;
2273
2398
  private takeOrgSlice;
2274
2399
  private pickEnvForOrg;
2275
- private processOneFromEnv;
2276
2400
  private processEntry;
2277
2401
  }
2278
2402
 
2279
- export { type AnyMessageCatalog, type AnyQueueItem, BaseScheduler, type BatchConfig, BatchedSpanManager, type BatchedSpanManagerOptions, type BufferEntry, BufferEntryError, BufferEntrySchema, BufferEntryStatus, CallbackFairQueueKeyProducer, type ClaimResult, type ConcurrencyCheckResult, type ConcurrencyGroupConfig, ConcurrencyManager, type ConcurrencyManagerOptions, type ConcurrencyState, type ConsumerLoopState, type CooloffOptions, CronSchema, CustomRetry, DRRScheduler, type DRRSchedulerConfig, type DeadLetterMessage, DefaultFairQueueKeyProducer, type DispatchSchedulerContext, type DrainResult, type EnqueueBatchOptions, type EnqueueOptions, ExponentialBackoffRetry, FairQueue, FairQueueAttributes, type FairQueueKeyProducer, type FairQueueMetrics, type FairQueueOptions, FairQueueTelemetry, type FairScheduler, FixedDelayRetry, type GlobalRateLimiter, ImmediateRetry, type InFlightMessage, type JobHandler, type JobHandlerParams, LinearBackoffRetry, MasterQueue, type MasterQueueOptions, type MessageCatalogKey, type MessageCatalogSchema, type MessageCatalogValue, type MessageHandler, type MessageHandlerContext, MessagingAttributes, MollifierBuffer, type MollifierBufferOptions, MollifierDrainer, type MollifierDrainerHandler, type MollifierDrainerOptions, NoRetry, NoopScheduler, type QueueCooloffState, type QueueDescriptor, type QueueItem, type QueueMessage, type QueueWithScore, type ReclaimedMessageInfo, type RetryOptions, type RetryStrategy, RoundRobinScheduler, type SchedulerContext, SimpleQueue, type StoredMessage, type TelemetryOptions, TenantDispatch, type TenantDispatchOptions, type TenantQueues, type TenantWithScore, VisibilityManager, type VisibilityManagerOptions, WeightedScheduler, type WeightedSchedulerBiases, type WeightedSchedulerConfig, Worker, type WorkerCatalog, type WorkerConcurrencyOptions, WorkerQueueManager, type WorkerQueueManagerOptions, type WorkerQueueOptions, createDefaultRetryStrategy, defaultRetryOptions, deserialiseSnapshot, isAbortError, noopTelemetry, serialiseSnapshot };
2403
+ export { type AcceptResult, type AnyMessageCatalog, type AnyQueueItem, BaseScheduler, type BatchConfig, BatchedSpanManager, type BatchedSpanManagerOptions, type BufferEntry, BufferEntryError, BufferEntrySchema, BufferEntryStatus, CallbackFairQueueKeyProducer, type CasSetMetadataResult, type ClaimResult, type ConcurrencyCheckResult, type ConcurrencyGroupConfig, ConcurrencyManager, type ConcurrencyManagerOptions, type ConcurrencyState, type ConsumerLoopState, type CooloffOptions, CronSchema, CustomRetry, DRRScheduler, type DRRSchedulerConfig, type DeadLetterMessage, DefaultFairQueueKeyProducer, type DispatchSchedulerContext, type DrainResult, type EnqueueBatchOptions, type EnqueueOptions, ExponentialBackoffRetry, FairQueue, FairQueueAttributes, type FairQueueKeyProducer, type FairQueueMetrics, type FairQueueOptions, FairQueueTelemetry, type FairScheduler, FixedDelayRetry, type GlobalRateLimiter, type IdempotencyClaimResult, type IdempotencyLookupInput, ImmediateRetry, type InFlightMessage, type JobHandler, type JobHandlerParams, LinearBackoffRetry, MasterQueue, type MasterQueueOptions, type MessageCatalogKey, type MessageCatalogSchema, type MessageCatalogValue, type MessageHandler, type MessageHandlerContext, MessagingAttributes, MollifierBuffer, type MollifierBufferOptions, MollifierDrainer, type MollifierDrainerHandler, type MollifierDrainerOptions, type MollifierDrainerTerminalFailureCause, type MollifierDrainerTerminalFailureHandler, type MutateSnapshotResult, NoRetry, NoopScheduler, type QueueCooloffState, type QueueDescriptor, type QueueItem, type QueueMessage, type QueueWithScore, type ReclaimedMessageInfo, type RetryOptions, type RetryStrategy, RoundRobinScheduler, type SchedulerContext, SimpleQueue, type SnapshotPatch, type StoredMessage, type TelemetryOptions, TenantDispatch, type TenantDispatchOptions, type TenantQueues, type TenantWithScore, VisibilityManager, type VisibilityManagerOptions, WeightedScheduler, type WeightedSchedulerBiases, type WeightedSchedulerConfig, Worker, type WorkerCatalog, type WorkerConcurrencyOptions, WorkerQueueManager, type WorkerQueueManagerOptions, type WorkerQueueOptions, createDefaultRetryStrategy, defaultRetryOptions, deserialiseSnapshot, idempotencyLookupKeyFor, isAbortError, makeIdempotencyClaimKey, noopTelemetry, serialiseSnapshot };