-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves Task manager's interval under a generic schedule field (#52727)
This moves the interval field under a generic schedule object field in preparation for the introduction of richer scheduling options (such as cron). It includes a migration for existing tasks, and we've ensured no existing Task Type Definitions exist in Kibana that rely on Interval. This includes support for the deprecated interval field (which gets mapped to schedule) but that support will be removed in 8.0.0, as it's a breaking change.
- Loading branch information
Showing
16 changed files
with
271 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
x-pack/legacy/plugins/task_manager/lib/correct_deprecated_fields.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ensureDeprecatedFieldsAreCorrected } from './correct_deprecated_fields'; | ||
import { mockLogger } from '../test_utils'; | ||
|
||
describe('ensureDeprecatedFieldsAreCorrected', () => { | ||
test('doesnt change tasks without any schedule fields', async () => { | ||
expect( | ||
ensureDeprecatedFieldsAreCorrected( | ||
{ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
params: {}, | ||
state: {}, | ||
}, | ||
mockLogger() | ||
) | ||
).toEqual({ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
params: {}, | ||
state: {}, | ||
}); | ||
}); | ||
test('doesnt change tasks with the schedule field', async () => { | ||
expect( | ||
ensureDeprecatedFieldsAreCorrected( | ||
{ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
schedule: { interval: '10m' }, | ||
params: {}, | ||
state: {}, | ||
}, | ||
mockLogger() | ||
) | ||
).toEqual({ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
schedule: { interval: '10m' }, | ||
params: {}, | ||
state: {}, | ||
}); | ||
}); | ||
test('corrects tasks with the deprecated inteval field', async () => { | ||
expect( | ||
ensureDeprecatedFieldsAreCorrected( | ||
{ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
interval: '10m', | ||
params: {}, | ||
state: {}, | ||
}, | ||
mockLogger() | ||
) | ||
).toEqual({ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
schedule: { interval: '10m' }, | ||
params: {}, | ||
state: {}, | ||
}); | ||
}); | ||
test('logs a warning when a deprecated inteval is corrected on a task', async () => { | ||
const logger = mockLogger(); | ||
ensureDeprecatedFieldsAreCorrected( | ||
{ | ||
taskType: 'foo', | ||
interval: '10m', | ||
params: {}, | ||
state: {}, | ||
}, | ||
logger | ||
); | ||
expect(logger.warn).toHaveBeenCalledWith( | ||
`Task of type "foo" has been scheduled with the deprecated 'interval' field which is due to be removed in a future release` | ||
); | ||
}); | ||
test('logs a warning when a deprecated inteval is corrected on a task with an id', async () => { | ||
const logger = mockLogger(); | ||
ensureDeprecatedFieldsAreCorrected( | ||
{ | ||
id: 'my-foo-id', | ||
taskType: 'foo', | ||
interval: '10m', | ||
params: {}, | ||
state: {}, | ||
}, | ||
logger | ||
); | ||
expect(logger.warn).toHaveBeenCalledWith( | ||
`Task "my-foo-id" of type "foo" has been scheduled with the deprecated 'interval' field which is due to be removed in a future release` | ||
); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
x-pack/legacy/plugins/task_manager/lib/correct_deprecated_fields.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TaskInstance, TaskInstanceWithDeprecatedFields } from '../task'; | ||
import { Logger } from '../types'; | ||
|
||
export function ensureDeprecatedFieldsAreCorrected( | ||
{ id, taskType, interval, schedule, ...taskInstance }: TaskInstanceWithDeprecatedFields, | ||
logger: Logger | ||
): TaskInstance { | ||
if (interval) { | ||
logger.warn( | ||
`Task${ | ||
id ? ` "${id}"` : '' | ||
} of type "${taskType}" has been scheduled with the deprecated 'interval' field which is due to be removed in a future release` | ||
); | ||
} | ||
return { | ||
id, | ||
taskType, | ||
...taskInstance, | ||
schedule: schedule || (interval ? { interval } : undefined), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.