diff --git a/docs/features/search/how-to-guides.md b/docs/features/search/how-to-guides.md index da94bd4ca4..161ff6844c 100644 --- a/docs/features/search/how-to-guides.md +++ b/docs/features/search/how-to-guides.md @@ -385,21 +385,15 @@ import { searchModuleCatalogCollator } from '@backstage/plugin-search-backend-mo import { searchModuleTechDocsCollator } from '@backstage/plugin-search-backend-module-techdocs/alpha'; import { searchModuleExploreCollator } from '@backstage/plugin-search-backend-module-explore/alpha'; -const schedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, -}; - const backend = createBackend(); // adding the search plugin to the backend backend.add(searchPlugin()); // (optional) the default search engine is Lunr, if you want to extend the search backend with another search engine. backend.add(searchModuleElasticsearchEngine()); -// extending search with collator modules to start index documents -backend.add(searchModuleCatalogCollator({ schedule })); -backend.add(searchModuleTechDocsCollator({ schedule })); -backend.add(searchModuleExploreCollator({ schedule })); +// extending search with collator modules to start index documents, take in optional schedule parameters. +backend.add(searchModuleCatalogCollator()); +backend.add(searchModuleTechDocsCollator()); +backend.add(searchModuleExploreCollator()); backend.start(); ``` diff --git a/packages/backend-next/src/index.ts b/packages/backend-next/src/index.ts index 231343203a..e3cbbd53b8 100644 --- a/packages/backend-next/src/index.ts +++ b/packages/backend-next/src/index.ts @@ -40,14 +40,9 @@ backend.add(catalogPlugin()); backend.add(catalogModuleTemplateKind()); // Search -const schedule = { - frequency: { minutes: 10 }, - timeout: { minutes: 15 }, - initialDelay: { seconds: 3 }, -}; backend.add(searchPlugin()); -backend.add(searchModuleCatalogCollator({ schedule })); -backend.add(searchModuleTechDocsCollator({ schedule })); -backend.add(searchModuleExploreCollator({ schedule })); +backend.add(searchModuleCatalogCollator()); +backend.add(searchModuleTechDocsCollator()); +backend.add(searchModuleExploreCollator()); backend.start(); diff --git a/plugins/search-backend-module-catalog/src/alpha.ts b/plugins/search-backend-module-catalog/src/alpha.ts index d4530b582b..89c7479035 100644 --- a/plugins/search-backend-module-catalog/src/alpha.ts +++ b/plugins/search-backend-module-catalog/src/alpha.ts @@ -46,7 +46,7 @@ export type SearchModuleCatalogCollatorOptions = Omit< DefaultCatalogCollatorFactoryOptions, 'discovery' | 'tokenManager' > & { - schedule: TaskScheduleDefinition; + schedule?: TaskScheduleDefinition; }; /** @@ -54,7 +54,7 @@ export type SearchModuleCatalogCollatorOptions = Omit< * Search backend module for the Catalog index. */ export const searchModuleCatalogCollator = createBackendModule( - (options: SearchModuleCatalogCollatorOptions) => ({ + (options?: SearchModuleCatalogCollatorOptions) => ({ moduleId: 'catalogCollator', pluginId: 'search', register(env) { @@ -73,12 +73,18 @@ export const searchModuleCatalogCollator = createBackendModule( scheduler, indexRegistry, }) { - const { schedule, ...rest } = options; + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner(schedule), + schedule: scheduler.createScheduledTaskRunner( + options?.schedule ?? defaultSchedule, + ), factory: DefaultCatalogCollatorFactory.fromConfig(config, { - ...rest, + ...options, discovery, tokenManager, }), diff --git a/plugins/search-backend-module-explore/src/alpha.ts b/plugins/search-backend-module-explore/src/alpha.ts index 357bb4233e..01303db631 100644 --- a/plugins/search-backend-module-explore/src/alpha.ts +++ b/plugins/search-backend-module-explore/src/alpha.ts @@ -47,7 +47,7 @@ export type SearchModuleExploreCollatorOptions = Omit< ToolDocumentCollatorFactoryOptions, 'logger' | 'discovery' > & { - schedule: TaskScheduleDefinition; + schedule?: TaskScheduleDefinition; }; /** @@ -55,7 +55,7 @@ export type SearchModuleExploreCollatorOptions = Omit< * Search backend module for the Explore index. */ export const searchModuleExploreCollator = createBackendModule( - (options: SearchModuleExploreCollatorOptions) => ({ + (options?: SearchModuleExploreCollatorOptions) => ({ moduleId: 'exploreCollator', pluginId: 'search', register(env) { @@ -68,12 +68,18 @@ export const searchModuleExploreCollator = createBackendModule( indexRegistry: searchIndexRegistryExtensionPoint, }, async init({ config, logger, discovery, scheduler, indexRegistry }) { - const { schedule, ...rest } = options; + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner(schedule), + schedule: scheduler.createScheduledTaskRunner( + options?.schedule ?? defaultSchedule, + ), factory: ToolDocumentCollatorFactory.fromConfig(config, { - ...rest, + ...options, discovery, logger: loggerToWinstonLogger(logger), }), diff --git a/plugins/search-backend-module-techdocs/src/alpha.ts b/plugins/search-backend-module-techdocs/src/alpha.ts index f58c439c80..c781ad40ca 100644 --- a/plugins/search-backend-module-techdocs/src/alpha.ts +++ b/plugins/search-backend-module-techdocs/src/alpha.ts @@ -42,7 +42,7 @@ export type SearchModuleTechDocsCollatorOptions = Omit< TechDocsCollatorFactoryOptions, 'logger' | 'discovery' | 'tokenManager' > & { - schedule: TaskScheduleDefinition; + schedule?: TaskScheduleDefinition; }; /** @@ -50,7 +50,7 @@ export type SearchModuleTechDocsCollatorOptions = Omit< * Search backend module for the TechDocs index. */ export const searchModuleTechDocsCollator = createBackendModule( - (options: SearchModuleTechDocsCollatorOptions) => ({ + (options?: SearchModuleTechDocsCollatorOptions) => ({ moduleId: 'techDocsCollator', pluginId: 'search', register(env) { @@ -71,12 +71,18 @@ export const searchModuleTechDocsCollator = createBackendModule( scheduler, indexRegistry, }) { - const { schedule, ...rest } = options; + const defaultSchedule = { + frequency: { minutes: 10 }, + timeout: { minutes: 15 }, + initialDelay: { seconds: 3 }, + }; indexRegistry.addCollator({ - schedule: scheduler.createScheduledTaskRunner(schedule), + schedule: scheduler.createScheduledTaskRunner( + options?.schedule ?? defaultSchedule, + ), factory: DefaultTechDocsCollatorFactory.fromConfig(config, { - ...rest, + ...options, discovery, tokenManager, logger: loggerToWinstonLogger(logger),