/* * @adonisjs/queue * * (c) AdonisJS * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ import type { ApplicationService } from '@adonisjs/core/types' import type { AdapterFactory, JobFactory, QueueConfig } from './types/main.js' /** * Resolve adapter factories from config providers. * * Adapters in the config can be either: * - Direct factory functions * - ConfigProvider objects that need to be resolved * * This function normalizes them all to factory functions. */ export async function resolveAdapters( config: QueueConfig, app: ApplicationService ): Promise> { const resolvedAdapters: Record = {} for (const [name, adapterConfig] of Object.entries(config.adapters)) { if (typeof adapterConfig === 'function') { resolvedAdapters[name] = adapterConfig as AdapterFactory } else { resolvedAdapters[name] = await adapterConfig.resolver(app) } } return resolvedAdapters } export function resolveJobFactory(config: QueueConfig, app: ApplicationService): JobFactory { return config.jobFactory ?? ((jobClass: any) => app.container.make(jobClass)) } /** * Jobs reload on every execution when the process runs under Hot Hook, * as with `node ace serve --hmr` or `node ace queue:work --hmr`. The * `hotReload` config option takes precedence. */ export function resolveHotReload(config: QueueConfig): boolean { return config.hotReload ?? (import.meta as ImportMeta & { hot?: object }).hot !== undefined }