[Fleet] Fix updating task interval for agent log usage (#148635)

This commit is contained in:
Nicolas Chaulet 2023-01-10 10:00:34 -04:00 committed by GitHub
parent b437fd54b8
commit 7d2428430d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,12 +56,25 @@ export async function startFleetUsageLogger(taskManager: TaskManagerStartContrac
if (!isInfoLogLevelEnabled) {
return;
}
appContextService.getLogger().info(`Task ${TASK_ID} scheduled with interval 5m`);
const interval = isDebugLogLevelEnabled ? '5m' : '15m';
// Re-schedule the task if interval changed
const task = await taskManager?.get(TASK_ID).catch((err) => {
if (err.output.statusCode === 404) {
return null;
}
throw err;
});
if (task?.schedule?.interval !== interval) {
await taskManager?.removeIfExists(TASK_ID);
}
appContextService.getLogger().info(`Task ${TASK_ID} scheduled with interval ${interval}`);
await taskManager?.ensureScheduled({
id: TASK_ID,
taskType: TASK_TYPE,
schedule: {
interval: isDebugLogLevelEnabled ? '5m' : '15m',
interval,
},
scope: ['fleet'],
state: {},