UNPKG

@sidequest/engine

Version:

@sidequest/engine is the core engine of SideQuest, a distributed background job processing system for Node.js and TypeScript.

49 lines (46 loc) 2.14 kB
import { logger } from '@sidequest/core'; /** * Determines if a new queue configuration differs from the existing queue configuration. * * Compares the provided queue data against the current queue configuration to detect * any changes in concurrency, state, or priority properties. Only checks properties * that are defined (truthy) in the new queue data. * * @param queue - The new queue data to compare against the existing configuration * @param queueConfig - The current queue configuration to compare against * @returns `true` if any of the defined properties in the new queue data differ from * the corresponding properties in the existing configuration, `false` otherwise */ function differentQueueConfig(queue, queueConfig) { return ((!!queue.concurrency && queue.concurrency !== queueConfig.concurrency) || (!!queue.state && queue.state !== queueConfig.state) || (!!queue.priority && queue.priority !== queueConfig.priority)); } /** * Ensures a queue configuration exists, creating it if necessary. * @param queue The name of the queue. * @param config Optional configuration for the new queue. * @param defaults Optional default values for the queue. * @param forceUpdate If true, updates the queue configuration even if it already exists. * @returns The queue configuration. */ async function grantQueueConfig(backend, queue, defaults, forceUpdate = false) { const queueConfig = await backend?.getQueue(queue.name); if (queueConfig) { if (forceUpdate && differentQueueConfig(queue, queueConfig)) { logger("Engine").warn(`Queue config for ${queue.name} exists but differs from the provided configuration. Updating...`); return await backend.updateQueue({ ...queueConfig, ...queue }); } else { return queueConfig; } } const newConfig = { ...defaults, ...queue, }; logger("Engine").info(`Creating queue config for ${queue.name}`); return backend?.createNewQueue(newConfig); } export { differentQueueConfig, grantQueueConfig }; //# sourceMappingURL=grant-queue-config.js.map