-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(scheduler): start and end time for schedule construct #28306
Changes from 10 commits
8acc52a
883ba81
a8c0232
ac47212
cece795
029d40b
ac5c8d2
16d0f02
8cc2d91
e6c41fa
e17d2b6
e037852
53bba92
380f428
a56f918
2f12a18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -138,6 +138,21 @@ new Schedule(this, 'Schedule', { | |||||
}); | ||||||
``` | ||||||
|
||||||
### Configuring a start and end time of the Schedule | ||||||
|
||||||
If you choose a recurring schedule, you can set the start and end time of the Schedule by specifying the startDate and endDate. | ||||||
These values must follow the format `yyyy-MM-ddTHH:mm:ss.SSSZ`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```ts | ||||||
declare const target: targets.LambdaInvoke; | ||||||
|
||||||
new Schedule(this, 'Schedule', { | ||||||
schedule: ScheduleExpression.rate(cdk.Duration.hours(12)), | ||||||
target: target, | ||||||
startDate: '2023-01-01T00:00:00.000Z', | ||||||
endDate: '2023-02-01T00:00:00.000Z', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we standardized on using the How do you feel about that? I think that's the best course of action here as it allows for more types of inputs, but feel free to push back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment! Using the Date type to allow for a variety of user inputs is certainly appealing. By typing these values as string representation in the ISO 8601 format, we could mitigate these inconsistencies and ensure more predictable behavior across different environments. This is just my personal opinion and I would love to get feedback from the CDK team. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CFN accepts https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, However, I would like to change these properties to use Date type, since this problem does not occur if the user passes a string with timezone at initialization, and this is not a CDK problem but a JavaScript Date class specification problem. |
||||||
}); | ||||||
``` | ||||||
|
||||||
## Scheduler Targets | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -114,6 +114,26 @@ export interface ScheduleProps { | |||||||||||||||||||||||
* @default - All events in Scheduler are encrypted with a key that AWS owns and manages. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
readonly key?: kms.IKey; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* The date, in UTC, after which the schedule can begin invoking its target. | ||||||||||||||||||||||||
* EventBridge Scheduler ignores startDate for one-time schedules. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* Specify an absolute time in the ISO 8601 format. For example, 2020-12-01T00:00:00.000Z. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @default - no value | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
readonly startDate?: string; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* The date, in UTC, before which the schedule can invoke its target. | ||||||||||||||||||||||||
* EventBridge Scheduler ignores endDate for one-time schedules. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* Specify an absolute time in the ISO 8601 format. For example, 2020-12-01T00:00:00.000Z. | ||||||||||||||||||||||||
* | ||||||||||||||||||||||||
* @default - no value | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
readonly endDate?: string; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
|
@@ -213,6 +233,8 @@ export class Schedule extends Resource implements ISchedule { | |||||||||||||||||||||||
return this.metricAll('InvocationsSentToDeadLetterCount_Truncated_MessageSizeExceeded', props); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private static readonly ISO8601_REGEX = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])\.[0-9]{3}(Z)?$/; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
A previous issue was caused by TransitionDate being formatted without the final There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are absolutely right. |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
/** | ||||||||||||||||||||||||
* The schedule group associated with this schedule. | ||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||
|
@@ -254,6 +276,8 @@ export class Schedule extends Resource implements ISchedule { | |||||||||||||||||||||||
|
||||||||||||||||||||||||
this.retryPolicy = targetConfig.retryPolicy; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
this.validateTimeFrame(props.startDate, props.endDate); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const resource = new CfnSchedule(this, 'Resource', { | ||||||||||||||||||||||||
name: this.physicalName, | ||||||||||||||||||||||||
flexibleTimeWindow: { mode: 'OFF' }, | ||||||||||||||||||||||||
|
@@ -276,6 +300,8 @@ export class Schedule extends Resource implements ISchedule { | |||||||||||||||||||||||
sageMakerPipelineParameters: targetConfig.sageMakerPipelineParameters, | ||||||||||||||||||||||||
sqsParameters: targetConfig.sqsParameters, | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
startDate: props.startDate, | ||||||||||||||||||||||||
endDate: props.endDate, | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
this.scheduleName = this.getResourceNameAttribute(resource.ref); | ||||||||||||||||||||||||
|
@@ -306,4 +332,22 @@ export class Schedule extends Resource implements ISchedule { | |||||||||||||||||||||||
const isEmptyPolicy = Object.values(policy).every(value => value === undefined); | ||||||||||||||||||||||||
return !isEmptyPolicy ? policy : undefined; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private validateTimeFrame(startDate?: string, endDate?: string) { | ||||||||||||||||||||||||
if (startDate && !Schedule.ISO8601_REGEX.test(startDate)) { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
throw new Error(`startDate needs to follow the format yyyy-MM-ddTHH:mm:ss.SSSZ but got ${startDate}`); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
if (endDate && !Schedule.ISO8601_REGEX.test(endDate)) { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
throw new Error(`endDate needs to follow the format yyyy-MM-ddTHH:mm:ss.SSSZ but got ${endDate}`); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (startDate && endDate) { | ||||||||||||||||||||||||
const start = new Date(startDate); | ||||||||||||||||||||||||
const end = new Date(endDate); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (end <= start) { | ||||||||||||||||||||||||
throw new Error(`startDate must come before the endDate but got startDate: ${startDate}, endDate: ${endDate}`); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It should be fine to compare the strings directly given the format. |
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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 would also prefer the props to be just named
start
andend
, orstartTime
/endTime
.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.
In CFn, it is StartDate and EndDate, so I shortened it to start and end.