UNPKG

@puls-atlas/cli

Version:

The Puls Atlas CLI tool for managing Atlas projects

31 lines 1.91 kB
import { normalizeOptionalString } from '../../../utils/value.js'; import { SEARCH_SOURCE_RUNNER_JOB_NAME } from '../resourceNames.js'; import { PULS_ATLAS_SEARCH_SOURCE_NAME_ENV } from '../runtimeEnv.js'; const DEFAULT_SEARCH_SOURCE_SCHEDULER_TIME_ZONE = 'Etc/UTC'; const toSchedulerSlug = value => String(value).trim().toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/-+/g, '-').replace(/^-+|-+$/g, ''); const truncateSchedulerName = value => value.slice(0, 63).replace(/-+$/g, ''); export const SEARCH_SOURCE_RUNNER_REQUESTED_SOURCE_ENV = PULS_ATLAS_SEARCH_SOURCE_NAME_ENV; export const createSearchSourceSchedulerJobName = (sourceName, namePrefix = 'atlas-search') => { const slug = toSchedulerSlug(sourceName) || 'source'; const normalizedNamePrefix = toSchedulerSlug(namePrefix) || 'atlas-search'; return truncateSchedulerName(`${normalizedNamePrefix}-${slug}-schedule`); }; export const getEnabledScheduledSearchSourcePlans = searchConfig => { const indexes = searchConfig?.indexes ?? {}; const sources = searchConfig?.sources ?? {}; return Object.entries(sources).filter(([, sourceConfig]) => sourceConfig?.enabled !== false).map(([sourceName, sourceConfig]) => ({ schedule: normalizeOptionalString(sourceConfig?.schedule), schedulerJobName: createSearchSourceSchedulerJobName(sourceName), sourceName, timeZone: DEFAULT_SEARCH_SOURCE_SCHEDULER_TIME_ZONE, validIndexNames: (sourceConfig?.indexes ?? []).filter(indexName => indexes[indexName]) })).filter(sourcePlan => sourcePlan.schedule !== null && sourcePlan.validIndexNames.length > 0); }; export const hasScheduledSearchSources = searchConfig => getEnabledScheduledSearchSourcePlans(searchConfig).length > 0; export default { SEARCH_SOURCE_RUNNER_JOB_NAME, SEARCH_SOURCE_RUNNER_REQUESTED_SOURCE_ENV, createSearchSourceSchedulerJobName, getEnabledScheduledSearchSourcePlans, hasScheduledSearchSources };