-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Add rrule schema to task schedule with intermediate release #219429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ersin-erdal
merged 23 commits into
elastic:main
from
ersin-erdal:216308-add-rrule-to-task-model-versions
May 2, 2025
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2cf3878
Add rrule schema to task schedule with intermediate release
ersin-erdal dacbfc6
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine c5069c7
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 38bffd6
modify schema and remove mappings
ersin-erdal f846dbc
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal d24788c
fix mappings_addition
ersin-erdal 4d30c93
remove mappings from the packages
ersin-erdal 6ca6280
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 6b2e3ef
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine a1b4481
remove rrule mapping
ersin-erdal be48567
fix interval mapping
ersin-erdal 40c26ab
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 4478f57
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine c57f65e
align rrule validation with the ones in alerting
ersin-erdal 768160a
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal 622cbc0
Merge branch 'main' into 216308-add-rrule-to-task-model-versions
ersin-erdal 66b6bfc
remove dynamic:false
ersin-erdal 39b9d76
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal 73f1df1
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 8aea7eb
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 9563728
add schema.maybe(
ersin-erdal ae0e29d
Merge branch '216308-add-rrule-to-task-model-versions' of github.com:…
ersin-erdal b970cc2
revert schema.maybe
ersin-erdal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
98 changes: 98 additions & 0 deletions
98
x-pack/platform/plugins/shared/task_manager/server/saved_objects/schemas/rrule.ts
This file contains hidden or 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,98 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { schema } from '@kbn/config-schema'; | ||
| import { Frequency } from '@kbn/rrule'; | ||
| import moment from 'moment-timezone'; | ||
|
|
||
| function validateTimezone(timezone: string) { | ||
| if (moment.tz.zone(timezone) != null) { | ||
| return; | ||
| } | ||
|
|
||
| return 'string is not a valid timezone: ' + timezone; | ||
| } | ||
|
|
||
| const validateRecurrenceByWeekday = (array: string[]) => { | ||
| if (array.length === 0) { | ||
| return 'rRule byweekday cannot be empty'; | ||
| } | ||
|
|
||
| const byWeekDayRegex = new RegExp('^(((\\+|-)[1-4])?(MO|TU|WE|TH|FR|SA|SU))$'); | ||
| const invalidDays: string[] = []; | ||
|
|
||
| array.forEach((day) => { | ||
| if (!byWeekDayRegex.test(day)) { | ||
| invalidDays.push(day); | ||
| } | ||
| }); | ||
|
|
||
| if (invalidDays.length > 0) { | ||
| return `invalid byweekday values in rRule byweekday: ${invalidDays.join(',')}`; | ||
| } | ||
| }; | ||
|
|
||
| const rruleCommon = schema.object({ | ||
| freq: schema.maybe( | ||
| schema.oneOf([ | ||
| schema.literal(0), | ||
| schema.literal(1), | ||
| schema.literal(2), | ||
| schema.literal(3), | ||
| schema.literal(4), | ||
| schema.literal(5), | ||
| schema.literal(6), | ||
| ]) | ||
| ), | ||
| interval: schema.maybe( | ||
| schema.number({ | ||
| validate: (interval: number) => { | ||
| if (!Number.isInteger(interval)) { | ||
| return 'rRule interval must be an integer greater than 0'; | ||
| } | ||
| }, | ||
| min: 1, | ||
| }) | ||
| ), | ||
| tzid: schema.string({ validate: validateTimezone, defaultValue: 'UTC' }), | ||
| }); | ||
|
|
||
| const byminute = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 59 }), { minSize: 1 })); | ||
| const byhour = schema.maybe(schema.arrayOf(schema.number({ min: 0, max: 23 }), { minSize: 1 })); | ||
| const byweekday = schema.maybe( | ||
| schema.arrayOf(schema.string(), { | ||
| minSize: 1, | ||
| validate: validateRecurrenceByWeekday, | ||
| }) | ||
| ); | ||
| const bymonthday = schema.maybe(schema.arrayOf(schema.number({ min: 1, max: 31 }), { minSize: 1 })); | ||
|
|
||
| const rruleMonthly = rruleCommon.extends({ | ||
| freq: schema.literal(Frequency.MONTHLY), | ||
| byhour, | ||
| byminute, | ||
| byweekday, | ||
| bymonthday, | ||
| }); | ||
|
|
||
| const rruleWeekly = rruleCommon.extends({ | ||
| freq: schema.literal(Frequency.WEEKLY), | ||
| byhour, | ||
| byminute, | ||
| byweekday, | ||
| bymonthday: schema.never(), | ||
| }); | ||
|
|
||
| const rruleDaily = rruleCommon.extends({ | ||
| freq: schema.literal(Frequency.DAILY), | ||
| byhour, | ||
| byminute, | ||
| byweekday, | ||
| bymonthday: schema.never(), | ||
| }); | ||
|
|
||
| export const rruleSchedule = schema.oneOf([rruleMonthly, rruleWeekly, rruleDaily]); | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about having one schema and do
feq: schema.oneOf[schema.literal(Frequency.DAILY), schema.literal(Frequency.WEEKLY), schema.literal(Frequency.MONTHLY].There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I grouped them because some configurations should not be used with some frequency types, it looks the same for now but when we add hourly and minutely we will not allow byweekday and byhour together as they break the library.