@keetanetwork/anchor 0.0.107 → 0.0.109
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/lib/queue/drivers/queue_firestore.d.ts.map +1 -1
- package/lib/queue/drivers/queue_firestore.js +4 -0
- package/lib/queue/drivers/queue_firestore.js.map +1 -1
- package/lib/queue/drivers/queue_postgres.d.ts +7 -0
- package/lib/queue/drivers/queue_postgres.d.ts.map +1 -1
- package/lib/queue/drivers/queue_postgres.js +66 -25
- package/lib/queue/drivers/queue_postgres.js.map +1 -1
- package/lib/queue/drivers/queue_redis.d.ts.map +1 -1
- package/lib/queue/drivers/queue_redis.js +16 -41
- package/lib/queue/drivers/queue_redis.js.map +1 -1
- package/lib/queue/drivers/queue_sqlite3.d.ts.map +1 -1
- package/lib/queue/drivers/queue_sqlite3.js +15 -1
- package/lib/queue/drivers/queue_sqlite3.js.map +1 -1
- package/lib/queue/index.d.ts +41 -1
- package/lib/queue/index.d.ts.map +1 -1
- package/lib/queue/index.js +120 -29
- package/lib/queue/index.js.map +1 -1
- package/lib/queue/internal.d.ts +7 -0
- package/lib/queue/internal.d.ts.map +1 -1
- package/lib/queue/internal.js +9 -0
- package/lib/queue/internal.js.map +1 -1
- package/npm-shrinkwrap.json +31 -13
- package/package.json +4 -4
package/lib/queue/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/queue/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAOzD,MAA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E,CAAC","sourcesContent":["import type { BrandedString, Brand } from '../utils/brand.ts';\nimport type { Logger } from '../log/index.ts';\nimport type { JSONSerializable } from '../utils/json.ts';\nimport { assertNever } from '../utils/never.js';\nimport type { AssertNever } from '../utils/never.ts';\nimport type { KeetaAnchorQueueRunOptions } from './common.js';\nimport { asleep } from '../utils/asleep.js';\nimport { Errors } from './common.js';\nimport {\n\tMethodLogger,\n\tManageStatusUpdates,\n\tConvertStringToRequestID\n} from './internal.js';\nimport { AsyncDisposableStack } from '../utils/defer.js';\n\nexport type KeetaAnchorQueueRequest<QueueRequest> = QueueRequest;\nexport type KeetaAnchorQueueRequestID = BrandedString<'KeetaAnchorQueueID'>;\nexport type KeetaAnchorQueueWorkerID = Brand<number, 'KeetaAnchorQueueWorkerID'>;\n\nexport type KeetaAnchorQueueStatus = 'pending' | 'processing' | 'completed' | 'failed_temporarily' | 'failed_permanently' | 'stuck' | 'aborted' | 'moved' | '@internal';\nconst keetaAnchorPipeableQueueStatuses = [ 'completed', 'failed_permanently' ] as const;\n/**\n * This is a type-level assertion to ensure that all values in keetaAnchorPipeableQueueStatuses are valid KeetaAnchorQueueStatus values.\n * If this assertion fails, it means that there is a value in keetaAnchorPipeableQueueStatuses that is not a valid KeetaAnchorQueueStatus, and the code will not compile.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype __check_keetaAnchorPipeableQueueStatuses_valid = AssertNever<typeof keetaAnchorPipeableQueueStatuses[number] extends KeetaAnchorQueueStatus ? never : true>;\n\nexport type KeetaAnchorPipeableQueueStatus = Extract<KeetaAnchorQueueStatus, typeof keetaAnchorPipeableQueueStatuses[number]>;\nexport type KeetaAnchorQueueEntry<QueueRequest, QueueResult> = {\n\t/**\n\t * The Job ID\n\t */\n\tid: KeetaAnchorQueueRequestID;\n\t/**\n\t * Idempotent IDs from a previous stage\n\t */\n\tidempotentKeys?: Set<KeetaAnchorQueueRequestID> | undefined;\n\trequest: KeetaAnchorQueueRequest<QueueRequest>;\n\toutput: QueueResult | null;\n\tlastError: string | null;\n\tstatus: KeetaAnchorQueueStatus;\n\tcreated: Date;\n\tupdated: Date;\n\tworker: KeetaAnchorQueueWorkerID | null;\n\tfailures: number;\n};\n\n/**\n * Extra information to provide to a request when adding an entry to the queue\n */\nexport type KeetaAnchorQueueEntryExtra = {\n\t[key in 'idempotentKeys' | 'id' | 'status']?: (key extends 'id' ? KeetaAnchorQueueRequestID | string : KeetaAnchorQueueEntry<never, never>[key]) | undefined;\n};\n\nexport type KeetaAnchorQueueFilter = {\n\t/**\n\t * Only return entries with this status\n\t */\n\tstatus?: KeetaAnchorQueueStatus;\n\t/**\n\t * Only return entries last updated before this date\n\t */\n\tupdatedBefore?: Date;\n\t/**\n\t * Limit the number of entries returned\n\t */\n\tlimit?: number;\n};\n\nexport type KeetaAnchorQueueDeleteInput = {\n\tid: KeetaAnchorQueueRequestID;\n\tstatus: KeetaAnchorQueueStatus;\n};\n\nexport type KeetaAnchorQueueCommonOptions = {\n\tlogger?: Logger | undefined;\n\tid?: string | undefined;\n};\n\nexport type KeetaAnchorQueueRunnerOptions = KeetaAnchorQueueCommonOptions & {\n\t/**\n\t * If specified, then multiple workers can be used to process this queue\n\t * in parallel by splitting the work among the workers.\n\t *\n\t * By default, only a single worker will process the queue (count=1, id=0)\n\t */\n\tworkers?: {\n\t\tcount: number;\n\t\tid: number;\n\t} | undefined;\n};\n\nexport type KeetaAnchorQueueStorageOptions = KeetaAnchorQueueCommonOptions & {\n\tpath?: string[] | undefined;\n};\n\nexport type KeetaAnchorQueueEntryAncillaryData<QueueResult> = {\n\t/**\n\t * The previous status of the entry -- if the entry is not currently in this status,\n\t * the status update will fail\n\t */\n\toldStatus?: KeetaAnchorQueueStatus | undefined;\n\t/**\n\t * The worker ID performing the status update\n\t */\n\tby?: KeetaAnchorQueueWorkerID | undefined;\n\t/**\n\t * The output data to store with the entry\n\t */\n\toutput?: QueueResult | null | undefined;\n\t/**\n\t * An error message to store with the entry\n\t */\n\terror?: string | undefined;\n};\n\nexport type KeetaAnchorQueueStorageDriverConstructor<QueueRequest extends JSONSerializable, QueueResult extends JSONSerializable> = new(options?: KeetaAnchorQueueStorageOptions) => KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\nexport interface KeetaAnchorQueueStorageDriver<QueueRequest extends JSONSerializable, QueueResult extends JSONSerializable> {\n\t/**\n\t * An ID for this instance of the storage driver\n\t */\n\treadonly id: string;\n\n\t/**\n\t * The name of the storage driver\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The partition ID for this instance of the storage driver\n\t *\n\t * This is used to divide a single storage backend into multiple\n\t * independent queues.\n\t *\n\t * The root partition is an empty array, and each element is\n\t * a hierarchical partition name.\n\t */\n\treadonly path: string[];\n\n\t/**\n\t * Enqueue an item to be processed by the queue\n\t *\n\t * It will be inserted into the queue as a 'pending' entry\n\t *\n\t * @param request The request to enqueue\n\t * @param id Optional ID to use for the entry -- if not provided, a new\n\t * ID will be generated. If the ID is already in use then\n\t * nothing will be added.\n\t * @returns The ID for the newly created pending entry\n\t */\n\tadd: (request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra) => Promise<KeetaAnchorQueueRequestID>;\n\n\t/**\n\t * Update the status of an entry in the queue\n\t *\n\t * If the status is \"failed_temporarily\", the failure count will be incremented\n\t *\n\t * @param id The entry ID to update\n\t * @param status The new status of the entry\n\t * @param ancillary Optional ancillary data for the status update\n\t * @returns void\n\t */\n\tsetStatus: (id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>) => Promise<void>;\n\n\t/**\n\t * Get entries from storage with an optional filter\n\t *\n\t * @param filter The filter to apply (optional)\n\t * @returns An array of entries matching the criteria\n\t */\n\tquery(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]>;\n\n\t/**\n\t * Get a single entry from storage by ID\n\t *\n\t * @param id The ID of the entry to retrieve\n\t * @returns The entry if found, or null if not found\n\t */\n\tget(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null>;\n\n\t/**\n\t * Delete entries by ID. Each entry is removed only if its current status matches\n\t * the status given in the input.\n\t */\n\tdelete(input: KeetaAnchorQueueDeleteInput[]): Promise<void>;\n\n\t/**\n\t * Perform maintenance tasks on the storage driver\n\t * (e.g. cleaning up old entries, etc)\n\t *\n\t * @returns void\n\t */\n\tmaintain?: () => Promise<void>;\n\n\t/**\n\t * Create a partitioned view of the queue\n\t *\n\t * @param partitionID The partition ID to use\n\t * @returns A new storage driver instance for the partition\n\t */\n\tpartition: (path: string) => Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>>;\n\n\t/**\n\t * Close the storage driver and release any resources\n\t */\n\tdestroy(): Promise<void>;\n\t[Symbol.asyncDispose](): Promise<void>;\n\n\t/** @internal */\n\t_Testing?: (key: string) => {\n\t\tsetToctouDelay?(delay: number): void;\n\t\tunsetToctouDelay?(): void;\n\t};\n}\n\n/**\n * An in-memory implementation of the KeetaAnchorQueueStorageDriver\n */\nexport class KeetaAnchorQueueStorageDriverMemory<QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> implements KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\tprotected queueStorage: { [path: string]: KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]; } = {};\n\tprotected readonly logger?: Logger | undefined;\n\tprotected partitionCounter = 0;\n\tprivate destroyed = false;\n\treadonly name: string = 'KeetaAnchorQueueStorageDriverMemory';\n\treadonly id: string;\n\treadonly path: string[] = [];\n\n\tconstructor(options?: KeetaAnchorQueueStorageOptions) {\n\t\tthis.id = options?.id ?? crypto.randomUUID();\n\t\tthis.logger = options?.logger;\n\t\tthis.path.push(...(options?.path ?? []));\n\t\tObject.freeze(this.path);\n\n\t\tthis.methodLogger('new')?.debug('Created new in-memory queue storage driver');\n\t}\n\n\tprotected clone(options?: Partial<KeetaAnchorQueueStorageOptions>): KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\t\tconst cloned = new KeetaAnchorQueueStorageDriverMemory<QueueRequest, QueueResult>({\n\t\t\tlogger: this.logger,\n\t\t\tid: `${this.id}::${this.partitionCounter++}`,\n\t\t\tpath: [...this.path],\n\t\t\t...options\n\t\t});\n\t\tcloned.queueStorage = this.queueStorage;\n\n\t\treturn(cloned);\n\t}\n\n\tprotected get queue(): KeetaAnchorQueueEntry<QueueRequest, QueueResult>[] {\n\t\tconst pathKey = ['root', ...this.path].join('.');\n\t\tlet retval = this.queueStorage[pathKey];\n\t\tif (retval === undefined) {\n\t\t\tretval = this.queueStorage[pathKey] = [];\n\t\t}\n\t\treturn(retval);\n\t}\n\n\tprotected methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueStorageDriverMemory',\n\t\t\tfile: 'src/lib/queue/index.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\tprivate checkDestroyed(): void {\n\t\tif (this.destroyed) {\n\t\t\tthrow(new Error('Queue has been destroyed'));\n\t\t}\n\t}\n\n\tasync add(request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('add');\n\n\t\tlet id = ConvertStringToRequestID(info?.id);\n\t\tif (id) {\n\t\t\tconst duplicateID = this.queue.some(function(checkEntry) {\n\t\t\t\treturn(checkEntry.id === id);\n\t\t\t});\n\n\t\t\tif (duplicateID) {\n\t\t\t\tlogger?.debug(`Request with id ${String(id)} already exists, ignoring`);\n\n\t\t\t\treturn(id);\n\t\t\t}\n\t\t}\n\n\t\tconst idempotentIDs = info?.idempotentKeys;\n\t\tif (idempotentIDs) {\n\t\t\tconst matchingIdempotentEntries = new Set<KeetaAnchorQueueRequestID>();\n\t\t\tfor (const idempotentID of idempotentIDs) {\n\t\t\t\tconst idempotentEntryExists = this.queue.some(function(checkEntry) {\n\t\t\t\t\treturn(checkEntry.idempotentKeys?.has(idempotentID) ?? false);\n\t\t\t\t});\n\n\t\t\t\tif (idempotentEntryExists) {\n\t\t\t\t\tmatchingIdempotentEntries.add(idempotentID);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (matchingIdempotentEntries.size !== 0) {\n\t\t\t\tthrow(new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', matchingIdempotentEntries));\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The status to use for the new entry\n\t\t */\n\t\tconst status = info?.status ?? 'pending';\n\n\t\t/*\n\t\t * The ID is a branded string, so we must convert the generated UUID\n\t\t */\n\t\tid ??= ConvertStringToRequestID(crypto.randomUUID());\n\n\t\tlogger?.debug(`Enqueuing request with id ${String(id)}`);\n\n\t\tthis.queue.push({\n\t\t\tid: id,\n\t\t\trequest: request,\n\t\t\toutput: null,\n\t\t\tlastError: null,\n\t\t\tstatus: status,\n\t\t\tfailures: 0,\n\t\t\tcreated: new Date(),\n\t\t\tupdated: new Date(),\n\t\t\tworker: null,\n\t\t\tidempotentKeys: idempotentIDs ? new Set(idempotentIDs) : undefined\n\t\t});\n\n\t\treturn(id);\n\t}\n\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>): Promise<void> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('setStatus');\n\n\t\tconst entry = this.queue.find(function(checkEntry) {\n\t\t\treturn(checkEntry.id === id);\n\t\t});\n\t\tif (!entry) {\n\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t}\n\n\t\tconst changedFields = ManageStatusUpdates<QueueResult>(id, entry, status, ancillary, logger);\n\n\t\tObject.assign(entry, changedFields);\n\t}\n\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> {\n\t\tthis.checkDestroyed();\n\n\t\tconst entry = this.queue.find(function(checkEntry) {\n\t\t\treturn(checkEntry.id === id);\n\t\t});\n\n\t\tif (!entry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(structuredClone(entry));\n\t}\n\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('query');\n\n\t\tconst queueDuplicate = structuredClone(this.queue);\n\n\t\tlogger?.debug(`Querying queue with id ${this.id} with filter:`, filter);\n\n\t\tconst allEntriesInStatus = (function() {\n\t\t\tconst filterStatus = filter?.status;\n\t\t\tconst filterLastUpdateBefore = filter?.updatedBefore;\n\t\t\tif (filterStatus || filterLastUpdateBefore) {\n\t\t\t\treturn(queueDuplicate.filter(function(entry) {\n\t\t\t\t\tif (filterStatus) {\n\t\t\t\t\t\tif (entry.status !== filterStatus) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (filterLastUpdateBefore) {\n\t\t\t\t\t\tif (entry.updated >= filterLastUpdateBefore) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn(true);\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\treturn(queueDuplicate);\n\t\t\t}\n\t\t})();\n\n\t\tlet retval = allEntriesInStatus;\n\t\tif (filter?.limit !== undefined) {\n\t\t\tretval = allEntriesInStatus.slice(0, filter.limit);\n\t\t}\n\n\t\tlogger?.debug(`Queried queue with id ${this.id} with filter:`, filter, '-- found', retval.length, 'entries');\n\n\t\treturn(retval);\n\t}\n\n\tasync delete(input: KeetaAnchorQueueDeleteInput[]): Promise<void> {\n\t\tthis.checkDestroyed();\n\n\t\tif (input.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst logger = this.methodLogger('delete');\n\t\tconst targets = new Map(input.map(function(target) {\n\t\t\treturn([target.id, target.status] as const);\n\t\t}));\n\t\tlet deleted = 0;\n\n\t\tfor (let index = this.queue.length - 1; index >= 0; index--) {\n\t\t\tconst entry = this.queue[index];\n\t\t\tif (entry === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst expectedStatus = targets.get(entry.id);\n\t\t\tif (expectedStatus !== undefined && entry.status === expectedStatus) {\n\t\t\t\tthis.queue.splice(index, 1);\n\t\t\t\tdeleted++;\n\t\t\t}\n\t\t}\n\n\t\tif (deleted > 0) {\n\t\t\tlogger?.debug(`Deleted ${deleted} entries from queue ${this.id}`);\n\t\t}\n\t}\n\n\tasync partition(path: string): Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('partition');\n\n\t\tlogger?.debug(`Creating partitioned queue storage driver for path \"${path}\"`);\n\n\t\tconst partitioned = this.clone({\n\t\t\tpath: [...this.path, path]\n\t\t});\n\n\t\treturn(partitioned);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.destroyed = true;\n\t\tthis.methodLogger('destroy')?.debug('Destroying in-memory queue');\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\treturn(await this.destroy());\n\t}\n}\n\ninterface AdditionalPipeOptions {\n\t/**\n\t * If true, call maintain/run on this target when maintaining/running this runner\n\t * Defaults to true\n\t */\n\texclusiveTarget?: boolean;\n}\n\n// @ts-ignore\nexport interface KeetaAnchorQueueRunnerConfigurationObject {\n\tmaxRetries: number;\n\tprocessTimeout: number;\n\tbatchSize: number;\n\tretryDelay: number;\n\tstuckMultiplier: number;\n\tcompletedRetentionDays: number;\n\tcompletedRetentionLimitPerRun: number;\n}\n\ntype KeetaAnchorQueueProcessorResultValue<UserResult> = {\n\t/**\n\t *\n\t */\n\tstatus: KeetaAnchorQueueStatus;\n\toutput: UserResult | null;\n\terror?: string | undefined;\n}\n\n/**\n * An exception which can be thrown by a processor to indicate its results.\n *\n * This is identical to the processor return value, but allows the processor\n * to throw it instead of returning it.\n *\n * This is useful in nested code run from a processor which may need to abort\n * the normal flow control and return a result to the queue runner\n */\nclass KeetaAnchorQueueProcessorResult<UserResult = unknown> extends Error implements KeetaAnchorQueueProcessorResultValue<UserResult> {\n\treadonly status: KeetaAnchorQueueProcessorResultValue<UserResult>['status'];\n\treadonly output: KeetaAnchorQueueProcessorResultValue<UserResult>['output'];\n\treadonly error?: KeetaAnchorQueueProcessorResultValue<UserResult>['error'] | undefined;\n\treadonly cause?: unknown;\n\n\tprivate readonly keetaAnchorQueueProcessorResultObjectTypeID!: string;\n\tprivate static readonly keetaAnchorQueueProcessorResultObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\n\tstatic isInstance<UserResult = unknown>(obj: unknown): obj is KeetaAnchorQueueProcessorResult<UserResult> {\n\t\tif (typeof obj !== 'object' || obj === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!('keetaAnchorQueueProcessorResultObjectTypeID' in obj)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tconst checkID = obj['keetaAnchorQueueProcessorResultObjectTypeID'];\n\t\tif (typeof checkID !== 'string') {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (checkID !== KeetaAnchorQueueProcessorResult.keetaAnchorQueueProcessorResultObjectTypeID) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\tconstructor(message: string, result: KeetaAnchorQueueProcessorResultValue<UserResult>, cause?: unknown) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorQueueProcessorResultObjectTypeID', {\n\t\t\tvalue: KeetaAnchorQueueProcessorResult.keetaAnchorQueueProcessorResultObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.status = result.status;\n\t\tthis.output = result.output;\n\t\tthis.error = result.error;\n\t\tthis.cause = cause;\n\t}\n}\n\n// Ensure that KeetaAnchorQueueRunnerConfigurationObject has all the required properties of KeetaAnchorQueueRunner, and no extra properties\n// if this assertion fails, it means that KeetaAnchorQueueRunnerConfigurationObject is missing a property from KeetaAnchorQueueRunner or has an extra property\n// @ts-ignore\ntype __check_KeetaAnchorQueueRunnerConfigurationObject = Required<Pick<KeetaAnchorQueueRunner, 'maxRetries' | 'retryDelay' | 'stuckMultiplier' | 'batchSize' | 'processTimeout' | 'completedRetentionDays' | 'completedRetentionLimitPerRun'>>;\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype __check = AssertNever<__check_KeetaAnchorQueueRunnerConfigurationObject extends KeetaAnchorQueueRunnerConfigurationObject ? (KeetaAnchorQueueRunnerConfigurationObject extends __check_KeetaAnchorQueueRunnerConfigurationObject ? never : false) : false>;\n\n/*\n * Export all the error-typed classes as a single object so that they can\n * be imported.\n *\n * The KeetaAnchorQueueProcessorResult class is included here so downstream\n * code can use it to throw errors from the processor function and have them\n * handled correctly by the queue runner -- but it's not strictly an error\n * (hence not living in ./errors.ts)\n */\nconst AllErrors: typeof Errors & {\n\tKeetaAnchorQueueProcessorResult: typeof KeetaAnchorQueueProcessorResult;\n} = {\n\tKeetaAnchorQueueProcessorResult,\n\t...Errors\n}\n\n/**\n * A Queue Runner and Request Translator for processing entries in a queue\n *\n * The queue runner is responsible for pulling entries from the queue,\n * processing them, and updating their status in the queue. As well\n * as moving jobs between queues by piping the output of one runner\n * to another. Additionally, maintenance tasks such as re-queuing\n * failed jobs and marking stuck jobs are also handled by the runner.\n *\n * This is an abstract base class that must be extended to provide\n * the actual processing logic as well as the encoding and decoding\n * for requests and responses.\n */\nexport abstract class KeetaAnchorQueueRunner<UserRequest = unknown, UserResult = unknown, QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> {\n\t/**\n\t * Errors which may be thrown by the queue runner or processor\n\t */\n\tstatic readonly Errors: typeof AllErrors = AllErrors;\n\n\t/**\n\t * The queue this runner is responsible for running\n\t */\n\tprivate readonly queue: KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\t/**\n\t * The logger we should use for logging anything\n\t */\n\tprivate readonly logger?: Logger | undefined;\n\t/**\n\t * The processor function to use for processing entries\n\t */\n\tprotected abstract processor(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * The processor for stuck jobs (optional)\n\t */\n\tprotected processorStuck?(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * The processor for aborted jobs (optional)\n\t */\n\tprotected processorAborted?(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * Worker configuration\n\t */\n\tprivate readonly workers: NonNullable<KeetaAnchorQueueRunnerOptions['workers']>;\n\tprivate readonly workerID: KeetaAnchorQueueWorkerID;\n\n\t/**\n\t * Pipes to other runners we have registered\n\t */\n\tprivate readonly pipes: (\n\t\t// Non-Batch pipe -- depending on acceptStatus, either UserResult[] or UserRequest[]\n\t\t(\n\t\t\t({\n\t\t\t\tisBatchPipe: false;\n\t\t\t} & ({\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserResult, any, QueueResult, any>\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'completed'>;\n\t\t\t} | {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserRequest, any, QueueResult, any>\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'failed_permanently'>;\n\t\t\t})) |\n\n\t\t\t// Batch pipe -- depending on acceptStatus, either UserResult[] or UserRequest[]\n\t\t\t({\n\t\t\t\tisBatchPipe: true;\n\t\t\t\tminBatchSize: number;\n\t\t\t\tmaxBatchSize: number;\n\t\t\t} & ({\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserResult[], any, JSONSerializable, any>;\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'completed'>;\n\t\t\t} | {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserRequest[], any, JSONSerializable, any>;\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'failed_permanently'>;\n\t\t\t}))\n\t\t) & AdditionalPipeOptions\n\t)[] = [];\n\n\t/**\n\t * Runners that pipe into this runner\n\t */\n\tprivate incomingPipeCount = 0;\n\n\t/**\n\t * Initialization promise\n\t */\n\tprivate initializePromise: Promise<void> | undefined;\n\n\t/**\n\t * Configuration for this queue\n\t */\n\t/**\n\t * The maximum number of times to retry a failed job before giving up\n\t * and marking it as permanently failed\n\t */\n\tprotected maxRetries = 5;\n\t/**\n\t * The amount of time to allow a job to run before considering it\n\t * timed out and marking it as aborted, the `aborted` processor\n\t * (if provided) will be responsible for determining what to do with\n\t * the job at that point (e.g. retry it, mark it as failed, etc)\n\t * because some work from the job may have been completed\n\t * before the timeout was reached -- it could even still be on-going\n\t * after the timeout is reached, so the `aborted` processor should be\n\t * prepared to handle that situation as well.\n\t */\n\tprotected processTimeout = 300_000; /* 5 minutes */\n\t/**\n\t * When piping a batch of jobs to another runner, this is the number\n\t * of jobs to include in each batch (max).\n\t */\n\tprotected batchSize = 100;\n\n\t/**\n\t * The amount of time to wait before retrying a failed job -- this should\n\t * be long enough to allow any transient issues to be resolved (e.g. a downstream\n\t * service to come back up, etc) but not so long that it causes excessive\n\t * delays in processing.\n\t *\n\t * Keep in mind that after the {@link maxRetries} is reached, the job will\n\t * be marked as permanently failed, so if the retry delay is too low then\n\t * it could cause jobs to be marked as permanently failed before transient\n\t * issues have a chance to be resolved.\n\t */\n\tprotected get retryDelay(): number {\n\t\tif (this.internalRetryDelay !== undefined) {\n\t\t\treturn(this.internalRetryDelay);\n\t\t}\n\t\treturn(this.processTimeout * 10);\n\t}\n\n\tprotected set retryDelay(value: number) {\n\t\tthis.internalRetryDelay = value;\n\t}\n\n\tprivate internalRetryDelay?: number;\n\n\t/**\n\t * The number of {@link processTimeout} intervals to wait before\n\t * considering a job to be stuck -- this is for jobs that are\n\t * still in the 'processing' state but have not updated their\n\t * timestamp in a long time, which likely indicates that the worker\n\t * processing the job has died or is otherwise no longer making\n\t * progress on the job.\n\t *\n\t * Like the `aborted` status, the `stuck` status means the job is in\n\t * an indeterminate state where it may have done some of the work of\n\t * the processor but we don't know how much (if any) of it was\n\t * completed, so the `stuck` processor should be prepared to handle\n\t * that situation. It is unlikely that the job is still being actively\n\t * processed by a worker at this point, but it is possible, so the\n\t * `stuck` processor should be prepared to handle that as well.\n\t */\n\tprotected get stuckMultiplier(): number {\n\t\tif (this.internalStuckMultiplier !== undefined) {\n\t\t\treturn(this.internalStuckMultiplier);\n\t\t}\n\t\treturn(10);\n\t}\n\n\tprotected set stuckMultiplier(value: number) {\n\t\tthis.internalStuckMultiplier = value;\n\t}\n\n\tprivate internalStuckMultiplier?: number;\n\n\t/**\n\t * How many runners can process this queue in parallel\n\t */\n\tprotected maxRunners?: number;\n\n\t/**\n\t * How long to keep completed entries in the queue to avoid\n\t * re-using the same ID. A negative value means that completed\n\t * records will be immediately deleted.\n\t *\n\t * In units of days. Setting this to infinity will disable\n\t * cleanup.\n\t *\n\t * Default is 30 days.\n\t */\n\tprotected completedRetentionDays = 30;\n\n\t/**\n\t * How many completed entries to delete per maintain() call\n\t */\n\tprotected completedRetentionLimitPerRun = 5000;\n\n\t/**\n\t * A unique key to identify this runner for fencing the same worker\n\t * from running at the same time\n\t */\n\tprivate readonly runnerLockKey: KeetaAnchorQueueRequestID;\n\n\t/**\n\t * The ID of this runner for diagnostic purposes\n\t */\n\treadonly id: string;\n\n\tconstructor(config: { queue: KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>; } & KeetaAnchorQueueRunnerOptions) {\n\t\tthis.queue = config.queue;\n\t\tthis.logger = config.logger;\n\t\tthis.workers = config.workers ?? {\n\t\t\tcount: 1,\n\t\t\tid: 0\n\t\t};\n\n\t\tif (this.workers.id < 0) {\n\t\t\tthrow(new Error('Worker ID cannot be negative'));\n\t\t}\n\n\t\tif (this.maxRunners) {\n\t\t\tif (this.workers.id > this.maxRunners - 1 || this.workers.count > this.maxRunners) {\n\t\t\t\tthrow(new Error('Worker ID other than 0 or worker count other than 1 is not supported yet'));\n\t\t\t}\n\t\t}\n\n\t\t/*\n\t\t * The worker ID is just a branded version of the worker number\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.workerID = this.workers.id as KeetaAnchorQueueWorkerID;\n\n\t\t/*\n\t\t * The runner lock key, a unique key used to ensure only\n\t\t * one instance of a given runner is running at a time\n\t\t */\n\t\tthis.runnerLockKey = ConvertStringToRequestID(`@runner-lock:9ba756f0-7aa2-41c7-a1ea-b010dc752ae8.worker.${this.workerID}`);\n\n\t\t/**\n\t\t * Instance ID\n\t\t */\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\n\t\tthis.methodLogger('new')?.debug('Created new queue runner attached to queue', this.queue.id);\n\t}\n\n\t/**\n\t * Helpful common handlers for the processorAborted and processorStuck methods\n\t */\n\tstatic processorHandlerHelpers: {\n\t\t/*\n\t\t * Because we are just passing the value through we do not\n\t\t * care about the type, we can handle any type because we\n\t\t * simply return the existing value\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t[key in 'RETRY']: NonNullable<KeetaAnchorQueueRunner<unknown, any>['processorAborted']> | NonNullable<KeetaAnchorQueueRunner<unknown, any>['processorStuck']>;\n\t} = {\n\t\t\tRETRY: async (entry) => {\n\t\t\t\treturn({\n\t\t\t\t\tstatus: 'failed_temporarily',\n\t\t\t\t\t/*\n\t\t\t\t\t * This is safe because we are not\n\t\t\t\t\t * doing any operations on the value\n\t\t\t\t\t * and it just being copied over itself\n\t\t\t\t\t */\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\toutput: entry.output,\n\t\t\t\t\terror: `Job was ${entry.status} after ${entry.failures} failures, retrying`\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\tprivate async initialize(): Promise<void> {\n\t\tif (this.initializePromise) {\n\t\t\treturn(await this.initializePromise);\n\t\t}\n\n\t\t/* Ensure the sequential lock entry exists */\n\t\tthis.initializePromise = (async () => {\n\t\t\t/*\n\t\t\t * We store `null` as the request value because we\n\t\t\t * don't have anything better to store -- it's not\n\t\t\t * always going to be compatible with the type\n\t\t\t * QueueRequest but we know that we will never actually\n\t\t\t * use the value.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tawait this.queue.add(null as unknown as QueueRequest, {\n\t\t\t\tid: this.runnerLockKey,\n\t\t\t\tstatus: '@internal'\n\t\t\t});\n\t\t})();\n\n\t\treturn(await this.initializePromise);\n\t}\n\n\tprotected setConfiguration(parameters: Partial<KeetaAnchorQueueRunnerConfigurationObject>): void {\n\t\tconst parameterNames = [ 'batchSize', 'maxRetries', 'processTimeout', 'retryDelay', 'stuckMultiplier', 'completedRetentionDays', 'completedRetentionLimitPerRun' ] as const satisfies (keyof typeof parameters)[];\n\t\t// Ensure that all keys in the config object are expected and used\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\ttype __checkAllExtensionConfigKeysAreValid = AssertNever<Exclude<keyof typeof parameters, typeof parameterNames[number]>>;\n\n\t\tfor (const parameterName of parameterNames) {\n\t\t\tconst value = parameters[parameterName];\n\t\t\tif (value === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis[parameterName] = value;\n\t\t}\n\t}\n\n\tprivate methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueRunner',\n\t\t\tfile: 'src/lib/queue/index.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\t/** @internal */\n\t_Testing(key: string): {\n\t\tsetParams: (params: Partial<KeetaAnchorQueueRunnerConfigurationObject> & { maxRunners?: number; }) => void;\n\t\tqueue: () => KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\t\tmarkWorkerAsProcessing: () => Promise<void>;\n\t} {\n\t\tif (key !== 'bc81abf8-e43b-490b-b486-744fb49a5082') {\n\t\t\tthrow(new Error('This is a testing only method'));\n\t\t}\n\n\t\treturn({\n\t\t\tsetParams: (params: Partial<KeetaAnchorQueueRunnerConfigurationObject> & { maxRunners?: number; }) => {\n\t\t\t\tconst { maxRunners, ...configParams } = params;\n\t\t\t\tthis.setConfiguration(configParams);\n\n\t\t\t\tif (maxRunners !== undefined) {\n\t\t\t\t\tthis.maxRunners = maxRunners;\n\t\t\t\t}\n\t\t\t},\n\t\t\tqueue: () => {\n\t\t\t\treturn(this.queue);\n\t\t\t},\n\t\t\tmarkWorkerAsProcessing: async () => {\n\t\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\t\toldStatus: '@internal',\n\t\t\t\t\tby: this.workerID\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n\n\tprotected abstract decodeRequest(request: QueueRequest): UserRequest;\n\tprotected abstract decodeResponse(response: QueueResult | null): UserResult | null;\n\n\tprotected abstract encodeRequest(request: UserRequest): QueueRequest;\n\tprotected abstract encodeResponse(response: UserResult | null): QueueResult | null;\n\n\tprotected decodeEntry(entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>): KeetaAnchorQueueEntry<UserRequest, UserResult> {\n\t\treturn({\n\t\t\t...entry,\n\t\t\trequest: this.decodeRequest(entry.request),\n\t\t\toutput: this.decodeResponse(entry.output)\n\t\t});\n\t}\n\n\t/**\n\t * Enqueue an item to be processed by the queue\n\t */\n\tasync add(request: UserRequest, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\tawait this.initialize();\n\n\t\tconst encodedRequest = this.encodeRequest(request);\n\t\tconst newID = await this.queue.add(encodedRequest, info);\n\t\treturn(newID);\n\t}\n\n\t/**\n\t * Get a single entry from storage by ID\n\t */\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<UserRequest, UserResult> | null> {\n\t\tawait this.initialize();\n\n\t\tconst entry = await this.queue.get(id);\n\t\tif (!entry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(this.decodeEntry(entry));\n\t}\n\n\t/**\n\t * Get entries from storage with an optional filter\n\t */\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<UserRequest, UserResult>[]> {\n\t\tawait this.initialize();\n\n\t\tconst entries = await this.queue.query(filter);\n\t\treturn(entries.map((entry) => {\n\t\t\treturn(this.decodeEntry(entry));\n\t\t}));\n\t}\n\n\t/**\n\t * Set the status of an entry in the queue\n\t */\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<UserResult>): Promise<void> {\n\t\tawait this.initialize();\n\n\t\tlet encodedOutput: QueueResult | null | undefined = undefined;\n\t\tif (ancillary?.output !== undefined) {\n\t\t\tencodedOutput = this.encodeResponse(ancillary.output);\n\t\t}\n\n\t\treturn(await this.queue.setStatus(id, status, {\n\t\t\t...ancillary,\n\t\t\toutput: encodedOutput\n\t\t}));\n\t}\n\n\t/**\n\t * Checks to see if the queue is runnable\n\t */\n\tasync runnable(): Promise<boolean> {\n\t\tawait this.initialize();\n\n\t\tconst pendingEntries = await this.queue.query({ status: 'pending', limit: 1 });\n\t\tif (pendingEntries.length > 0) {\n\t\t\treturn(true);\n\t\t}\n\n\t\tfor (const pipe of this.pipes) {\n\t\t\tconst pipeRunnable = await pipe.target.runnable();\n\t\t\tif (pipeRunnable) {\n\t\t\t\treturn(true);\n\t\t\t}\n\t\t}\n\n\t\treturn(false);\n\t}\n\n\tprivate async updateRunnerLockTimestamp(): Promise<void> {\n\t\tconst logger = this.methodLogger('updateRunnerLockTimestamp');\n\n\t\ttry {\n\t\t\tlogger?.debug('Updating sequential processing lock timestamp for worker ID', this.workerID);\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\toldStatus: 'processing',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t\tlogger?.debug('Updated sequential processing lock timestamp for worker ID', this.workerID);\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.error('Failed to update sequential processing lock timestamp for worker ID', this.workerID, ':', error);\n\t\t\tthrow(error);\n\t\t}\n\t}\n\n\tprivate async getRunnerLock(cleanup: InstanceType<typeof AsyncDisposableStack>): Promise<boolean> {\n\t\tconst logger = this.methodLogger('getRunnerLock');\n\n\t\ttry {\n\t\t\tlogger?.debug('Acquiring sequential processing lock for worker ID', this.workerID);\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\toldStatus: '@internal',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t\tlogger?.debug('Acquired sequential processing lock for worker ID', this.workerID);\n\t\t} catch (error: unknown) {\n\t\t\tif (Errors.IncorrectStateAssertedError.isInstance(error)) {\n\t\t\t\treturn(false);\n\t\t\t}\n\n\t\t\tthrow(error);\n\t\t}\n\n\t\tcleanup.defer(async () => {\n\t\t\tfor (let retry = 0; retry < 10; retry++) {\n\t\t\t\tlogger?.debug(`Releasing sequential processing lock try #${retry + 1} for worker ID`, this.workerID);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.queue.setStatus(this.runnerLockKey, '@internal', {\n\t\t\t\t\t\toldStatus: 'processing',\n\t\t\t\t\t\tby: undefined\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tawait asleep(1000);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t});\n\n\t\treturn(true);\n\t}\n\n\tprivate async maintainRunnerLock(): Promise<void> {\n\t\tconst logger = this.methodLogger('maintainRunnerLock');\n\t\tconst moment = new Date();\n\t\tawait using cleanup = new AsyncDisposableStack();\n\n\t\tconst obtained = await this.getRunnerLock(cleanup);\n\t\tif (obtained) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Check to see if the lock is stale\n\t\t */\n\t\tconst lockEntry = await this.queue.get(this.runnerLockKey);\n\n\t\tif (!lockEntry) {\n\t\t\treturn;\n\t\t}\n\t\tconst lockAge = moment.getTime() - lockEntry.updated.getTime();\n\t\tif (lockAge > this.processTimeout * this.stuckMultiplier) {\n\t\t\tlogger?.warn('Processing lock is stale, taking over lock for worker ID', this.workerID);\n\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, '@internal', {\n\t\t\t\toldStatus: 'processing',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Run the queue processor\n\t *\n\t * Processes up to `batchSize` entries from the queue and returns\n\t * true if there may be more work to do, or false if the queue\n\t * is empty.\n\t *\n\t * @param options Optional run options\n\t */\n\tasync run(options?: KeetaAnchorQueueRunOptions): Promise<boolean> {\n\t\tconst timeout = options?.timeoutMs;\n\n\t\tawait this.initialize();\n\n\t\tconst logger = this.methodLogger('run');\n\t\tconst batchSize = this.batchSize;\n\t\tconst processTimeout = this.processTimeout;\n\t\tawait using cleanup = new AsyncDisposableStack();\n\n\t\tlet retval = true;\n\n\t\tconst startTime = Date.now();\n\n\t\tconst locked = await this.getRunnerLock(cleanup);\n\t\tif (!locked) {\n\t\t\tlogger?.debug('Another worker is already processing the queue, skipping run');\n\n\t\t\treturn(true);\n\t\t}\n\n\t\tconst processJobOk = Symbol('processJobOk');\n\t\tconst processJobTimeout = Symbol('processJobTimeout');\n\n\t\tconst processJob = async (index: number, entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>, startingStatus: KeetaAnchorQueueStatus, processor: (entry: KeetaAnchorQueueEntry<UserRequest, UserResult>) => Promise<{ status: KeetaAnchorQueueStatus; output: UserResult | null; error?: string | undefined; }>): Promise<typeof processJobTimeout | typeof processJobOk> => {\n\t\t\tif (timeout !== undefined) {\n\t\t\t\tconst elapsed = Date.now() - startTime;\n\t\t\t\tif (elapsed >= timeout) {\n\t\t\t\t\tlogger?.debug(`Timeout of ${timeout}ms reached after processing ${index} entries (${startingStatus} phase; elapsed ${elapsed}ms)`);\n\n\t\t\t\t\treturn(processJobTimeout);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait this.updateRunnerLockTimestamp();\n\n\t\t\tlet setEntryStatus: { status: KeetaAnchorQueueStatus; output: UserResult | null; error?: string | undefined; } = { status: 'failed_temporarily', output: null };\n\n\t\t\tlogger?.debug(`Trying to acquire process lock for entry request with id ${String(entry.id)}`);\n\n\t\t\ttry {\n\t\t\t\t/*\n\t\t\t\t * Get a lock by setting it to 'processing'\n\t\t\t\t */\n\t\t\t\tawait this.queue.setStatus(entry.id, 'processing', { oldStatus: startingStatus, by: this.workerID });\n\n\t\t\t\t/*\n\t\t\t\t * Log an info-level log when we start and finish processing an entry\n\t\t\t\t */\n\t\t\t\tlogger?.info(`Processing entry request with id ${String(entry.id)}`);\n\n\t\t\t\t/*\n\t\t\t\t * Process the entry with a timeout, if the timeout is reached\n\t\t\t\t * we should mark the process as aborted because we no longer\n\t\t\t\t * know what state the work is in and someone will need to\n\t\t\t\t * inspect the job and determine through some other means if\n\t\t\t\t * it is completed or failed.\n\t\t\t\t */\n\t\t\t\tlet timeoutTimer: ReturnType<typeof setTimeout> | null = null;\n\t\t\t\tsetEntryStatus = await Promise.race([\n\t\t\t\t\tnew Promise<{ status: 'aborted', output: null }>(function(resolve) {\n\t\t\t\t\t\ttimeoutTimer = setTimeout(function() {\n\t\t\t\t\t\t\tresolve({ status: 'aborted', output: null });\n\t\t\t\t\t\t}, processTimeout);\n\t\t\t\t\t}),\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn(await processor(this.decodeEntry(entry)));\n\t\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t\tif (KeetaAnchorQueueProcessorResult.isInstance<UserResult>(error)) {\n\t\t\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\t\t\tstatus: error.status,\n\t\t\t\t\t\t\t\t\toutput: error.output,\n\t\t\t\t\t\t\t\t\terror: error.error\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tif (timeoutTimer) {\n\t\t\t\t\t\t\t\tclearTimeout(timeoutTimer);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})()\n\t\t\t\t]);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tif (Errors.IncorrectStateAssertedError.isInstance(error)) {\n\t\t\t\t\tlogger?.debug(`Skipping request with id ${String(entry.id)} because it is no longer in the expected state \"${startingStatus}\"`, error);\n\n\t\t\t\t\treturn(processJobOk);\n\t\t\t\t}\n\n\t\t\t\tlogger?.error(`Failed to process request with id ${String(entry.id)}, setting state to \"${setEntryStatus.status}\":`, error);\n\t\t\t\tsetEntryStatus.status = 'failed_temporarily';\n\t\t\t\tsetEntryStatus.error = String(error);\n\t\t\t}\n\n\t\t\tif (setEntryStatus.status === 'processing') {\n\t\t\t\tlogger?.error(`Processor for request with id ${String(entry.id)} returned invalid status \"processing\"`);\n\t\t\t\tsetEntryStatus.status = 'failed_temporarily';\n\t\t\t\tsetEntryStatus.error = 'Processor returned invalid status \"processing\"';\n\t\t\t}\n\n\t\t\tlet by: KeetaAnchorQueueWorkerID | undefined = this.workerID;\n\t\t\tif (setEntryStatus.status === 'pending') {\n\t\t\t\tby = undefined;\n\t\t\t}\n\n\t\t\tlogger?.info(`Finished processing entry request with id ${String(entry.id)} with new status`, setEntryStatus.status);\n\n\t\t\tawait this.queue.setStatus(entry.id, setEntryStatus.status, { oldStatus: 'processing', by: by, output: this.encodeResponse(setEntryStatus.output), error: setEntryStatus.error });\n\n\t\t\treturn(processJobOk);\n\t\t};\n\n\t\t/*\n\t\t * Process pending jobs first\n\t\t */\n\t\tfor (let index = 0; index < batchSize; index++) {\n\t\t\tconst entries = await this.queue.query({ status: 'pending', limit: 1 });\n\t\t\tconst entry = entries[0];\n\t\t\tif (entry === undefined) {\n\t\t\t\tretval = false;\n\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst result = await processJob(index, entry, 'pending', this.processor.bind(this));\n\t\t\tif (result === processJobTimeout) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\t/*\n\t\t * Next process any pipes to other runners\n\t\t */\n\t\tconst pipes = [...this.pipes];\n\t\tfor (const pipe of pipes) {\n\t\t\tif (pipe.exclusiveTarget === false) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet remainingTime: number | undefined = undefined;\n\t\t\tif (timeout !== undefined) {\n\t\t\t\tconst elapsed = Date.now() - startTime;\n\t\t\t\tremainingTime = timeout - elapsed;\n\t\t\t\tif (remainingTime <= 0) {\n\t\t\t\t\tremainingTime = -1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst pipeHasMoreWork = await pipe.target.run({\n\t\t\t\t...options,\n\t\t\t\ttimeoutMs: remainingTime\n\t\t\t});\n\n\t\t\tif (pipeHasMoreWork) {\n\t\t\t\tretval = true;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Process stuck or aborted jobs (if possible)\n\t\t */\n\t\tconst conditions = [{\n\t\t\tstatus: 'aborted' as const,\n\t\t\tprocessor: this.processorAborted?.bind(this)\n\t\t}, {\n\t\t\tstatus: 'stuck' as const,\n\t\t\tprocessor: this.processorStuck?.bind(this)\n\t\t}];\n\n\t\tlet timeoutReached = false;\n\t\tfor (const condition of conditions) {\n\t\t\tif (condition.processor === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tfor (let index = 0; index < batchSize; index++) {\n\t\t\t\tconst entries = await this.queue.query({ status: condition.status, limit: 1 });\n\t\t\t\tconst entry = entries[0];\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tconst result = await processJob(index, entry, condition.status, condition.processor);\n\t\t\t\tif (result === processJobTimeout) {\n\t\t\t\t\ttimeoutReached = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (timeoutReached) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\tprivate async markStuckRequestsAsStuck(): Promise<void> {\n\t\tconst stuckThreshold = this.processTimeout * this.stuckMultiplier;\n\n\t\tconst logger = this.methodLogger('markStuckRequestsAsStuck');\n\t\tconst now = Date.now();\n\n\t\tconst requests = await this.queue.query({ status: 'processing', limit: 100, updatedBefore: new Date(now - stuckThreshold) });\n\t\tfor (const request of requests) {\n\t\t\t/*\n\t\t\t * Skip the runner lock entries, they are managed separately\n\t\t\t */\n\t\t\tif (request.id.toString().startsWith('@runner-lock:9ba756f0-7aa2-41c7-a1ea-b010dc752ae8.worker.')) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tlogger?.warn(`Marking request with id ${String(request.id)} as stuck`);\n\n\t\t\t\tawait this.queue.setStatus(request.id, 'stuck', { oldStatus: 'processing', by: this.workerID });\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.error(`Failed to mark request with id ${String(request.id)} as stuck:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async requeueFailedRequests(): Promise<void> {\n\t\tconst retryDelay = this.retryDelay;\n\t\tconst maxRetries = this.maxRetries;\n\n\t\tconst logger = this.methodLogger('requeueFailedRequests');\n\t\tconst now = Date.now();\n\n\t\tconst requests = await this.queue.query({ status: 'failed_temporarily', limit: 100, updatedBefore: new Date(now - retryDelay) });\n\t\tfor (const request of requests) {\n\t\t\ttry {\n\t\t\t\tif (request.failures >= maxRetries) {\n\t\t\t\t\tlogger?.info(`Request with id ${String(request.id)} has exceeded maximum retries, not requeuing -- moving to failed_permanently`);\n\t\t\t\t\tawait this.queue.setStatus(request.id, 'failed_permanently', { oldStatus: 'failed_temporarily', by: this.workerID });\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlogger?.debug(`Requeuing failed request with id ${String(request.id)}`);\n\n\t\t\t\tawait this.queue.setStatus(request.id, 'pending', { oldStatus: 'failed_temporarily', by: this.workerID });\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.error(`Failed to requeue request with id ${String(request.id)}:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async moveCompletedToNextStage(statusTarget: KeetaAnchorPipeableQueueStatus): Promise<void> {\n\t\tconst logger = this.methodLogger('moveCompletedToNextStage');\n\n\t\tconst pipes = [...this.pipes].filter(function(pipe) {\n\t\t\treturn(pipe.acceptStatus === statusTarget);\n\t\t});\n\n\t\tif (pipes.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst allRequests = await this.queue.query({ status: statusTarget, limit: 100 });\n\t\tlet requests = allRequests;\n\n\t\tconst RequestSentToPipes = new Map<KeetaAnchorQueueRequestID, number>();\n\t\tfunction IncrRequestSentToPipes(requestID: KeetaAnchorQueueRequestID): void {\n\t\t\tconst sentCount = RequestSentToPipes.get(requestID) ?? 0;\n\t\t\tRequestSentToPipes.set(requestID, sentCount + 1);\n\t\t}\n\n\t\tconst getNextPipeRequestInput = (entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>) => {\n\t\t\tif (statusTarget === 'completed') {\n\t\t\t\treturn(this.decodeResponse(entry.output));\n\t\t\t} else if (statusTarget === 'failed_permanently') {\n\t\t\t\treturn(this.decodeRequest(entry.request));\n\t\t\t}\n\n\t\t\tassertNever(statusTarget);\n\t\t};\n\n\t\tfor (const pipe of pipes) {\n\t\t\tlogger?.debug('Processing pipe to target', pipe.target.id, pipe.isBatchPipe ? '(batch pipe)' : '(single item pipe)');\n\n\t\t\tif (pipe.isBatchPipe) {\n\t\t\t\t/**\n\t\t\t\t * Keep track of all the requests we successfully\n\t\t\t\t * sent to the target stage\n\t\t\t\t */\n\t\t\t\tconst allTargetSeenRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * During each iteration of the batch processing, we keep track\n\t\t\t\t * of the IDs we have already seen by the target and processed\n\t\t\t\t * so we don't try to reprocess them again\n\t\t\t\t */\n\t\t\t\tconst iterationTargetSeenRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * If we get a batch that cannot be added to the target pipe,\n\t\t\t\t * we just skip over them for retrying at a later date\n\t\t\t\t */\n\t\t\t\tconst skipRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * Compute a durable ID for this batch and target\n\t\t\t\t */\n\t\t\t\tlet batchID = ConvertStringToRequestID(crypto.randomUUID());\n\n\t\t\t\t/**\n\t\t\t\t * Keep track of sequential failures to find enough entries\n\t\t\t\t * and stop processing if we can't find enough after a few tries\n\t\t\t\t * in a row\n\t\t\t\t */\n\t\t\t\tlet sequentialFailureCount = 0;\n\n\t\t\t\tfor (;requests.length >= pipe.minBatchSize;\n\t\t\t\t\t/*\n\t\t\t\t\t * Remove any entries we have already seen during\n\t\t\t\t\t * the last iteration of the loop\n\t\t\t\t\t */\n\t\t\t\t\trequests = requests.filter(function(entry) {\n\t\t\t\t\t\treturn(!iterationTargetSeenRequestIDs.has(entry.id) && !skipRequestIDs.has(entry.id));\n\t\t\t\t\t})\n\t\t\t\t) {\n\t\t\t\t\titerationTargetSeenRequestIDs.clear();\n\n\t\t\t\t\tlogger?.debug(`Preparing to move ${statusTarget} requests to next stage ${pipe.target.id} (min=${pipe.minBatchSize}, max=${pipe.maxBatchSize}), have ${requests.length} ${statusTarget} requests available`);\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Compute a batch of entries to send to the next stage,\n\t\t\t\t\t * constrained to the max batch size of the pipe and\n\t\t\t\t\t * the entries which have non-null outputs\n\t\t\t\t\t */\n\t\t\t\t\tconst batchRaw = requests.map((entry) => {\n\t\t\t\t\t\treturn({ output: getNextPipeRequestInput(entry), id: entry.id });\n\t\t\t\t\t}).filter(function(entry): entry is { output: UserRequest | UserResult; id: KeetaAnchorQueueRequestID; } {\n\t\t\t\t\t\tif (entry === null) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(true);\n\t\t\t\t\t}).slice(0, pipe.maxBatchSize);\n\n\t\t\t\t\t/*\n\t\t\t\t\t * If we don't have enough entries to meet the minimum\n\t\t\t\t\t * batch size, skip this iteration\n\t\t\t\t\t */\n\t\t\t\t\tif (batchRaw.length < pipe.minBatchSize) {\n\t\t\t\t\t\tsequentialFailureCount++;\n\t\t\t\t\t\tif (sequentialFailureCount >= 3) {\n\t\t\t\t\t\t\tlogger?.debug(`Not enough ${statusTarget} requests to move to next stage ${pipe.target.id}, stopping batch processing`);\n\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlogger?.debug(`Not moving ${statusTarget} requests to next stage ${pipe.target.id} because batch size ${batchRaw.length} is less than minimum size ${pipe.minBatchSize}`);\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tsequentialFailureCount = 0;\n\n\t\t\t\t\t/**\n\t\t\t\t\t * The IDs for the entries we are sending to the next stage\n\t\t\t\t\t * target -- this may get reduced if we find there are already\n\t\t\t\t\t * jobs in the next stage that have the idempotentIDs of one of\n\t\t\t\t\t * these jobs\n\t\t\t\t\t */\n\t\t\t\t\tconst batchLocalIDs = new Set(batchRaw.map(function(entry) {\n\t\t\t\t\t\treturn(entry.id);\n\t\t\t\t\t}));\n\t\t\t\t\t/**\n\t\t\t\t\t * The outputs for the batch we are sending to the next stage\n\t\t\t\t\t */\n\t\t\t\t\tconst batchOutput = batchRaw.map(function(entry) {\n\t\t\t\t\t\treturn(entry.output);\n\t\t\t\t\t});\n\n\t\t\t\t\tlogger?.debug(`Moving batch of ${batchOutput.length} ${statusTarget} requests to next pipe`, pipe.target.id, '(input entry IDs:', Array.from(batchLocalIDs), '->', `${pipe.target.id}:${String(batchID)})`);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// There is no way for typescript to cleanly infer the type here, so we assert it.\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\t\tawait pipe.target.add(batchOutput as (UserRequest & UserResult)[], {\n\t\t\t\t\t\t\tid: batchID,\n\t\t\t\t\t\t\t/* Use the set of IDs as the idempotent IDs for the batch */\n\t\t\t\t\t\t\tidempotentKeys: batchLocalIDs\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tbatchID = ConvertStringToRequestID(crypto.randomUUID());\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (Errors.IdempotentExistsError.isInstance(error) && error.idempotentIDsFound) {\n\t\t\t\t\t\t\tlogger?.debug('Some of the jobs have already been added to the target queue, skipping those:', error.idempotentIDsFound.values());\n\t\t\t\t\t\t\tfor (const requestID of error.idempotentIDsFound) {\n\t\t\t\t\t\t\t\titerationTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\t\t\tallTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t/*\n\t\t\t\t\t\t\t * If we got some kind of other error adding these\n\t\t\t\t\t\t\t * items to the target queue runner, just skip them\n\t\t\t\t\t\t\t * and we will retry them on the next iteration\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tlogger?.error(`Failed to move completed batch to next stage ${pipe.target.id}, will try to create another batch without them:`, error);\n\n\t\t\t\t\t\t\tfor (const requestID of batchLocalIDs) {\n\t\t\t\t\t\t\t\tskipRequestIDs.add(requestID);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const requestID of batchLocalIDs) {\n\t\t\t\t\t\titerationTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\tallTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/*\n\t\t\t\t * For every request we know the target has definitely seen, mark it\n\t\t\t\t * as moved for this pipe\n\t\t\t\t */\n\t\t\t\tfor (const requestID of allTargetSeenRequestIDs) {\n\t\t\t\t\tIncrRequestSentToPipes(requestID);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const request of requests) {\n\t\t\t\t\tlet shouldMarkAsMoved = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = getNextPipeRequestInput(request);\n\n\t\t\t\t\t\tif (output === null) {\n\t\t\t\t\t\t\tlogger?.debug(`Completed request with id ${String(request.id)} has no output -- next stage will not be run`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger?.debug(`Moving ${statusTarget} request with id ${String(request.id)} to next pipe`, pipe.target.id);\n\t\t\t\t\t\t\t// There is no way for typescript to cleanly infer the type here, so we assert it.\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\t\t\tawait pipe.target.add(output as UserRequest & UserResult, { id: request.id });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tlogger?.error(`Failed to move completed request with id ${String(request.id)} to next stage:`, error);\n\t\t\t\t\t\tshouldMarkAsMoved = false;\n\t\t\t\t\t}\n\t\t\t\t\tif (shouldMarkAsMoved) {\n\t\t\t\t\t\tIncrRequestSentToPipes(request.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst TotalPipes = pipes.length;\n\t\tfor (const request of allRequests) {\n\t\t\tconst sentCount = RequestSentToPipes.get(request.id) ?? 0;\n\t\t\tif (sentCount !== TotalPipes) {\n\t\t\t\tlogger?.debug(`${statusTarget} request with id ${String(request.id)} was only moved to ${sentCount} out of ${TotalPipes} pipes -- not marking as moved`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlogger?.debug(`Marking ${statusTarget} request with id ${String(request.id)} as moved`);\n\n\t\t\tawait this.queue.setStatus(request.id, 'moved', { oldStatus: statusTarget, by: this.workerID });\n\t\t}\n\n\t}\n\n\tasync maintain(): Promise<void> {\n\t\tconst logger = this.methodLogger('maintain');\n\n\t\tawait this.initialize();\n\n\t\t/*\n\t\t * Call `maintainRunnerLock` for every worker ID (not just 0)\n\t\t * so that we can ensure the runner lock is maintained and not\n\t\t * stale as part of maintain()\n\t\t */\n\t\ttry {\n\t\t\tawait this.maintainRunnerLock();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to maintain runner lock:', error);\n\t\t}\n\n\t\t/*\n\t\t * Only the worker with ID 0 should the rest of the maintenance tasks\n\t\t * so that we don't have multiple workers trying to do the same\n\t\t * maintenance tasks at the same time on the same queues\n\t\t */\n\t\tif (this.workers.id !== 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlogger?.debug(`Worker ID ${this.workerID} beginning maintenance tasks for queue ${this.queue.id}`);\n\n\t\ttry {\n\t\t\tawait this.markStuckRequestsAsStuck();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to mark stuck requests as stuck:', error);\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.requeueFailedRequests();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to requeue failed requests:', error);\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.deleteExpiredCompleted();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to delete expired completed requests:', error);\n\t\t}\n\n\t\tfor (const pipeStatus of keetaAnchorPipeableQueueStatuses) {\n\t\t\ttry {\n\t\t\t\tawait this.moveCompletedToNextStage(pipeStatus);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to move ${pipeStatus} requests to next stage:`, error);\n\t\t\t}\n\t\t}\n\n\t\tfor (const pipe of this.pipes) {\n\t\t\ttry {\n\t\t\t\tif (pipe.exclusiveTarget === false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait pipe.target.maintain();\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to maintain piped runner with ID ${pipe.target.id}:`, error);\n\t\t\t}\n\t\t}\n\n\t\tif (this.queue.maintain) {\n\t\t\ttry {\n\t\t\t\tawait this.queue.maintain();\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to maintain queue storage driver with ID ${this.queue.id}`, error);\n\t\t\t}\n\t\t}\n\n\t\tlogger?.debug(`Worker ID ${this.workerID} completed maintenance tasks for queue ${this.queue.id}`);\n\t}\n\n\tprivate async deleteExpiredCompleted(): Promise<void> {\n\t\tif (this.completedRetentionDays === Infinity) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.pipes.length > 0 || this.incomingPipeCount > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filter: KeetaAnchorQueueFilter = {\n\t\t\tstatus: 'completed',\n\t\t\tlimit: this.completedRetentionLimitPerRun\n\t\t};\n\n\t\tif (this.completedRetentionDays > 0) {\n\t\t\tfilter.updatedBefore = new Date(Date.now() - this.completedRetentionDays * 86_400_000);\n\t\t}\n\n\t\tconst entries = await this.queue.query(filter);\n\n\t\tif (entries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.queue.delete(entries.map(function(entry) {\n\t\t\treturn({\n\t\t\t\tid: entry.id,\n\t\t\t\tstatus: entry.status\n\t\t\t});\n\t\t}));\n\t}\n\n\t/**\n\t * Pipe the the completed entries of this runner to another runner\n\t */\n\tpipe<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserResult, T1, QueueResult, T2>, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: false,\n\t\t\ttarget: target,\n\t\t\tacceptStatus: 'completed'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tpipeFailed<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserRequest, T1, QueueResult, T2>, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: false,\n\t\t\ttarget: target,\n\t\t\tacceptStatus: 'failed_permanently'\n\t\t});\n\t\treturn(target);\n\t}\n\n\t/**\n\t * Pipe batches of completed entries from this runner to another runner\n\t */\n\tpipeBatch<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserResult[], T1, JSONSerializable, T2>, maxBatchSize = 100, minBatchSize = 1, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: true,\n\t\t\ttarget: target,\n\t\t\tminBatchSize: minBatchSize,\n\t\t\tmaxBatchSize: maxBatchSize,\n\t\t\tacceptStatus: 'completed'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tpipeBatchFailed<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserRequest[], T1, JSONSerializable, T2>, maxBatchSize = 100, minBatchSize = 1, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: true,\n\t\t\ttarget: target,\n\t\t\tminBatchSize: minBatchSize,\n\t\t\tmaxBatchSize: maxBatchSize,\n\t\t\tacceptStatus: 'failed_permanently'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.methodLogger('destroy')?.debug('Destroying queue runner attached to queue', this.queue.id);\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\tawait this.destroy();\n\t}\n}\n\n/**\n * A KeetaAnchorQueueRunner for use when you want to process already\n * JSON-serializable data without any encoding/decoding needed\n */\nexport abstract class KeetaAnchorQueueRunnerJSON<UserRequest extends JSONSerializable = JSONSerializable, UserResult extends JSONSerializable = JSONSerializable> extends KeetaAnchorQueueRunner<UserRequest, UserResult, JSONSerializable, JSONSerializable> {\n\tprotected decodeRequest(request: JSONSerializable): UserRequest {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(request as UserRequest);\n\t}\n\n\tprotected decodeResponse(response: JSONSerializable | null): UserResult | null {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(response as UserResult | null);\n\t}\n\n\tprotected encodeRequest(request: JSONSerializable): JSONSerializable {\n\t\treturn(request);\n\t}\n\n\tprotected encodeResponse(response: JSONSerializable | null): JSONSerializable | null {\n\t\treturn(response);\n\t}\n}\n\n/**\n * A KeetaAnchorQueueRunnerJSON that takes a processor function\n * in the constructor -- this is mainly useful for testing\n */\nexport class KeetaAnchorQueueRunnerJSONConfigProc<UserRequest extends JSONSerializable = JSONSerializable, UserResult extends JSONSerializable = JSONSerializable> extends KeetaAnchorQueueRunnerJSON<UserRequest, UserResult> {\n\tprotected readonly processor: KeetaAnchorQueueRunner<UserRequest, UserResult>['processor'];\n\n\tconstructor(config: ConstructorParameters<typeof KeetaAnchorQueueRunner>[0] & {\n\t\tprocessor: KeetaAnchorQueueRunner<UserRequest, UserResult>['processor'];\n\t\tprocessorStuck?: KeetaAnchorQueueRunner<UserRequest, UserResult>['processorStuck'] | keyof typeof KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers | undefined;\n\t\tprocessorAborted?: KeetaAnchorQueueRunner<UserRequest, UserResult>['processorAborted'] | keyof typeof KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers | undefined;\n\t} & Partial<KeetaAnchorQueueRunnerConfigurationObject>) {\n\t\tsuper(config);\n\n\t\tconst { processor, processorStuck, processorAborted, ...parameters } = config;\n\n\t\tthis.processor = processor;\n\n\t\tif (processorStuck) {\n\t\t\tif (typeof processorStuck === 'string') {\n\t\t\t\tthis.processorStuck = KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers[processorStuck];\n\t\t\t} else {\n\t\t\t\tthis.processorStuck = processorStuck;\n\t\t\t}\n\t\t}\n\t\tif (processorAborted) {\n\t\t\tif (typeof processorAborted === 'string') {\n\t\t\t\tthis.processorAborted = KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers[processorAborted];\n\t\t\t} else {\n\t\t\t\tthis.processorAborted = processorAborted;\n\t\t\t}\n\t\t}\n\n\t\tthis.setConfiguration(parameters);\n\t}\n}\n\nexport { AllErrors as Errors };\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype _ignore_static_assert_memory = AssertNever<typeof KeetaAnchorQueueStorageDriverMemory<{ a: string; }, number> extends KeetaAnchorQueueStorageDriverConstructor<{ a: string; }, number> ? never : false>;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/queue/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACN,sBAAsB,EACtB,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAOzD,MAAM,gCAAgC,GAAG,CAAE,WAAW,EAAE,oBAAoB,CAAW,CAAC;AA6MxF;;GAEG;AACH,MAAM,OAAO,mCAAmC;IACrC,YAAY,GAA4E,EAAE,CAAC;IAClF,MAAM,CAAsB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C,gBAAgB,GAAG,oCAAoC,CAAC,uBAAuB,CAAC,gBAAgB,CAAC,CAAC;YACxG,CAAC;iBAAM,CAAC;gBACP,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;YAC1C,CAAC;QACF,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CACD;AAED,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,CAAC","sourcesContent":["import type { BrandedString, Brand } from '../utils/brand.ts';\nimport type { Logger } from '../log/index.ts';\nimport type { JSONSerializable } from '../utils/json.ts';\nimport { assertNever } from '../utils/never.js';\nimport type { AssertNever } from '../utils/never.ts';\nimport type { KeetaAnchorQueueRunOptions } from './common.js';\nimport { asleep } from '../utils/asleep.js';\nimport { Errors } from './common.js';\nimport {\n\tCompareQueueEntryOrder,\n\tMethodLogger,\n\tManageStatusUpdates,\n\tConvertStringToRequestID\n} from './internal.js';\nimport { AsyncDisposableStack } from '../utils/defer.js';\n\nexport type KeetaAnchorQueueRequest<QueueRequest> = QueueRequest;\nexport type KeetaAnchorQueueRequestID = BrandedString<'KeetaAnchorQueueID'>;\nexport type KeetaAnchorQueueWorkerID = Brand<number, 'KeetaAnchorQueueWorkerID'>;\n\nexport type KeetaAnchorQueueStatus = 'pending' | 'processing' | 'completed' | 'failed_temporarily' | 'failed_permanently' | 'stuck' | 'aborted' | 'moved' | '@internal';\nconst keetaAnchorPipeableQueueStatuses = [ 'completed', 'failed_permanently' ] as const;\n/**\n * This is a type-level assertion to ensure that all values in keetaAnchorPipeableQueueStatuses are valid KeetaAnchorQueueStatus values.\n * If this assertion fails, it means that there is a value in keetaAnchorPipeableQueueStatuses that is not a valid KeetaAnchorQueueStatus, and the code will not compile.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype __check_keetaAnchorPipeableQueueStatuses_valid = AssertNever<typeof keetaAnchorPipeableQueueStatuses[number] extends KeetaAnchorQueueStatus ? never : true>;\n\nexport type KeetaAnchorPipeableQueueStatus = Extract<KeetaAnchorQueueStatus, typeof keetaAnchorPipeableQueueStatuses[number]>;\nexport type KeetaAnchorQueueEntry<QueueRequest, QueueResult> = {\n\t/**\n\t * The Job ID\n\t */\n\tid: KeetaAnchorQueueRequestID;\n\t/**\n\t * Idempotent IDs from a previous stage\n\t */\n\tidempotentKeys?: Set<KeetaAnchorQueueRequestID> | undefined;\n\trequest: KeetaAnchorQueueRequest<QueueRequest>;\n\toutput: QueueResult | null;\n\tlastError: string | null;\n\tstatus: KeetaAnchorQueueStatus;\n\tcreated: Date;\n\tupdated: Date;\n\tworker: KeetaAnchorQueueWorkerID | null;\n\tfailures: number;\n};\n\n/**\n * Extra information to provide to a request when adding an entry to the queue\n */\nexport type KeetaAnchorQueueEntryExtra = {\n\t[key in 'idempotentKeys' | 'id' | 'status']?: (key extends 'id' ? KeetaAnchorQueueRequestID | string : KeetaAnchorQueueEntry<never, never>[key]) | undefined;\n};\n\nexport type KeetaAnchorQueueFilter = {\n\t/**\n\t * Only return entries with this status\n\t */\n\tstatus?: KeetaAnchorQueueStatus;\n\t/**\n\t * Only return entries last updated before this date\n\t */\n\tupdatedBefore?: Date;\n\t/**\n\t * Limit the number of entries returned\n\t */\n\tlimit?: number;\n};\n\nexport type KeetaAnchorQueueDeleteInput = {\n\tid: KeetaAnchorQueueRequestID;\n\tstatus: KeetaAnchorQueueStatus;\n};\n\nexport type KeetaAnchorQueueCommonOptions = {\n\tlogger?: Logger | undefined;\n\tid?: string | undefined;\n};\n\nexport type KeetaAnchorQueueRunnerOptions = KeetaAnchorQueueCommonOptions & {\n\t/**\n\t * If specified, then multiple workers can be used to process this queue\n\t * in parallel by splitting the work among the workers.\n\t *\n\t * By default, only a single worker will process the queue (count=1, id=0)\n\t */\n\tworkers?: {\n\t\tcount: number;\n\t\tid: number;\n\t} | undefined;\n};\n\nexport type KeetaAnchorQueueStorageOptions = KeetaAnchorQueueCommonOptions & {\n\tpath?: string[] | undefined;\n};\n\nexport type KeetaAnchorQueueEntryAncillaryData<QueueResult> = {\n\t/**\n\t * The previous status of the entry -- if the entry is not currently in this status,\n\t * the status update will fail\n\t */\n\toldStatus?: KeetaAnchorQueueStatus | undefined;\n\t/**\n\t * The worker ID performing the status update\n\t */\n\tby?: KeetaAnchorQueueWorkerID | undefined;\n\t/**\n\t * The output data to store with the entry\n\t */\n\toutput?: QueueResult | null | undefined;\n\t/**\n\t * An error message to store with the entry\n\t */\n\terror?: string | undefined;\n};\n\nexport type KeetaAnchorQueueStorageDriverConstructor<QueueRequest extends JSONSerializable, QueueResult extends JSONSerializable> = new(options?: KeetaAnchorQueueStorageOptions) => KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\nexport interface KeetaAnchorQueueStorageDriver<QueueRequest extends JSONSerializable, QueueResult extends JSONSerializable> {\n\t/**\n\t * An ID for this instance of the storage driver\n\t */\n\treadonly id: string;\n\n\t/**\n\t * The name of the storage driver\n\t */\n\treadonly name: string;\n\n\t/**\n\t * The partition ID for this instance of the storage driver\n\t *\n\t * This is used to divide a single storage backend into multiple\n\t * independent queues.\n\t *\n\t * The root partition is an empty array, and each element is\n\t * a hierarchical partition name.\n\t */\n\treadonly path: string[];\n\n\t/**\n\t * Enqueue an item to be processed by the queue\n\t *\n\t * It will be inserted into the queue as a 'pending' entry\n\t *\n\t * @param request The request to enqueue\n\t * @param id Optional ID to use for the entry -- if not provided, a new\n\t * ID will be generated. If the ID is already in use then\n\t * nothing will be added.\n\t * @returns The ID for the newly created pending entry\n\t */\n\tadd: (request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra) => Promise<KeetaAnchorQueueRequestID>;\n\n\t/**\n\t * Update the status of an entry in the queue\n\t *\n\t * If the status is \"failed_temporarily\", the failure count will be incremented\n\t *\n\t * @param id The entry ID to update\n\t * @param status The new status of the entry\n\t * @param ancillary Optional ancillary data for the status update\n\t * @returns void\n\t */\n\tsetStatus: (id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>) => Promise<void>;\n\n\t/**\n\t * Get entries from storage with an optional filter\n\t *\n\t * Entries MUST be returned oldest \"updated\" first. Ties MUST be\n\t * broken in a fixed order the driver chooses (entry ID for the\n\t * database drivers, insertion order for the memory driver), so\n\t * repeated queries agree. Every status change bumps \"updated\",\n\t * so an entry whose status is set (even to the same status) moves\n\t * to the back of the line. The runner relies on this to keep\n\t * entries that cannot make progress from blocking newer ones.\n\t *\n\t * @param filter The filter to apply (optional)\n\t * @returns An array of entries matching the criteria, in the order above\n\t */\n\tquery(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]>;\n\n\t/**\n\t * Get a single entry from storage by ID\n\t *\n\t * @param id The ID of the entry to retrieve\n\t * @returns The entry if found, or null if not found\n\t */\n\tget(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null>;\n\n\t/**\n\t * Delete entries by ID. Each entry is removed only if its current status matches\n\t * the status given in the input.\n\t */\n\tdelete(input: KeetaAnchorQueueDeleteInput[]): Promise<void>;\n\n\t/**\n\t * Perform maintenance tasks on the storage driver\n\t * (e.g. cleaning up old entries, etc)\n\t *\n\t * @returns void\n\t */\n\tmaintain?: () => Promise<void>;\n\n\t/**\n\t * Create a partitioned view of the queue\n\t *\n\t * @param partitionID The partition ID to use\n\t * @returns A new storage driver instance for the partition\n\t */\n\tpartition: (path: string) => Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>>;\n\n\t/**\n\t * Close the storage driver and release any resources\n\t */\n\tdestroy(): Promise<void>;\n\t[Symbol.asyncDispose](): Promise<void>;\n\n\t/** @internal */\n\t_Testing?: (key: string) => {\n\t\tsetToctouDelay?(delay: number): void;\n\t\tunsetToctouDelay?(): void;\n\t};\n}\n\n/**\n * An in-memory implementation of the KeetaAnchorQueueStorageDriver\n */\nexport class KeetaAnchorQueueStorageDriverMemory<QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> implements KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\tprotected queueStorage: { [path: string]: KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]; } = {};\n\tprotected readonly logger?: Logger | undefined;\n\tprotected partitionCounter = 0;\n\tprivate destroyed = false;\n\treadonly name: string = 'KeetaAnchorQueueStorageDriverMemory';\n\treadonly id: string;\n\treadonly path: string[] = [];\n\n\tconstructor(options?: KeetaAnchorQueueStorageOptions) {\n\t\tthis.id = options?.id ?? crypto.randomUUID();\n\t\tthis.logger = options?.logger;\n\t\tthis.path.push(...(options?.path ?? []));\n\t\tObject.freeze(this.path);\n\n\t\tthis.methodLogger('new')?.debug('Created new in-memory queue storage driver');\n\t}\n\n\tprotected clone(options?: Partial<KeetaAnchorQueueStorageOptions>): KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult> {\n\t\tconst cloned = new KeetaAnchorQueueStorageDriverMemory<QueueRequest, QueueResult>({\n\t\t\tlogger: this.logger,\n\t\t\tid: `${this.id}::${this.partitionCounter++}`,\n\t\t\tpath: [...this.path],\n\t\t\t...options\n\t\t});\n\t\tcloned.queueStorage = this.queueStorage;\n\n\t\treturn(cloned);\n\t}\n\n\tprotected get queue(): KeetaAnchorQueueEntry<QueueRequest, QueueResult>[] {\n\t\tconst pathKey = ['root', ...this.path].join('.');\n\t\tlet retval = this.queueStorage[pathKey];\n\t\tif (retval === undefined) {\n\t\t\tretval = this.queueStorage[pathKey] = [];\n\t\t}\n\t\treturn(retval);\n\t}\n\n\tprotected methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueStorageDriverMemory',\n\t\t\tfile: 'src/lib/queue/index.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\tprivate checkDestroyed(): void {\n\t\tif (this.destroyed) {\n\t\t\tthrow(new Error('Queue has been destroyed'));\n\t\t}\n\t}\n\n\tasync add(request: KeetaAnchorQueueRequest<QueueRequest>, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('add');\n\n\t\tlet id = ConvertStringToRequestID(info?.id);\n\t\tif (id) {\n\t\t\tconst duplicateID = this.queue.some(function(checkEntry) {\n\t\t\t\treturn(checkEntry.id === id);\n\t\t\t});\n\n\t\t\tif (duplicateID) {\n\t\t\t\tlogger?.debug(`Request with id ${String(id)} already exists, ignoring`);\n\n\t\t\t\treturn(id);\n\t\t\t}\n\t\t}\n\n\t\tconst idempotentIDs = info?.idempotentKeys;\n\t\tif (idempotentIDs) {\n\t\t\tconst matchingIdempotentEntries = new Set<KeetaAnchorQueueRequestID>();\n\t\t\tfor (const idempotentID of idempotentIDs) {\n\t\t\t\tconst idempotentEntryExists = this.queue.some(function(checkEntry) {\n\t\t\t\t\treturn(checkEntry.idempotentKeys?.has(idempotentID) ?? false);\n\t\t\t\t});\n\n\t\t\t\tif (idempotentEntryExists) {\n\t\t\t\t\tmatchingIdempotentEntries.add(idempotentID);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (matchingIdempotentEntries.size !== 0) {\n\t\t\t\tthrow(new Errors.IdempotentExistsError('One or more idempotent entries already exist in the queue', matchingIdempotentEntries));\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * The status to use for the new entry\n\t\t */\n\t\tconst status = info?.status ?? 'pending';\n\n\t\t/*\n\t\t * The ID is a branded string, so we must convert the generated UUID\n\t\t */\n\t\tid ??= ConvertStringToRequestID(crypto.randomUUID());\n\n\t\tlogger?.debug(`Enqueuing request with id ${String(id)}`);\n\n\t\tthis.queue.push({\n\t\t\tid: id,\n\t\t\trequest: request,\n\t\t\toutput: null,\n\t\t\tlastError: null,\n\t\t\tstatus: status,\n\t\t\tfailures: 0,\n\t\t\tcreated: new Date(),\n\t\t\tupdated: new Date(),\n\t\t\tworker: null,\n\t\t\tidempotentKeys: idempotentIDs ? new Set(idempotentIDs) : undefined\n\t\t});\n\n\t\treturn(id);\n\t}\n\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>): Promise<void> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('setStatus');\n\n\t\tconst entry = this.queue.find(function(checkEntry) {\n\t\t\treturn(checkEntry.id === id);\n\t\t});\n\t\tif (!entry) {\n\t\t\tthrow(new Error(`Request with ID ${String(id)} not found`));\n\t\t}\n\n\t\tconst changedFields = ManageStatusUpdates<QueueResult>(id, entry, status, ancillary, logger);\n\n\t\tObject.assign(entry, changedFields);\n\t}\n\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | null> {\n\t\tthis.checkDestroyed();\n\n\t\tconst entry = this.queue.find(function(checkEntry) {\n\t\t\treturn(checkEntry.id === id);\n\t\t});\n\n\t\tif (!entry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(structuredClone(entry));\n\t}\n\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult>[]> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('query');\n\n\t\tconst queueDuplicate = structuredClone(this.queue);\n\n\t\tlogger?.debug(`Querying queue with id ${this.id} with filter:`, filter);\n\n\t\tconst allEntriesInStatus = (function() {\n\t\t\tconst filterStatus = filter?.status;\n\t\t\tconst filterLastUpdateBefore = filter?.updatedBefore;\n\t\t\tif (filterStatus || filterLastUpdateBefore) {\n\t\t\t\treturn(queueDuplicate.filter(function(entry) {\n\t\t\t\t\tif (filterStatus) {\n\t\t\t\t\t\tif (entry.status !== filterStatus) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif (filterLastUpdateBefore) {\n\t\t\t\t\t\tif (entry.updated >= filterLastUpdateBefore) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn(true);\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\treturn(queueDuplicate);\n\t\t\t}\n\t\t})();\n\n\t\t/*\n\t\t * Oldest updated first, as the storage driver contract requires;\n\t\t * the sort is stable, so ties keep their insertion order. Both\n\t\t * branches above return a copy, so sorting in place is safe.\n\t\t */\n\t\tallEntriesInStatus.sort(CompareQueueEntryOrder);\n\n\t\tlet retval = allEntriesInStatus;\n\t\tif (filter?.limit !== undefined) {\n\t\t\tretval = allEntriesInStatus.slice(0, filter.limit);\n\t\t}\n\n\t\tlogger?.debug(`Queried queue with id ${this.id} with filter:`, filter, '-- found', retval.length, 'entries');\n\n\t\treturn(retval);\n\t}\n\n\tasync delete(input: KeetaAnchorQueueDeleteInput[]): Promise<void> {\n\t\tthis.checkDestroyed();\n\n\t\tif (input.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst logger = this.methodLogger('delete');\n\t\tconst targets = new Map(input.map(function(target) {\n\t\t\treturn([target.id, target.status] as const);\n\t\t}));\n\t\tlet deleted = 0;\n\n\t\tfor (let index = this.queue.length - 1; index >= 0; index--) {\n\t\t\tconst entry = this.queue[index];\n\t\t\tif (entry === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst expectedStatus = targets.get(entry.id);\n\t\t\tif (expectedStatus !== undefined && entry.status === expectedStatus) {\n\t\t\t\tthis.queue.splice(index, 1);\n\t\t\t\tdeleted++;\n\t\t\t}\n\t\t}\n\n\t\tif (deleted > 0) {\n\t\t\tlogger?.debug(`Deleted ${deleted} entries from queue ${this.id}`);\n\t\t}\n\t}\n\n\tasync partition(path: string): Promise<KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>> {\n\t\tthis.checkDestroyed();\n\n\t\tconst logger = this.methodLogger('partition');\n\n\t\tlogger?.debug(`Creating partitioned queue storage driver for path \"${path}\"`);\n\n\t\tconst partitioned = this.clone({\n\t\t\tpath: [...this.path, path]\n\t\t});\n\n\t\treturn(partitioned);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.destroyed = true;\n\t\tthis.methodLogger('destroy')?.debug('Destroying in-memory queue');\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\treturn(await this.destroy());\n\t}\n}\n\ninterface AdditionalPipeOptions {\n\t/**\n\t * If true, call maintain/run on this target when maintaining/running this runner\n\t * Defaults to true\n\t */\n\texclusiveTarget?: boolean;\n}\n\n// @ts-ignore\nexport interface KeetaAnchorQueueRunnerConfigurationObject {\n\tmaxRetries: number;\n\tprocessTimeout: number;\n\tbatchSize: number;\n\tretryDelay: number;\n\tstuckMultiplier: number;\n\tcompletedRetentionDays: number;\n\tcompletedRetentionLimitPerRun: number;\n}\n\ntype KeetaAnchorQueueProcessorResultValue<UserResult> = {\n\t/**\n\t *\n\t */\n\tstatus: KeetaAnchorQueueStatus;\n\toutput: UserResult | null;\n\terror?: string | undefined;\n}\n\n/**\n * An exception which can be thrown by a processor to indicate its results.\n *\n * This is identical to the processor return value, but allows the processor\n * to throw it instead of returning it.\n *\n * This is useful in nested code run from a processor which may need to abort\n * the normal flow control and return a result to the queue runner\n */\nclass KeetaAnchorQueueProcessorResult<UserResult = unknown> extends Error implements KeetaAnchorQueueProcessorResultValue<UserResult> {\n\treadonly status: KeetaAnchorQueueProcessorResultValue<UserResult>['status'];\n\treadonly output: KeetaAnchorQueueProcessorResultValue<UserResult>['output'];\n\treadonly error?: KeetaAnchorQueueProcessorResultValue<UserResult>['error'] | undefined;\n\treadonly cause?: unknown;\n\n\tprivate readonly keetaAnchorQueueProcessorResultObjectTypeID!: string;\n\tprivate static readonly keetaAnchorQueueProcessorResultObjectTypeID = '5d7f1578-e887-4104-bab0-4115ae33b08f';\n\n\tstatic isInstance<UserResult = unknown>(obj: unknown): obj is KeetaAnchorQueueProcessorResult<UserResult> {\n\t\tif (typeof obj !== 'object' || obj === null) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (!('keetaAnchorQueueProcessorResultObjectTypeID' in obj)) {\n\t\t\treturn(false);\n\t\t}\n\n\t\tconst checkID = obj['keetaAnchorQueueProcessorResultObjectTypeID'];\n\t\tif (typeof checkID !== 'string') {\n\t\t\treturn(false);\n\t\t}\n\n\t\tif (checkID !== KeetaAnchorQueueProcessorResult.keetaAnchorQueueProcessorResultObjectTypeID) {\n\t\t\treturn(false);\n\t\t}\n\n\t\treturn(true);\n\t}\n\n\tconstructor(message: string, result: KeetaAnchorQueueProcessorResultValue<UserResult>, cause?: unknown) {\n\t\tsuper(message);\n\n\t\tObject.defineProperty(this, 'keetaAnchorQueueProcessorResultObjectTypeID', {\n\t\t\tvalue: KeetaAnchorQueueProcessorResult.keetaAnchorQueueProcessorResultObjectTypeID,\n\t\t\tenumerable: false\n\t\t});\n\n\t\tthis.status = result.status;\n\t\tthis.output = result.output;\n\t\tthis.error = result.error;\n\t\tthis.cause = cause;\n\t}\n}\n\n// Ensure that KeetaAnchorQueueRunnerConfigurationObject has all the required properties of KeetaAnchorQueueRunner, and no extra properties\n// if this assertion fails, it means that KeetaAnchorQueueRunnerConfigurationObject is missing a property from KeetaAnchorQueueRunner or has an extra property\n// @ts-ignore\ntype __check_KeetaAnchorQueueRunnerConfigurationObject = Required<Pick<KeetaAnchorQueueRunner, 'maxRetries' | 'retryDelay' | 'stuckMultiplier' | 'batchSize' | 'processTimeout' | 'completedRetentionDays' | 'completedRetentionLimitPerRun'>>;\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype __check = AssertNever<__check_KeetaAnchorQueueRunnerConfigurationObject extends KeetaAnchorQueueRunnerConfigurationObject ? (KeetaAnchorQueueRunnerConfigurationObject extends __check_KeetaAnchorQueueRunnerConfigurationObject ? never : false) : false>;\n\n/*\n * Export all the error-typed classes as a single object so that they can\n * be imported.\n *\n * The KeetaAnchorQueueProcessorResult class is included here so downstream\n * code can use it to throw errors from the processor function and have them\n * handled correctly by the queue runner -- but it's not strictly an error\n * (hence not living in ./errors.ts)\n */\nconst AllErrors: typeof Errors & {\n\tKeetaAnchorQueueProcessorResult: typeof KeetaAnchorQueueProcessorResult;\n} = {\n\tKeetaAnchorQueueProcessorResult,\n\t...Errors\n}\n\n/**\n * A Queue Runner and Request Translator for processing entries in a queue\n *\n * The queue runner is responsible for pulling entries from the queue,\n * processing them, and updating their status in the queue. As well\n * as moving jobs between queues by piping the output of one runner\n * to another. Additionally, maintenance tasks such as re-queuing\n * failed jobs and marking stuck jobs are also handled by the runner.\n *\n * This is an abstract base class that must be extended to provide\n * the actual processing logic as well as the encoding and decoding\n * for requests and responses.\n */\nexport abstract class KeetaAnchorQueueRunner<UserRequest = unknown, UserResult = unknown, QueueRequest extends JSONSerializable = JSONSerializable, QueueResult extends JSONSerializable = JSONSerializable> {\n\t/**\n\t * Errors which may be thrown by the queue runner or processor\n\t */\n\tstatic readonly Errors: typeof AllErrors = AllErrors;\n\n\t/**\n\t * The queue this runner is responsible for running\n\t */\n\tprivate readonly queue: KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\t/**\n\t * The logger we should use for logging anything\n\t */\n\tprivate readonly logger?: Logger | undefined;\n\t/**\n\t * The processor function to use for processing entries\n\t */\n\tprotected abstract processor(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * The processor for stuck jobs (optional)\n\t */\n\tprotected processorStuck?(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * The processor for aborted jobs (optional)\n\t */\n\tprotected processorAborted?(entry: KeetaAnchorQueueEntry<UserRequest, UserResult>): Promise<KeetaAnchorQueueProcessorResultValue<UserResult>>;\n\n\t/**\n\t * Worker configuration\n\t */\n\tprivate readonly workers: NonNullable<KeetaAnchorQueueRunnerOptions['workers']>;\n\tprivate readonly workerID: KeetaAnchorQueueWorkerID;\n\n\t/**\n\t * Pipes to other runners we have registered\n\t */\n\tprivate readonly pipes: (\n\t\t// Non-Batch pipe -- depending on acceptStatus, either UserResult[] or UserRequest[]\n\t\t(\n\t\t\t({\n\t\t\t\tisBatchPipe: false;\n\t\t\t} & ({\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserResult, any, QueueResult, any>\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'completed'>;\n\t\t\t} | {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserRequest, any, QueueResult, any>\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'failed_permanently'>;\n\t\t\t})) |\n\n\t\t\t// Batch pipe -- depending on acceptStatus, either UserResult[] or UserRequest[]\n\t\t\t({\n\t\t\t\tisBatchPipe: true;\n\t\t\t\tminBatchSize: number;\n\t\t\t\tmaxBatchSize: number;\n\t\t\t} & ({\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserResult[], any, JSONSerializable, any>;\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'completed'>;\n\t\t\t} | {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t\ttarget: KeetaAnchorQueueRunner<UserRequest[], any, JSONSerializable, any>;\n\t\t\t\tacceptStatus: Extract<KeetaAnchorPipeableQueueStatus, 'failed_permanently'>;\n\t\t\t}))\n\t\t) & AdditionalPipeOptions\n\t)[] = [];\n\n\t/**\n\t * Runners that pipe into this runner\n\t */\n\tprivate incomingPipeCount = 0;\n\n\t/**\n\t * Initialization promise\n\t */\n\tprivate initializePromise: Promise<void> | undefined;\n\n\t/**\n\t * Configuration for this queue\n\t */\n\t/**\n\t * The maximum number of times to retry a failed job before giving up\n\t * and marking it as permanently failed\n\t */\n\tprotected maxRetries = 5;\n\t/**\n\t * The amount of time to allow a job to run before considering it\n\t * timed out and marking it as aborted, the `aborted` processor\n\t * (if provided) will be responsible for determining what to do with\n\t * the job at that point (e.g. retry it, mark it as failed, etc)\n\t * because some work from the job may have been completed\n\t * before the timeout was reached -- it could even still be on-going\n\t * after the timeout is reached, so the `aborted` processor should be\n\t * prepared to handle that situation as well.\n\t */\n\tprotected processTimeout = 300_000; /* 5 minutes */\n\t/**\n\t * The number of completed entries fetched per maintenance pass\n\t * when moving entries to the next stage. A full page means more\n\t * entries may be waiting behind it, so unmoved entries are sent\n\t * to the back of the line.\n\t */\n\tprivate readonly pipeMoveFetchLimit = 100;\n\t/**\n\t * When piping a batch of jobs to another runner, this is the number\n\t * of jobs to include in each batch (max).\n\t */\n\tprotected batchSize = 100;\n\n\t/**\n\t * The amount of time to wait before retrying a failed job -- this should\n\t * be long enough to allow any transient issues to be resolved (e.g. a downstream\n\t * service to come back up, etc) but not so long that it causes excessive\n\t * delays in processing.\n\t *\n\t * Keep in mind that after the {@link maxRetries} is reached, the job will\n\t * be marked as permanently failed, so if the retry delay is too low then\n\t * it could cause jobs to be marked as permanently failed before transient\n\t * issues have a chance to be resolved.\n\t */\n\tprotected get retryDelay(): number {\n\t\tif (this.internalRetryDelay !== undefined) {\n\t\t\treturn(this.internalRetryDelay);\n\t\t}\n\t\treturn(this.processTimeout * 10);\n\t}\n\n\tprotected set retryDelay(value: number) {\n\t\tthis.internalRetryDelay = value;\n\t}\n\n\tprivate internalRetryDelay?: number;\n\n\t/**\n\t * The number of {@link processTimeout} intervals to wait before\n\t * considering a job to be stuck -- this is for jobs that are\n\t * still in the 'processing' state but have not updated their\n\t * timestamp in a long time, which likely indicates that the worker\n\t * processing the job has died or is otherwise no longer making\n\t * progress on the job.\n\t *\n\t * Like the `aborted` status, the `stuck` status means the job is in\n\t * an indeterminate state where it may have done some of the work of\n\t * the processor but we don't know how much (if any) of it was\n\t * completed, so the `stuck` processor should be prepared to handle\n\t * that situation. It is unlikely that the job is still being actively\n\t * processed by a worker at this point, but it is possible, so the\n\t * `stuck` processor should be prepared to handle that as well.\n\t */\n\tprotected get stuckMultiplier(): number {\n\t\tif (this.internalStuckMultiplier !== undefined) {\n\t\t\treturn(this.internalStuckMultiplier);\n\t\t}\n\t\treturn(10);\n\t}\n\n\tprotected set stuckMultiplier(value: number) {\n\t\tthis.internalStuckMultiplier = value;\n\t}\n\n\tprivate internalStuckMultiplier?: number;\n\n\t/**\n\t * How many runners can process this queue in parallel\n\t */\n\tprotected maxRunners?: number;\n\n\t/**\n\t * How long to keep completed entries in the queue to avoid\n\t * re-using the same ID. A negative value means that completed\n\t * records will be immediately deleted.\n\t *\n\t * In units of days. Setting this to infinity will disable\n\t * cleanup.\n\t *\n\t * Default is 30 days.\n\t */\n\tprotected completedRetentionDays = 30;\n\n\t/**\n\t * How many completed entries to delete per maintain() call\n\t */\n\tprotected completedRetentionLimitPerRun = 5000;\n\n\t/**\n\t * A unique key to identify this runner for fencing the same worker\n\t * from running at the same time\n\t */\n\tprivate readonly runnerLockKey: KeetaAnchorQueueRequestID;\n\n\t/**\n\t * The ID of this runner for diagnostic purposes\n\t */\n\treadonly id: string;\n\n\tconstructor(config: { queue: KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>; } & KeetaAnchorQueueRunnerOptions) {\n\t\tthis.queue = config.queue;\n\t\tthis.logger = config.logger;\n\t\tthis.workers = config.workers ?? {\n\t\t\tcount: 1,\n\t\t\tid: 0\n\t\t};\n\n\t\tif (this.workers.id < 0) {\n\t\t\tthrow(new Error('Worker ID cannot be negative'));\n\t\t}\n\n\t\tif (this.maxRunners) {\n\t\t\tif (this.workers.id > this.maxRunners - 1 || this.workers.count > this.maxRunners) {\n\t\t\t\tthrow(new Error('Worker ID other than 0 or worker count other than 1 is not supported yet'));\n\t\t\t}\n\t\t}\n\n\t\t/*\n\t\t * The worker ID is just a branded version of the worker number\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\tthis.workerID = this.workers.id as KeetaAnchorQueueWorkerID;\n\n\t\t/*\n\t\t * The runner lock key, a unique key used to ensure only\n\t\t * one instance of a given runner is running at a time\n\t\t */\n\t\tthis.runnerLockKey = ConvertStringToRequestID(`@runner-lock:9ba756f0-7aa2-41c7-a1ea-b010dc752ae8.worker.${this.workerID}`);\n\n\t\t/**\n\t\t * Instance ID\n\t\t */\n\t\tthis.id = config.id ?? crypto.randomUUID();\n\n\t\tthis.methodLogger('new')?.debug('Created new queue runner attached to queue', this.queue.id);\n\t}\n\n\t/**\n\t * Helpful common handlers for the processorAborted and processorStuck methods\n\t */\n\tstatic processorHandlerHelpers: {\n\t\t/*\n\t\t * Because we are just passing the value through we do not\n\t\t * care about the type, we can handle any type because we\n\t\t * simply return the existing value\n\t\t */\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t[key in 'RETRY']: NonNullable<KeetaAnchorQueueRunner<unknown, any>['processorAborted']> | NonNullable<KeetaAnchorQueueRunner<unknown, any>['processorStuck']>;\n\t} = {\n\t\t\tRETRY: async (entry) => {\n\t\t\t\treturn({\n\t\t\t\t\tstatus: 'failed_temporarily',\n\t\t\t\t\t/*\n\t\t\t\t\t * This is safe because we are not\n\t\t\t\t\t * doing any operations on the value\n\t\t\t\t\t * and it just being copied over itself\n\t\t\t\t\t */\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\t\toutput: entry.output,\n\t\t\t\t\terror: `Job was ${entry.status} after ${entry.failures} failures, retrying`\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\tprivate async initialize(): Promise<void> {\n\t\tif (this.initializePromise) {\n\t\t\treturn(await this.initializePromise);\n\t\t}\n\n\t\t/* Ensure the sequential lock entry exists */\n\t\tthis.initializePromise = (async () => {\n\t\t\t/*\n\t\t\t * We store `null` as the request value because we\n\t\t\t * don't have anything better to store -- it's not\n\t\t\t * always going to be compatible with the type\n\t\t\t * QueueRequest but we know that we will never actually\n\t\t\t * use the value.\n\t\t\t */\n\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\tawait this.queue.add(null as unknown as QueueRequest, {\n\t\t\t\tid: this.runnerLockKey,\n\t\t\t\tstatus: '@internal'\n\t\t\t});\n\t\t})();\n\n\t\treturn(await this.initializePromise);\n\t}\n\n\tprotected setConfiguration(parameters: Partial<KeetaAnchorQueueRunnerConfigurationObject>): void {\n\t\tconst parameterNames = [ 'batchSize', 'maxRetries', 'processTimeout', 'retryDelay', 'stuckMultiplier', 'completedRetentionDays', 'completedRetentionLimitPerRun' ] as const satisfies (keyof typeof parameters)[];\n\t\t// Ensure that all keys in the config object are expected and used\n\t\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\t\ttype __checkAllExtensionConfigKeysAreValid = AssertNever<Exclude<keyof typeof parameters, typeof parameterNames[number]>>;\n\n\t\tfor (const parameterName of parameterNames) {\n\t\t\tconst value = parameters[parameterName];\n\t\t\tif (value === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tthis[parameterName] = value;\n\t\t}\n\t}\n\n\tprivate methodLogger(method: string): Logger | undefined {\n\t\treturn(MethodLogger(this.logger, {\n\t\t\tclass: 'KeetaAnchorQueueRunner',\n\t\t\tfile: 'src/lib/queue/index.ts',\n\t\t\tmethod: method,\n\t\t\tinstanceID: this.id\n\t\t}));\n\t}\n\n\t/** @internal */\n\t_Testing(key: string): {\n\t\tsetParams: (params: Partial<KeetaAnchorQueueRunnerConfigurationObject> & { maxRunners?: number; }) => void;\n\t\tqueue: () => KeetaAnchorQueueStorageDriver<QueueRequest, QueueResult>;\n\t\tmarkWorkerAsProcessing: () => Promise<void>;\n\t\tpipeMoveFetchLimit: number;\n\t} {\n\t\tif (key !== 'bc81abf8-e43b-490b-b486-744fb49a5082') {\n\t\t\tthrow(new Error('This is a testing only method'));\n\t\t}\n\n\t\treturn({\n\t\t\tsetParams: (params: Partial<KeetaAnchorQueueRunnerConfigurationObject> & { maxRunners?: number; }) => {\n\t\t\t\tconst { maxRunners, ...configParams } = params;\n\t\t\t\tthis.setConfiguration(configParams);\n\n\t\t\t\tif (maxRunners !== undefined) {\n\t\t\t\t\tthis.maxRunners = maxRunners;\n\t\t\t\t}\n\t\t\t},\n\t\t\tqueue: () => {\n\t\t\t\treturn(this.queue);\n\t\t\t},\n\t\t\tmarkWorkerAsProcessing: async () => {\n\t\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\t\toldStatus: '@internal',\n\t\t\t\t\tby: this.workerID\n\t\t\t\t});\n\t\t\t},\n\t\t\tpipeMoveFetchLimit: this.pipeMoveFetchLimit\n\t\t});\n\t}\n\n\tprotected abstract decodeRequest(request: QueueRequest): UserRequest;\n\tprotected abstract decodeResponse(response: QueueResult | null): UserResult | null;\n\n\tprotected abstract encodeRequest(request: UserRequest): QueueRequest;\n\tprotected abstract encodeResponse(response: UserResult | null): QueueResult | null;\n\n\tprotected decodeEntry(entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>): KeetaAnchorQueueEntry<UserRequest, UserResult> {\n\t\treturn({\n\t\t\t...entry,\n\t\t\trequest: this.decodeRequest(entry.request),\n\t\t\toutput: this.decodeResponse(entry.output)\n\t\t});\n\t}\n\n\t/**\n\t * Enqueue an item to be processed by the queue\n\t */\n\tasync add(request: UserRequest, info?: KeetaAnchorQueueEntryExtra): Promise<KeetaAnchorQueueRequestID> {\n\t\tawait this.initialize();\n\n\t\tconst encodedRequest = this.encodeRequest(request);\n\t\tconst newID = await this.queue.add(encodedRequest, info);\n\t\treturn(newID);\n\t}\n\n\t/**\n\t * Get a single entry from storage by ID\n\t */\n\tasync get(id: KeetaAnchorQueueRequestID): Promise<KeetaAnchorQueueEntry<UserRequest, UserResult> | null> {\n\t\tawait this.initialize();\n\n\t\tconst entry = await this.queue.get(id);\n\t\tif (!entry) {\n\t\t\treturn(null);\n\t\t}\n\n\t\treturn(this.decodeEntry(entry));\n\t}\n\n\t/**\n\t * Get entries from storage with an optional filter\n\t */\n\tasync query(filter?: KeetaAnchorQueueFilter): Promise<KeetaAnchorQueueEntry<UserRequest, UserResult>[]> {\n\t\tawait this.initialize();\n\n\t\tconst entries = await this.queue.query(filter);\n\t\treturn(entries.map((entry) => {\n\t\t\treturn(this.decodeEntry(entry));\n\t\t}));\n\t}\n\n\t/**\n\t * Set the status of an entry in the queue\n\t */\n\tasync setStatus(id: KeetaAnchorQueueRequestID, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<UserResult>): Promise<void> {\n\t\tawait this.initialize();\n\n\t\tlet encodedOutput: QueueResult | null | undefined = undefined;\n\t\tif (ancillary?.output !== undefined) {\n\t\t\tencodedOutput = this.encodeResponse(ancillary.output);\n\t\t}\n\n\t\treturn(await this.queue.setStatus(id, status, {\n\t\t\t...ancillary,\n\t\t\toutput: encodedOutput\n\t\t}));\n\t}\n\n\t/**\n\t * Checks to see if the queue is runnable\n\t */\n\tasync runnable(): Promise<boolean> {\n\t\tawait this.initialize();\n\n\t\tconst pendingEntries = await this.queue.query({ status: 'pending', limit: 1 });\n\t\tif (pendingEntries.length > 0) {\n\t\t\treturn(true);\n\t\t}\n\n\t\tfor (const pipe of this.pipes) {\n\t\t\tconst pipeRunnable = await pipe.target.runnable();\n\t\t\tif (pipeRunnable) {\n\t\t\t\treturn(true);\n\t\t\t}\n\t\t}\n\n\t\treturn(false);\n\t}\n\n\tprivate async updateRunnerLockTimestamp(): Promise<void> {\n\t\tconst logger = this.methodLogger('updateRunnerLockTimestamp');\n\n\t\ttry {\n\t\t\tlogger?.debug('Updating sequential processing lock timestamp for worker ID', this.workerID);\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\toldStatus: 'processing',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t\tlogger?.debug('Updated sequential processing lock timestamp for worker ID', this.workerID);\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.error('Failed to update sequential processing lock timestamp for worker ID', this.workerID, ':', error);\n\t\t\tthrow(error);\n\t\t}\n\t}\n\n\tprivate async getRunnerLock(cleanup: InstanceType<typeof AsyncDisposableStack>): Promise<boolean> {\n\t\tconst logger = this.methodLogger('getRunnerLock');\n\n\t\ttry {\n\t\t\tlogger?.debug('Acquiring sequential processing lock for worker ID', this.workerID);\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, 'processing', {\n\t\t\t\toldStatus: '@internal',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t\tlogger?.debug('Acquired sequential processing lock for worker ID', this.workerID);\n\t\t} catch (error: unknown) {\n\t\t\tif (Errors.IncorrectStateAssertedError.isInstance(error)) {\n\t\t\t\treturn(false);\n\t\t\t}\n\n\t\t\tthrow(error);\n\t\t}\n\n\t\tcleanup.defer(async () => {\n\t\t\tfor (let retry = 0; retry < 10; retry++) {\n\t\t\t\tlogger?.debug(`Releasing sequential processing lock try #${retry + 1} for worker ID`, this.workerID);\n\t\t\t\ttry {\n\t\t\t\t\tawait this.queue.setStatus(this.runnerLockKey, '@internal', {\n\t\t\t\t\t\toldStatus: 'processing',\n\t\t\t\t\t\tby: undefined\n\t\t\t\t\t});\n\t\t\t\t} catch {\n\t\t\t\t\tawait asleep(1000);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t});\n\n\t\treturn(true);\n\t}\n\n\tprivate async maintainRunnerLock(): Promise<void> {\n\t\tconst logger = this.methodLogger('maintainRunnerLock');\n\t\tconst moment = new Date();\n\t\tawait using cleanup = new AsyncDisposableStack();\n\n\t\tconst obtained = await this.getRunnerLock(cleanup);\n\t\tif (obtained) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Check to see if the lock is stale\n\t\t */\n\t\tconst lockEntry = await this.queue.get(this.runnerLockKey);\n\n\t\tif (!lockEntry) {\n\t\t\treturn;\n\t\t}\n\t\tconst lockAge = moment.getTime() - lockEntry.updated.getTime();\n\t\tif (lockAge > this.processTimeout * this.stuckMultiplier) {\n\t\t\tlogger?.warn('Processing lock is stale, taking over lock for worker ID', this.workerID);\n\n\t\t\tawait this.queue.setStatus(this.runnerLockKey, '@internal', {\n\t\t\t\toldStatus: 'processing',\n\t\t\t\tby: this.workerID\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Run the queue processor\n\t *\n\t * Processes up to `batchSize` entries from the queue and returns\n\t * true if there may be more work to do, or false if the queue\n\t * is empty.\n\t *\n\t * @param options Optional run options\n\t */\n\tasync run(options?: KeetaAnchorQueueRunOptions): Promise<boolean> {\n\t\tconst timeout = options?.timeoutMs;\n\n\t\tawait this.initialize();\n\n\t\tconst logger = this.methodLogger('run');\n\t\tconst batchSize = this.batchSize;\n\t\tconst processTimeout = this.processTimeout;\n\t\tawait using cleanup = new AsyncDisposableStack();\n\n\t\tlet retval = true;\n\n\t\tconst startTime = Date.now();\n\n\t\tconst locked = await this.getRunnerLock(cleanup);\n\t\tif (!locked) {\n\t\t\tlogger?.debug('Another worker is already processing the queue, skipping run');\n\n\t\t\treturn(true);\n\t\t}\n\n\t\tconst processJobOk = Symbol('processJobOk');\n\t\tconst processJobTimeout = Symbol('processJobTimeout');\n\t\tconst processJobContended = Symbol('processJobContended');\n\n\t\ttype EntryProcessor = (entry: KeetaAnchorQueueEntry<UserRequest, UserResult>) => Promise<{ status: KeetaAnchorQueueStatus; output: UserResult | null; error?: string | undefined; }>;\n\n\t\tconst processJob = async (index: number, entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>, startingStatus: KeetaAnchorQueueStatus, processor: EntryProcessor): Promise<typeof processJobTimeout | typeof processJobOk | typeof processJobContended> => {\n\t\t\tif (timeout !== undefined) {\n\t\t\t\tconst elapsed = Date.now() - startTime;\n\t\t\t\tif (elapsed >= timeout) {\n\t\t\t\t\tlogger?.debug(`Timeout of ${timeout}ms reached after processing ${index} entries (${startingStatus} phase; elapsed ${elapsed}ms)`);\n\n\t\t\t\t\treturn(processJobTimeout);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tawait this.updateRunnerLockTimestamp();\n\n\t\t\tlet setEntryStatus: { status: KeetaAnchorQueueStatus; output: UserResult | null; error?: string | undefined; } = { status: 'failed_temporarily', output: null };\n\n\t\t\tlogger?.debug(`Trying to acquire process lock for entry request with id ${String(entry.id)}`);\n\n\t\t\ttry {\n\t\t\t\t/*\n\t\t\t\t * Get a lock by setting it to 'processing'\n\t\t\t\t */\n\t\t\t\tawait this.queue.setStatus(entry.id, 'processing', { oldStatus: startingStatus, by: this.workerID });\n\n\t\t\t\t/*\n\t\t\t\t * Log an info-level log when we start and finish processing an entry\n\t\t\t\t */\n\t\t\t\tlogger?.info(`Processing entry request with id ${String(entry.id)}`);\n\n\t\t\t\t/*\n\t\t\t\t * Process the entry with a timeout, if the timeout is reached\n\t\t\t\t * we should mark the process as aborted because we no longer\n\t\t\t\t * know what state the work is in and someone will need to\n\t\t\t\t * inspect the job and determine through some other means if\n\t\t\t\t * it is completed or failed.\n\t\t\t\t */\n\t\t\t\tlet timeoutTimer: ReturnType<typeof setTimeout> | null = null;\n\t\t\t\tsetEntryStatus = await Promise.race([\n\t\t\t\t\tnew Promise<{ status: 'aborted', output: null }>(function(resolve) {\n\t\t\t\t\t\ttimeoutTimer = setTimeout(function() {\n\t\t\t\t\t\t\tresolve({ status: 'aborted', output: null });\n\t\t\t\t\t\t}, processTimeout);\n\t\t\t\t\t}),\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\treturn(await processor(this.decodeEntry(entry)));\n\t\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\t\tif (KeetaAnchorQueueProcessorResult.isInstance<UserResult>(error)) {\n\t\t\t\t\t\t\t\treturn({\n\t\t\t\t\t\t\t\t\tstatus: error.status,\n\t\t\t\t\t\t\t\t\toutput: error.output,\n\t\t\t\t\t\t\t\t\terror: error.error\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthrow(error);\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tif (timeoutTimer) {\n\t\t\t\t\t\t\t\tclearTimeout(timeoutTimer);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t})()\n\t\t\t\t]);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tif (Errors.IncorrectStateAssertedError.isInstance(error)) {\n\t\t\t\t\tlogger?.debug(`Skipping request with id ${String(entry.id)} because it is no longer in the expected state \"${startingStatus}\"`, error);\n\n\t\t\t\t\treturn(processJobContended);\n\t\t\t\t}\n\n\t\t\t\tlogger?.error(`Failed to process request with id ${String(entry.id)}, setting state to \"${setEntryStatus.status}\":`, error);\n\t\t\t\tsetEntryStatus.status = 'failed_temporarily';\n\t\t\t\tsetEntryStatus.error = String(error);\n\t\t\t}\n\n\t\t\tif (setEntryStatus.status === 'processing') {\n\t\t\t\tlogger?.error(`Processor for request with id ${String(entry.id)} returned invalid status \"processing\"`);\n\t\t\t\tsetEntryStatus.status = 'failed_temporarily';\n\t\t\t\tsetEntryStatus.error = 'Processor returned invalid status \"processing\"';\n\t\t\t}\n\n\t\t\tlet by: KeetaAnchorQueueWorkerID | undefined = this.workerID;\n\t\t\tif (setEntryStatus.status === 'pending') {\n\t\t\t\tby = undefined;\n\t\t\t}\n\n\t\t\tlogger?.info(`Finished processing entry request with id ${String(entry.id)} with new status`, setEntryStatus.status);\n\n\t\t\tawait this.queue.setStatus(entry.id, setEntryStatus.status, { oldStatus: 'processing', by: by, output: this.encodeResponse(setEntryStatus.output), error: setEntryStatus.error });\n\n\t\t\treturn(processJobOk);\n\t\t};\n\n\t\t/**\n\t\t * Process up to `batchSize` entries in the given status.\n\t\t *\n\t\t * Returns 'empty' when no entries are left in that status,\n\t\t * 'timeout' when the run timeout was reached, and 'more' when\n\t\t * the batch is used up and entries may remain.\n\t\t */\n\t\tconst processStatus = async (status: KeetaAnchorQueueStatus, processor: EntryProcessor): Promise<'empty' | 'timeout' | 'more'> => {\n\t\t\t/*\n\t\t\t * Losing an entry to another worker does not use up a\n\t\t\t * batch slot, but the retries are bounded so a run always\n\t\t\t * ends\n\t\t\t */\n\t\t\tlet contended = 0;\n\t\t\tlet processed = 0;\n\t\t\twhile (processed < batchSize) {\n\t\t\t\tconst entry = await this.nextEntryToProcess(status, processed + contended);\n\t\t\t\tif (entry === undefined) {\n\t\t\t\t\treturn('empty');\n\t\t\t\t}\n\n\t\t\t\tconst result = await processJob(processed, entry, status, processor);\n\t\t\t\tif (result === processJobTimeout) {\n\t\t\t\t\treturn('timeout');\n\t\t\t\t}\n\n\t\t\t\tif (result === processJobContended && contended < batchSize) {\n\t\t\t\t\tcontended++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tprocessed++;\n\t\t\t}\n\n\t\t\treturn('more');\n\t\t};\n\n\t\t/*\n\t\t * Process pending jobs first\n\t\t */\n\t\tconst pendingResult = await processStatus('pending', this.processor.bind(this));\n\t\tif (pendingResult === 'empty') {\n\t\t\tretval = false;\n\t\t}\n\n\t\t/*\n\t\t * Next process any pipes to other runners\n\t\t */\n\t\tconst pipes = [...this.pipes];\n\t\tfor (const pipe of pipes) {\n\t\t\tif (pipe.exclusiveTarget === false) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlet remainingTime: number | undefined = undefined;\n\t\t\tif (timeout !== undefined) {\n\t\t\t\tconst elapsed = Date.now() - startTime;\n\t\t\t\tremainingTime = timeout - elapsed;\n\t\t\t\tif (remainingTime <= 0) {\n\t\t\t\t\tremainingTime = -1;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst pipeHasMoreWork = await pipe.target.run({\n\t\t\t\t...options,\n\t\t\t\ttimeoutMs: remainingTime\n\t\t\t});\n\n\t\t\tif (pipeHasMoreWork) {\n\t\t\t\tretval = true;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Process stuck or aborted jobs (if possible)\n\t\t */\n\t\tconst conditions = [{\n\t\t\tstatus: 'aborted' as const,\n\t\t\tprocessor: this.processorAborted?.bind(this)\n\t\t}, {\n\t\t\tstatus: 'stuck' as const,\n\t\t\tprocessor: this.processorStuck?.bind(this)\n\t\t}];\n\n\t\tfor (const condition of conditions) {\n\t\t\tif (condition.processor === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst conditionResult = await processStatus(condition.status, condition.processor);\n\t\t\tif (conditionResult === 'timeout') {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\n\t\treturn(retval);\n\t}\n\n\t/**\n\t * Pick the next entry in the given status for this worker to try.\n\t *\n\t * query() returns the oldest entries first, so if every worker\n\t * took the first one they would all race for the same entry and\n\t * all but one would lose it. Instead each worker looks at the\n\t * oldest `workers.count` entries and takes the one at its worker\n\t * ID plus `attempt`, so concurrent workers start on different\n\t * entries. Adding the attempt number rotates the slot within a\n\t * run, so every worker reaches the oldest entry within\n\t * `workers.count` attempts even when some worker IDs are not\n\t * running. With a single worker this is simply the oldest entry.\n\t *\n\t * @param status The status to pick an entry from\n\t * @param attempt How many entries this run has already tried in\n\t * that status\n\t */\n\tprivate async nextEntryToProcess(status: KeetaAnchorQueueStatus, attempt: number): Promise<KeetaAnchorQueueEntry<QueueRequest, QueueResult> | undefined> {\n\t\tconst candidates = await this.queue.query({ status: status, limit: Math.max(1, this.workers.count) });\n\t\tif (candidates.length === 0) {\n\t\t\treturn(undefined);\n\t\t}\n\n\t\treturn(candidates[(this.workers.id + attempt) % candidates.length]);\n\t}\n\n\tprivate async markStuckRequestsAsStuck(): Promise<void> {\n\t\tconst stuckThreshold = this.processTimeout * this.stuckMultiplier;\n\n\t\tconst logger = this.methodLogger('markStuckRequestsAsStuck');\n\t\tconst now = Date.now();\n\n\t\tconst requests = await this.queue.query({ status: 'processing', limit: 100, updatedBefore: new Date(now - stuckThreshold) });\n\t\tfor (const request of requests) {\n\t\t\t/*\n\t\t\t * Skip the runner lock entries, they are managed separately\n\t\t\t */\n\t\t\tif (request.id.toString().startsWith('@runner-lock:9ba756f0-7aa2-41c7-a1ea-b010dc752ae8.worker.')) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tlogger?.warn(`Marking request with id ${String(request.id)} as stuck`);\n\n\t\t\t\tawait this.queue.setStatus(request.id, 'stuck', { oldStatus: 'processing', by: this.workerID });\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.error(`Failed to mark request with id ${String(request.id)} as stuck:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async requeueFailedRequests(): Promise<void> {\n\t\tconst retryDelay = this.retryDelay;\n\t\tconst maxRetries = this.maxRetries;\n\n\t\tconst logger = this.methodLogger('requeueFailedRequests');\n\t\tconst now = Date.now();\n\n\t\tconst requests = await this.queue.query({ status: 'failed_temporarily', limit: 100, updatedBefore: new Date(now - retryDelay) });\n\t\tfor (const request of requests) {\n\t\t\ttry {\n\t\t\t\tif (request.failures >= maxRetries) {\n\t\t\t\t\tlogger?.info(`Request with id ${String(request.id)} has exceeded maximum retries, not requeuing -- moving to failed_permanently`);\n\t\t\t\t\tawait this.queue.setStatus(request.id, 'failed_permanently', { oldStatus: 'failed_temporarily', by: this.workerID });\n\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tlogger?.debug(`Requeuing failed request with id ${String(request.id)}`);\n\n\t\t\t\tawait this.queue.setStatus(request.id, 'pending', { oldStatus: 'failed_temporarily', by: this.workerID });\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.error(`Failed to requeue request with id ${String(request.id)}:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate async moveCompletedToNextStage(statusTarget: KeetaAnchorPipeableQueueStatus): Promise<void> {\n\t\tconst logger = this.methodLogger('moveCompletedToNextStage');\n\n\t\tconst pipes = [...this.pipes].filter(function(pipe) {\n\t\t\treturn(pipe.acceptStatus === statusTarget);\n\t\t});\n\n\t\tif (pipes.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst fetchLimit = this.pipeMoveFetchLimit;\n\t\tconst allRequests = await this.queue.query({ status: statusTarget, limit: fetchLimit });\n\t\tlet requests = allRequests;\n\n\t\tconst RequestSentToPipes = new Map<KeetaAnchorQueueRequestID, number>();\n\t\tfunction IncrRequestSentToPipes(requestID: KeetaAnchorQueueRequestID): void {\n\t\t\tconst sentCount = RequestSentToPipes.get(requestID) ?? 0;\n\t\t\tRequestSentToPipes.set(requestID, sentCount + 1);\n\t\t}\n\n\t\tconst getNextPipeRequestInput = (entry: KeetaAnchorQueueEntry<QueueRequest, QueueResult>) => {\n\t\t\tif (statusTarget === 'completed') {\n\t\t\t\treturn(this.decodeResponse(entry.output));\n\t\t\t} else if (statusTarget === 'failed_permanently') {\n\t\t\t\treturn(this.decodeRequest(entry.request));\n\t\t\t}\n\n\t\t\tassertNever(statusTarget);\n\t\t};\n\n\t\tfor (const pipe of pipes) {\n\t\t\tlogger?.debug('Processing pipe to target', pipe.target.id, pipe.isBatchPipe ? '(batch pipe)' : '(single item pipe)');\n\n\t\t\tif (pipe.isBatchPipe) {\n\t\t\t\t/**\n\t\t\t\t * Keep track of all the requests we successfully\n\t\t\t\t * sent to the target stage\n\t\t\t\t */\n\t\t\t\tconst allTargetSeenRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * During each iteration of the batch processing, we keep track\n\t\t\t\t * of the IDs we have already seen by the target and processed\n\t\t\t\t * so we don't try to reprocess them again\n\t\t\t\t */\n\t\t\t\tconst iterationTargetSeenRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * If we get a batch that cannot be added to the target pipe,\n\t\t\t\t * we just skip over them for retrying at a later date\n\t\t\t\t */\n\t\t\t\tconst skipRequestIDs = new Set<KeetaAnchorQueueRequestID>();\n\n\t\t\t\t/**\n\t\t\t\t * Compute a durable ID for this batch and target\n\t\t\t\t */\n\t\t\t\tlet batchID = ConvertStringToRequestID(crypto.randomUUID());\n\n\t\t\t\t/**\n\t\t\t\t * Keep track of sequential failures to find enough entries\n\t\t\t\t * and stop processing if we can't find enough after a few tries\n\t\t\t\t * in a row\n\t\t\t\t */\n\t\t\t\tlet sequentialFailureCount = 0;\n\n\t\t\t\tfor (;requests.length >= pipe.minBatchSize;\n\t\t\t\t\t/*\n\t\t\t\t\t * Remove any entries we have already seen during\n\t\t\t\t\t * the last iteration of the loop\n\t\t\t\t\t */\n\t\t\t\t\trequests = requests.filter(function(entry) {\n\t\t\t\t\t\treturn(!iterationTargetSeenRequestIDs.has(entry.id) && !skipRequestIDs.has(entry.id));\n\t\t\t\t\t})\n\t\t\t\t) {\n\t\t\t\t\titerationTargetSeenRequestIDs.clear();\n\n\t\t\t\t\tlogger?.debug(`Preparing to move ${statusTarget} requests to next stage ${pipe.target.id} (min=${pipe.minBatchSize}, max=${pipe.maxBatchSize}), have ${requests.length} ${statusTarget} requests available`);\n\n\t\t\t\t\t/**\n\t\t\t\t\t * Compute a batch of entries to send to the next stage,\n\t\t\t\t\t * constrained to the max batch size of the pipe and\n\t\t\t\t\t * the entries which have non-null outputs\n\t\t\t\t\t */\n\t\t\t\t\tconst batchRaw = requests.map((entry) => {\n\t\t\t\t\t\treturn({ output: getNextPipeRequestInput(entry), id: entry.id });\n\t\t\t\t\t}).filter(function(entry): entry is { output: UserRequest | UserResult; id: KeetaAnchorQueueRequestID; } {\n\t\t\t\t\t\tif (entry === null) {\n\t\t\t\t\t\t\treturn(false);\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn(true);\n\t\t\t\t\t}).slice(0, pipe.maxBatchSize);\n\n\t\t\t\t\t/*\n\t\t\t\t\t * If we don't have enough entries to meet the minimum\n\t\t\t\t\t * batch size, skip this iteration\n\t\t\t\t\t */\n\t\t\t\t\tif (batchRaw.length < pipe.minBatchSize) {\n\t\t\t\t\t\tsequentialFailureCount++;\n\t\t\t\t\t\tif (sequentialFailureCount >= 3) {\n\t\t\t\t\t\t\tlogger?.debug(`Not enough ${statusTarget} requests to move to next stage ${pipe.target.id}, stopping batch processing`);\n\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlogger?.debug(`Not moving ${statusTarget} requests to next stage ${pipe.target.id} because batch size ${batchRaw.length} is less than minimum size ${pipe.minBatchSize}`);\n\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tsequentialFailureCount = 0;\n\n\t\t\t\t\t/**\n\t\t\t\t\t * The IDs for the entries we are sending to the next stage\n\t\t\t\t\t * target -- this may get reduced if we find there are already\n\t\t\t\t\t * jobs in the next stage that have the idempotentIDs of one of\n\t\t\t\t\t * these jobs\n\t\t\t\t\t */\n\t\t\t\t\tconst batchLocalIDs = new Set(batchRaw.map(function(entry) {\n\t\t\t\t\t\treturn(entry.id);\n\t\t\t\t\t}));\n\t\t\t\t\t/**\n\t\t\t\t\t * The outputs for the batch we are sending to the next stage\n\t\t\t\t\t */\n\t\t\t\t\tconst batchOutput = batchRaw.map(function(entry) {\n\t\t\t\t\t\treturn(entry.output);\n\t\t\t\t\t});\n\n\t\t\t\t\tlogger?.debug(`Moving batch of ${batchOutput.length} ${statusTarget} requests to next pipe`, pipe.target.id, '(input entry IDs:', Array.from(batchLocalIDs), '->', `${pipe.target.id}:${String(batchID)})`);\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// There is no way for typescript to cleanly infer the type here, so we assert it.\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\t\tawait pipe.target.add(batchOutput as (UserRequest & UserResult)[], {\n\t\t\t\t\t\t\tid: batchID,\n\t\t\t\t\t\t\t/* Use the set of IDs as the idempotent IDs for the batch */\n\t\t\t\t\t\t\tidempotentKeys: batchLocalIDs\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tbatchID = ConvertStringToRequestID(crypto.randomUUID());\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tif (Errors.IdempotentExistsError.isInstance(error) && error.idempotentIDsFound) {\n\t\t\t\t\t\t\tlogger?.debug('Some of the jobs have already been added to the target queue, skipping those:', error.idempotentIDsFound.values());\n\t\t\t\t\t\t\tfor (const requestID of error.idempotentIDsFound) {\n\t\t\t\t\t\t\t\titerationTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\t\t\tallTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t/*\n\t\t\t\t\t\t\t * If we got some kind of other error adding these\n\t\t\t\t\t\t\t * items to the target queue runner, just skip them\n\t\t\t\t\t\t\t * and we will retry them on the next iteration\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tlogger?.error(`Failed to move completed batch to next stage ${pipe.target.id}, will try to create another batch without them:`, error);\n\n\t\t\t\t\t\t\tfor (const requestID of batchLocalIDs) {\n\t\t\t\t\t\t\t\tskipRequestIDs.add(requestID);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (const requestID of batchLocalIDs) {\n\t\t\t\t\t\titerationTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t\tallTargetSeenRequestIDs.add(requestID);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/*\n\t\t\t\t * For every request we know the target has definitely seen, mark it\n\t\t\t\t * as moved for this pipe\n\t\t\t\t */\n\t\t\t\tfor (const requestID of allTargetSeenRequestIDs) {\n\t\t\t\t\tIncrRequestSentToPipes(requestID);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor (const request of requests) {\n\t\t\t\t\tlet shouldMarkAsMoved = true;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst output = getNextPipeRequestInput(request);\n\n\t\t\t\t\t\tif (output === null) {\n\t\t\t\t\t\t\tlogger?.debug(`Completed request with id ${String(request.id)} has no output -- next stage will not be run`);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tlogger?.debug(`Moving ${statusTarget} request with id ${String(request.id)} to next pipe`, pipe.target.id);\n\t\t\t\t\t\t\t// There is no way for typescript to cleanly infer the type here, so we assert it.\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\t\t\t\t\t\tawait pipe.target.add(output as UserRequest & UserResult, { id: request.id });\n\t\t\t\t\t\t}\n\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tlogger?.error(`Failed to move completed request with id ${String(request.id)} to next stage:`, error);\n\t\t\t\t\t\tshouldMarkAsMoved = false;\n\t\t\t\t\t}\n\t\t\t\t\tif (shouldMarkAsMoved) {\n\t\t\t\t\t\tIncrRequestSentToPipes(request.id);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst unmovedRequests: typeof allRequests = [];\n\n\t\tconst TotalPipes = pipes.length;\n\t\tfor (const request of allRequests) {\n\t\t\tconst sentCount = RequestSentToPipes.get(request.id) ?? 0;\n\t\t\tif (sentCount !== TotalPipes) {\n\t\t\t\tlogger?.debug(`${statusTarget} request with id ${String(request.id)} was only moved to ${sentCount} out of ${TotalPipes} pipes -- not marking as moved`);\n\n\t\t\t\tunmovedRequests.push(request);\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tlogger?.debug(`Marking ${statusTarget} request with id ${String(request.id)} as moved`);\n\n\t\t\tawait this.queue.setStatus(request.id, 'moved', { oldStatus: statusTarget, by: this.workerID });\n\t\t}\n\n\t\t/*\n\t\t * If we fetched a full page, there may be more entries behind\n\t\t * the ones we could not move. Since query() returns the oldest\n\t\t * updated entries first, the same entries would be fetched again\n\t\t * on the next pass and block everything behind them, so touch\n\t\t * each one we could not move to send it to the back of the line.\n\t\t *\n\t\t * Touching resets \"updated\", which completed-entry retention\n\t\t * also reads; that is safe only because retention is skipped\n\t\t * for any queue with pipes (see deleteExpiredCompleted). The\n\t\t * original worker is kept so the entry still records who\n\t\t * processed it.\n\t\t */\n\t\tif (allRequests.length >= fetchLimit) {\n\t\t\tawait this.sendToBackOfLine(unmovedRequests, statusTarget);\n\t\t}\n\t}\n\n\t/**\n\t * Send entries to the back of the line by setting each to the\n\t * status it already has, which bumps \"updated\" and keeps the\n\t * worker that processed it. Another worker may have changed an\n\t * entry since it was fetched, so a failure is logged and skipped.\n\t */\n\tprivate async sendToBackOfLine(requests: KeetaAnchorQueueEntry<QueueRequest, QueueResult>[], status: KeetaAnchorQueueStatus): Promise<void> {\n\t\tconst logger = this.methodLogger('sendToBackOfLine');\n\n\t\tfor (const request of requests) {\n\t\t\tlet worker: KeetaAnchorQueueWorkerID | undefined = undefined;\n\t\t\tif (request.worker !== null) {\n\t\t\t\tworker = request.worker;\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait this.queue.setStatus(request.id, status, { oldStatus: status, by: worker });\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to move ${status} request with id ${String(request.id)} to the back of the line:`, error);\n\t\t\t}\n\t\t}\n\t}\n\n\tasync maintain(): Promise<void> {\n\t\tconst logger = this.methodLogger('maintain');\n\n\t\tawait this.initialize();\n\n\t\t/*\n\t\t * Call `maintainRunnerLock` for every worker ID (not just 0)\n\t\t * so that we can ensure the runner lock is maintained and not\n\t\t * stale as part of maintain()\n\t\t */\n\t\ttry {\n\t\t\tawait this.maintainRunnerLock();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to maintain runner lock:', error);\n\t\t}\n\n\t\t/*\n\t\t * Only the worker with ID 0 should the rest of the maintenance tasks\n\t\t * so that we don't have multiple workers trying to do the same\n\t\t * maintenance tasks at the same time on the same queues\n\t\t */\n\t\tif (this.workers.id !== 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tlogger?.debug(`Worker ID ${this.workerID} beginning maintenance tasks for queue ${this.queue.id}`);\n\n\t\ttry {\n\t\t\tawait this.markStuckRequestsAsStuck();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to mark stuck requests as stuck:', error);\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.requeueFailedRequests();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to requeue failed requests:', error);\n\t\t}\n\n\t\ttry {\n\t\t\tawait this.deleteExpiredCompleted();\n\t\t} catch (error: unknown) {\n\t\t\tlogger?.debug('Failed to delete expired completed requests:', error);\n\t\t}\n\n\t\tfor (const pipeStatus of keetaAnchorPipeableQueueStatuses) {\n\t\t\ttry {\n\t\t\t\tawait this.moveCompletedToNextStage(pipeStatus);\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to move ${pipeStatus} requests to next stage:`, error);\n\t\t\t}\n\t\t}\n\n\t\tfor (const pipe of this.pipes) {\n\t\t\ttry {\n\t\t\t\tif (pipe.exclusiveTarget === false) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tawait pipe.target.maintain();\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to maintain piped runner with ID ${pipe.target.id}:`, error);\n\t\t\t}\n\t\t}\n\n\t\tif (this.queue.maintain) {\n\t\t\ttry {\n\t\t\t\tawait this.queue.maintain();\n\t\t\t} catch (error: unknown) {\n\t\t\t\tlogger?.debug(`Failed to maintain queue storage driver with ID ${this.queue.id}`, error);\n\t\t\t}\n\t\t}\n\n\t\tlogger?.debug(`Worker ID ${this.workerID} completed maintenance tasks for queue ${this.queue.id}`);\n\t}\n\n\tprivate async deleteExpiredCompleted(): Promise<void> {\n\t\tif (this.completedRetentionDays === Infinity) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.pipes.length > 0 || this.incomingPipeCount > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst filter: KeetaAnchorQueueFilter = {\n\t\t\tstatus: 'completed',\n\t\t\tlimit: this.completedRetentionLimitPerRun\n\t\t};\n\n\t\tif (this.completedRetentionDays > 0) {\n\t\t\tfilter.updatedBefore = new Date(Date.now() - this.completedRetentionDays * 86_400_000);\n\t\t}\n\n\t\tconst entries = await this.queue.query(filter);\n\n\t\tif (entries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tawait this.queue.delete(entries.map(function(entry) {\n\t\t\treturn({\n\t\t\t\tid: entry.id,\n\t\t\t\tstatus: entry.status\n\t\t\t});\n\t\t}));\n\t}\n\n\t/**\n\t * Pipe the the completed entries of this runner to another runner\n\t */\n\tpipe<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserResult, T1, QueueResult, T2>, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: false,\n\t\t\ttarget: target,\n\t\t\tacceptStatus: 'completed'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tpipeFailed<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserRequest, T1, QueueResult, T2>, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: false,\n\t\t\ttarget: target,\n\t\t\tacceptStatus: 'failed_permanently'\n\t\t});\n\t\treturn(target);\n\t}\n\n\t/**\n\t * Pipe batches of completed entries from this runner to another runner\n\t */\n\tpipeBatch<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserResult[], T1, JSONSerializable, T2>, maxBatchSize = 100, minBatchSize = 1, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: true,\n\t\t\ttarget: target,\n\t\t\tminBatchSize: minBatchSize,\n\t\t\tmaxBatchSize: maxBatchSize,\n\t\t\tacceptStatus: 'completed'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tpipeBatchFailed<T1, T2 extends JSONSerializable>(target: KeetaAnchorQueueRunner<UserRequest[], T1, JSONSerializable, T2>, maxBatchSize = 100, minBatchSize = 1, options?: AdditionalPipeOptions): typeof target {\n\t\ttarget.incomingPipeCount++;\n\t\tthis.pipes.push({\n\t\t\t...options,\n\t\t\tisBatchPipe: true,\n\t\t\ttarget: target,\n\t\t\tminBatchSize: minBatchSize,\n\t\t\tmaxBatchSize: maxBatchSize,\n\t\t\tacceptStatus: 'failed_permanently'\n\t\t});\n\t\treturn(target);\n\t}\n\n\tasync destroy(): Promise<void> {\n\t\tthis.methodLogger('destroy')?.debug('Destroying queue runner attached to queue', this.queue.id);\n\t}\n\n\tasync [Symbol.asyncDispose](): Promise<void> {\n\t\tawait this.destroy();\n\t}\n}\n\n/**\n * A KeetaAnchorQueueRunner for use when you want to process already\n * JSON-serializable data without any encoding/decoding needed\n */\nexport abstract class KeetaAnchorQueueRunnerJSON<UserRequest extends JSONSerializable = JSONSerializable, UserResult extends JSONSerializable = JSONSerializable> extends KeetaAnchorQueueRunner<UserRequest, UserResult, JSONSerializable, JSONSerializable> {\n\tprotected decodeRequest(request: JSONSerializable): UserRequest {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(request as UserRequest);\n\t}\n\n\tprotected decodeResponse(response: JSONSerializable | null): UserResult | null {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(response as UserResult | null);\n\t}\n\n\tprotected encodeRequest(request: JSONSerializable): JSONSerializable {\n\t\treturn(request);\n\t}\n\n\tprotected encodeResponse(response: JSONSerializable | null): JSONSerializable | null {\n\t\treturn(response);\n\t}\n}\n\n/**\n * A KeetaAnchorQueueRunnerJSON that takes a processor function\n * in the constructor -- this is mainly useful for testing\n */\nexport class KeetaAnchorQueueRunnerJSONConfigProc<UserRequest extends JSONSerializable = JSONSerializable, UserResult extends JSONSerializable = JSONSerializable> extends KeetaAnchorQueueRunnerJSON<UserRequest, UserResult> {\n\tprotected readonly processor: KeetaAnchorQueueRunner<UserRequest, UserResult>['processor'];\n\n\tconstructor(config: ConstructorParameters<typeof KeetaAnchorQueueRunner>[0] & {\n\t\tprocessor: KeetaAnchorQueueRunner<UserRequest, UserResult>['processor'];\n\t\tprocessorStuck?: KeetaAnchorQueueRunner<UserRequest, UserResult>['processorStuck'] | keyof typeof KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers | undefined;\n\t\tprocessorAborted?: KeetaAnchorQueueRunner<UserRequest, UserResult>['processorAborted'] | keyof typeof KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers | undefined;\n\t} & Partial<KeetaAnchorQueueRunnerConfigurationObject>) {\n\t\tsuper(config);\n\n\t\tconst { processor, processorStuck, processorAborted, ...parameters } = config;\n\n\t\tthis.processor = processor;\n\n\t\tif (processorStuck) {\n\t\t\tif (typeof processorStuck === 'string') {\n\t\t\t\tthis.processorStuck = KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers[processorStuck];\n\t\t\t} else {\n\t\t\t\tthis.processorStuck = processorStuck;\n\t\t\t}\n\t\t}\n\t\tif (processorAborted) {\n\t\t\tif (typeof processorAborted === 'string') {\n\t\t\t\tthis.processorAborted = KeetaAnchorQueueRunnerJSONConfigProc.processorHandlerHelpers[processorAborted];\n\t\t\t} else {\n\t\t\t\tthis.processorAborted = processorAborted;\n\t\t\t}\n\t\t}\n\n\t\tthis.setConfiguration(parameters);\n\t}\n}\n\nexport { AllErrors as Errors };\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ntype _ignore_static_assert_memory = AssertNever<typeof KeetaAnchorQueueStorageDriverMemory<{ a: string; }, number> extends KeetaAnchorQueueStorageDriverConstructor<{ a: string; }, number> ? never : false>;\n"]}
|
package/lib/queue/internal.d.ts
CHANGED
|
@@ -16,5 +16,12 @@ export declare function ManageStatusUpdates<QueueResult>(id: KeetaAnchorQueueReq
|
|
|
16
16
|
*/
|
|
17
17
|
export declare function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID): KeetaAnchorQueueRequestID;
|
|
18
18
|
export declare function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID | undefined): KeetaAnchorQueueRequestID | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Compare two queue entries by the order that
|
|
21
|
+
* `KeetaAnchorQueueStorageDriver.query()` must return them in: oldest
|
|
22
|
+
* "updated" first. Use with a stable sort so that ties keep their
|
|
23
|
+
* existing (insertion) order.
|
|
24
|
+
*/
|
|
25
|
+
export declare function CompareQueueEntryOrder(a: Pick<KeetaAnchorQueueEntry<unknown, unknown>, 'updated'>, b: Pick<KeetaAnchorQueueEntry<unknown, unknown>, 'updated'>): number;
|
|
19
26
|
export {};
|
|
20
27
|
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/lib/queue/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EACX,qBAAqB,EACrB,kCAAkC,EAClC,yBAAyB,EACzB,sBAAsB,EACtB,MAAM,YAAY,CAAC;AAIpB,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;CAAE,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,SAAS,CA2BtL;AAED,KAAK,kBAAkB,CAAC,WAAW,IAAI,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,WAAW,GAAG,UAAU,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE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,GAAG,QAAQ,CAAC,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC,CAAC;AAC5N,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,EAAE,EAAE,yBAAyB,EAAE,aAAa,EAAE,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC,EAAE,MAAM,EAAE,sBAAsB,EAAE,SAAS,CAAC,EAAE,kCAAkC,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAoCtT;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,GAAG,yBAAyB,CAAC;AAC/G,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,yBAAyB,GAAG,SAAS,GAAG,yBAAyB,GAAG,SAAS,CAAC;AAUvI;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,CAEvK"}
|
package/lib/queue/internal.js
CHANGED
|
@@ -63,4 +63,13 @@ export function ConvertStringToRequestID(input) {
|
|
|
63
63
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
64
64
|
return input;
|
|
65
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Compare two queue entries by the order that
|
|
68
|
+
* `KeetaAnchorQueueStorageDriver.query()` must return them in: oldest
|
|
69
|
+
* "updated" first. Use with a stable sort so that ties keep their
|
|
70
|
+
* existing (insertion) order.
|
|
71
|
+
*/
|
|
72
|
+
export function CompareQueueEntryOrder(a, b) {
|
|
73
|
+
return (a.updated.getTime() - b.updated.getTime());
|
|
74
|
+
}
|
|
66
75
|
//# sourceMappingURL=internal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/lib/queue/internal.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,0CAA0C;AAC1C,MAAM,UAAU,YAAY,CAA+B,KAAQ,EAAE,IAA0E;IAC9I,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,yEAAyE;QACzE,OAAO,SAAmD,CAAC;IAC5D,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/F,MAAM,MAAM,GAAW;QACtB,KAAK,EAAE,UAAS,GAAG,OAAkB;YACpC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,EAAE,UAAS,GAAG,OAAkB;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,UAAS,GAAG,OAAkB;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,KAAK,EAAE,UAAS,GAAG,OAAkB;YACpC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,GAAG,EAAE,UAAS,GAAG,OAAkB;YAClC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QAChC,CAAC;KACD,CAAC;IAEF,yEAAyE;IACzE,OAAO,MAAgD,CA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0CAA0C,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5F,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,EAAE,KAAK,CAAC,sCAAsC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED,OAAM,CAAC,MAAM,CAAC,CAAC;AAChB,CAAC;AAUD,MAAM,UAAU,wBAAwB,CAAC,KAAqD;IAC7F,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAM,CAAC,SAAS,CAAC,CAAC;IACnB,CAAC;IAED,yEAAyE;IACzE,OAAO,KAAmC,CAAC;AAC5C,CAAC","sourcesContent":["import type { Logger } from '../log/index.ts';\nimport type {\n\tKeetaAnchorQueueEntry,\n\tKeetaAnchorQueueEntryAncillaryData,\n\tKeetaAnchorQueueRequestID,\n\tKeetaAnchorQueueStatus\n} from './index.ts';\nimport { Errors } from './common.js';\n\n/* XXX: Move this somewhere more common */\nexport function MethodLogger<T extends Logger | undefined>(input: T, from: { file: string; method: string; class: string; instanceID: string; }): T extends Logger ? Logger : undefined {\n\tif (input === undefined) {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(undefined as T extends Logger ? Logger : undefined);\n\t}\n\n\tconst fromStr = `${from.class}${from.instanceID ? `:${from.instanceID}` : ''}::${from.method}`;\n\tconst retval: Logger = {\n\t\tdebug: function(...logArgs: unknown[]): void {\n\t\t\tinput.debug(fromStr, ...logArgs);\n\t\t},\n\t\tinfo: function(...logArgs: unknown[]): void {\n\t\t\tinput.info(fromStr, ...logArgs);\n\t\t},\n\t\twarn: function(...logArgs: unknown[]): void {\n\t\t\tinput.warn(fromStr, ...logArgs);\n\t\t},\n\t\terror: function(...logArgs: unknown[]): void {\n\t\t\tinput.error(fromStr, ...logArgs);\n\t\t},\n\t\tlog: function(...logArgs: unknown[]): void {\n\t\t\tinput.log(fromStr, ...logArgs);\n\t\t}\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(retval as T extends Logger ? Logger : undefined);\n}\n\ntype StatusUpdateResult<QueueResult> = Pick<Partial<KeetaAnchorQueueEntry<unknown, QueueResult>>, 'lastError' | 'failures' | 'output'> & Pick<KeetaAnchorQueueEntry<unknown, QueueResult>, 'status' | 'worker' | 'updated'>;\nexport function ManageStatusUpdates<QueueResult>(id: KeetaAnchorQueueRequestID, existingEntry: Pick<KeetaAnchorQueueEntry<unknown, QueueResult>, 'status' | 'failures'>, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>, logger?: Logger): StatusUpdateResult<QueueResult> {\n\tconst retval: StatusUpdateResult<QueueResult> = {\n\t\tstatus: status,\n\t\tworker: ancillary?.by ?? null,\n\t\tupdated: new Date()\n\t};\n\n\tconst { oldStatus, output } = ancillary ?? {};\n\tif (oldStatus && existingEntry.status !== oldStatus) {\n\t\tthrow(new Errors.IncorrectStateAssertedError(id, oldStatus, existingEntry.status));\n\t}\n\n\tlogger?.debug(`Setting request with id ${String(id)} status from \"${existingEntry.status}\" to \"${status}\"`);\n\n\tif (status === 'failed_temporarily') {\n\t\tconst existingFailures = existingEntry.failures;\n\t\tretval.failures = existingFailures + 1;\n\t\tlogger?.debug(`Incrementing failure count for request with id ${String(id)} to ${retval.failures}`);\n\t}\n\n\tif (status === 'pending' || status === 'completed') {\n\t\tlogger?.debug(`Clearing last error for request with id ${String(id)}`);\n\t\tretval.lastError = null;\n\t}\n\n\tif (ancillary?.error) {\n\t\tretval.lastError = ancillary.error;\n\t\tlogger?.debug(`Setting last error for request with id ${String(id)} to:`, ancillary.error);\n\t}\n\n\tif (output !== undefined) {\n\t\tretval.output = output;\n\t\tlogger?.debug(`Setting output for request with id ${String(id)} to:`, output);\n\t}\n\n\treturn(retval);\n}\n\n/**\n * Convert a string to a KeetaAnchorQueueRequestID (branded string type)\n *\n * Use only when appropriate, such as when receiving a request ID from an\n * external source or generating a new one.\n */\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID): KeetaAnchorQueueRequestID;\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID | undefined): KeetaAnchorQueueRequestID | undefined;\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID | undefined): KeetaAnchorQueueRequestID | undefined {\n\tif (input === undefined) {\n\t\treturn(undefined);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(input as KeetaAnchorQueueRequestID);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/lib/queue/internal.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,0CAA0C;AAC1C,MAAM,UAAU,YAAY,CAA+B,KAAQ,EAAE,IAA0E;IAC9I,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,yEAAyE;QACzE,OAAO,SAAmD,CAAC;IAC5D,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/F,MAAM,MAAM,GAAW;QACtB,KAAK,EAAE,UAAS,GAAG,OAAkB;YACpC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,EAAE,UAAS,GAAG,OAAkB;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,IAAI,EAAE,UAAS,GAAG,OAAkB;YACnC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO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AAS,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;QACpD,MAAM,EAAE,KAAK,CAAC,2CAA2C,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACvE,MAAM,CAAC,SAAS,GAAG,IAAI,CAAC;IACzB,CAAC;IAED,IAAI,SAAS,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,CAAC,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC;QACnC,MAAM,EAAE,KAAK,CAAC,0CAA0C,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IAC5F,CAAC;IAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,EAAE,KAAK,CAAC,sCAAsC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/E,CAAC;IAED,OAAM,CAAC,MAAM,CAAC,CAAC;AAChB,CAAC;AAUD,MAAM,UAAU,wBAAwB,CAAC,KAAqD;IAC7F,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,OAAM,CAAC,SAAS,CAAC,CAAC;IACnB,CAAC;IAED,yEAAyE;IACzE,OAAO,KAAmC,CAAC;AAC5C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,CAA2D,EAAE,CAA2D;IAC9J,OAAM,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { Logger } from '../log/index.ts';\nimport type {\n\tKeetaAnchorQueueEntry,\n\tKeetaAnchorQueueEntryAncillaryData,\n\tKeetaAnchorQueueRequestID,\n\tKeetaAnchorQueueStatus\n} from './index.ts';\nimport { Errors } from './common.js';\n\n/* XXX: Move this somewhere more common */\nexport function MethodLogger<T extends Logger | undefined>(input: T, from: { file: string; method: string; class: string; instanceID: string; }): T extends Logger ? Logger : undefined {\n\tif (input === undefined) {\n\t\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\t\treturn(undefined as T extends Logger ? Logger : undefined);\n\t}\n\n\tconst fromStr = `${from.class}${from.instanceID ? `:${from.instanceID}` : ''}::${from.method}`;\n\tconst retval: Logger = {\n\t\tdebug: function(...logArgs: unknown[]): void {\n\t\t\tinput.debug(fromStr, ...logArgs);\n\t\t},\n\t\tinfo: function(...logArgs: unknown[]): void {\n\t\t\tinput.info(fromStr, ...logArgs);\n\t\t},\n\t\twarn: function(...logArgs: unknown[]): void {\n\t\t\tinput.warn(fromStr, ...logArgs);\n\t\t},\n\t\terror: function(...logArgs: unknown[]): void {\n\t\t\tinput.error(fromStr, ...logArgs);\n\t\t},\n\t\tlog: function(...logArgs: unknown[]): void {\n\t\t\tinput.log(fromStr, ...logArgs);\n\t\t}\n\t};\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(retval as T extends Logger ? Logger : undefined);\n}\n\ntype StatusUpdateResult<QueueResult> = Pick<Partial<KeetaAnchorQueueEntry<unknown, QueueResult>>, 'lastError' | 'failures' | 'output'> & Pick<KeetaAnchorQueueEntry<unknown, QueueResult>, 'status' | 'worker' | 'updated'>;\nexport function ManageStatusUpdates<QueueResult>(id: KeetaAnchorQueueRequestID, existingEntry: Pick<KeetaAnchorQueueEntry<unknown, QueueResult>, 'status' | 'failures'>, status: KeetaAnchorQueueStatus, ancillary?: KeetaAnchorQueueEntryAncillaryData<QueueResult>, logger?: Logger): StatusUpdateResult<QueueResult> {\n\tconst retval: StatusUpdateResult<QueueResult> = {\n\t\tstatus: status,\n\t\tworker: ancillary?.by ?? null,\n\t\tupdated: new Date()\n\t};\n\n\tconst { oldStatus, output } = ancillary ?? {};\n\tif (oldStatus && existingEntry.status !== oldStatus) {\n\t\tthrow(new Errors.IncorrectStateAssertedError(id, oldStatus, existingEntry.status));\n\t}\n\n\tlogger?.debug(`Setting request with id ${String(id)} status from \"${existingEntry.status}\" to \"${status}\"`);\n\n\tif (status === 'failed_temporarily') {\n\t\tconst existingFailures = existingEntry.failures;\n\t\tretval.failures = existingFailures + 1;\n\t\tlogger?.debug(`Incrementing failure count for request with id ${String(id)} to ${retval.failures}`);\n\t}\n\n\tif (status === 'pending' || status === 'completed') {\n\t\tlogger?.debug(`Clearing last error for request with id ${String(id)}`);\n\t\tretval.lastError = null;\n\t}\n\n\tif (ancillary?.error) {\n\t\tretval.lastError = ancillary.error;\n\t\tlogger?.debug(`Setting last error for request with id ${String(id)} to:`, ancillary.error);\n\t}\n\n\tif (output !== undefined) {\n\t\tretval.output = output;\n\t\tlogger?.debug(`Setting output for request with id ${String(id)} to:`, output);\n\t}\n\n\treturn(retval);\n}\n\n/**\n * Convert a string to a KeetaAnchorQueueRequestID (branded string type)\n *\n * Use only when appropriate, such as when receiving a request ID from an\n * external source or generating a new one.\n */\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID): KeetaAnchorQueueRequestID;\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID | undefined): KeetaAnchorQueueRequestID | undefined;\nexport function ConvertStringToRequestID(input: string | KeetaAnchorQueueRequestID | undefined): KeetaAnchorQueueRequestID | undefined {\n\tif (input === undefined) {\n\t\treturn(undefined);\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions\n\treturn(input as KeetaAnchorQueueRequestID);\n}\n\n/**\n * Compare two queue entries by the order that\n * `KeetaAnchorQueueStorageDriver.query()` must return them in: oldest\n * \"updated\" first. Use with a stable sort so that ties keep their\n * existing (insertion) order.\n */\nexport function CompareQueueEntryOrder(a: Pick<KeetaAnchorQueueEntry<unknown, unknown>, 'updated'>, b: Pick<KeetaAnchorQueueEntry<unknown, unknown>, 'updated'>): number {\n\treturn(a.updated.getTime() - b.updated.getTime());\n}\n"]}
|