diff --git a/x-pack/plugins/task_manager/server/lib/set_claim_strategy.test.ts b/x-pack/plugins/task_manager/server/lib/set_claim_strategy.test.ts index 993693c6ba5ab..805a5f05b0440 100644 --- a/x-pack/plugins/task_manager/server/lib/set_claim_strategy.test.ts +++ b/x-pack/plugins/task_manager/server/lib/set_claim_strategy.test.ts @@ -151,6 +151,22 @@ describe('setClaimStrategy', () => { expect(logger.info).not.toHaveBeenCalled(); }); + test(`should honor config-provided poll_interval`, () => { + const config = { ...getConfigWithoutClaimStrategy(), poll_interval: 120000 }; + const returnedConfig = setClaimStrategy({ + config, + logger, + isCloud: false, + isElasticStaffOwned: false, + isServerless: false, + }); + + expect(returnedConfig.claim_strategy).toBe(CLAIM_STRATEGY_UPDATE_BY_QUERY); + expect(returnedConfig.poll_interval).toBe(120000); + + expect(logger.info).not.toHaveBeenCalled(); + }); + test(`should set claim strategy to update_by_query if cloud and not serverless with undefined deploymentId`, () => { const config = getConfigWithoutClaimStrategy(); const returnedConfig = setClaimStrategy({ diff --git a/x-pack/plugins/task_manager/server/lib/set_claim_strategy.ts b/x-pack/plugins/task_manager/server/lib/set_claim_strategy.ts index 9ff24ad67a963..ad4d36ea530cd 100644 --- a/x-pack/plugins/task_manager/server/lib/set_claim_strategy.ts +++ b/x-pack/plugins/task_manager/server/lib/set_claim_strategy.ts @@ -68,13 +68,32 @@ export function setClaimStrategy(opts: SetClaimStrategyOpts): TaskManagerConfig return { ...opts.config, claim_strategy: CLAIM_STRATEGY_MGET, - poll_interval: MGET_DEFAULT_POLL_INTERVAL, + poll_interval: maybeSetDefaultInterval(opts.config, MGET_DEFAULT_POLL_INTERVAL), }; } return { ...opts.config, claim_strategy: CLAIM_STRATEGY_UPDATE_BY_QUERY, - poll_interval: DEFAULT_POLL_INTERVAL, + poll_interval: maybeSetDefaultInterval(opts.config, DEFAULT_POLL_INTERVAL), }; } + +/** + * If the poll interval is not overridden by the user, return the specified default. + * + * @param config Current config + * @param defaultPollInterval Default to set + */ +function maybeSetDefaultInterval(config: TaskManagerConfig, defaultPollInterval: number) { + if (config.claim_strategy) { + return config.poll_interval; + } + + // Our default when there's no claim_strategy is DEFAULT_POLL_INTERVAL + if (config.poll_interval === DEFAULT_POLL_INTERVAL) { + return defaultPollInterval; + } + + return config.poll_interval; +}