Skip to content

Commit

Permalink
feat(scheduler): change property names
Browse files Browse the repository at this point in the history
  • Loading branch information
sakurai-ryo committed Dec 8, 2023
1 parent a8c279a commit ba4630b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-scheduler-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ const schedule = new Schedule(this, 'Schedule', {
## Configuring flexible time window

You can configure flexible time windows by specifying the `flexibleTimeWindow` property.
By default, the mode of `flexibleTimeWindow` is set to `off` and this feature is disabled.
By default, the mode of `flexibleTimeWindow` is set to `OFF` and this feature is disabled.

```ts
declare const target: targets.LambdaInvoke;

const schedule = new Schedule(this, 'Schedule', {
schedule: ScheduleExpression.rate(Duration.hours(12)),
target,
flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.hours(10)),
flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.hours(10)),
});
```

Expand Down
10 changes: 4 additions & 6 deletions packages/@aws-cdk/aws-scheduler-alpha/lib/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,19 @@ export interface ScheduleTargetProps {

/**
* A time window during which EventBridge Scheduler invokes the schedule.
*
* @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html
*/
export class FlexibleTimeWindowMode {
/**
* FlexibleTimeWindow is disabled.
*/
public static off(): FlexibleTimeWindowMode {
public static Off(): FlexibleTimeWindowMode {
return new FlexibleTimeWindowMode('OFF');
}

/**
* FlexibleTimeWindow is enabled.
*/
public static flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode {
public static Flexible(maximumWindowInMinutes: Duration): FlexibleTimeWindowMode {
if (maximumWindowInMinutes.toMinutes() < 1 || maximumWindowInMinutes.toMinutes() > 1440) {
throw new Error(`maximumWindowInMinutes must be between 1 and 1440, got ${maximumWindowInMinutes.toMinutes()}`);
}
Expand Down Expand Up @@ -164,7 +162,7 @@ export interface ScheduleProps {
*
* @see https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-flexible-time-windows.html
*
* @default FlexibleTimeWindowMode.OFF()
* @default FlexibleTimeWindowMode.Off()
*/
readonly flexibleTimeWindow?: FlexibleTimeWindowMode;
}
Expand Down Expand Up @@ -307,7 +305,7 @@ export class Schedule extends Resource implements ISchedule {

this.retryPolicy = targetConfig.retryPolicy;

const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.off();
const flexibleTimeWindow = props.flexibleTimeWindow ?? FlexibleTimeWindowMode.Off();

const resource = new CfnSchedule(this, 'Resource', {
name: this.physicalName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ new scheduler.Schedule(stack, 'CustomerKmsSchedule', {
new scheduler.Schedule(stack, 'UseFlexibleTimeWindow', {
schedule: expression,
target: target,
flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.flexible(cdk.Duration.minutes(10)),
flexibleTimeWindow: scheduler.FlexibleTimeWindowMode.Flexible(cdk.Duration.minutes(10)),
});

new IntegTest(app, 'integtest-schedule', {
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-scheduler-alpha/test/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Schedule', () => {
new Schedule(stack, 'TestSchedule', {
schedule: expr,
target: new SomeLambdaTarget(func, role),
flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1440)),
flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1440)),
});

// THEN
Expand All @@ -167,7 +167,7 @@ describe('Schedule', () => {
new Schedule(stack, 'TestSchedule', {
schedule: expr,
target: new SomeLambdaTarget(func, role),
flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(1441)),
flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(1441)),
});
}).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 1441');
});
Expand All @@ -177,7 +177,7 @@ describe('Schedule', () => {
new Schedule(stack, 'TestSchedule', {
schedule: expr,
target: new SomeLambdaTarget(func, role),
flexibleTimeWindow: FlexibleTimeWindowMode.flexible(Duration.minutes(0)),
flexibleTimeWindow: FlexibleTimeWindowMode.Flexible(Duration.minutes(0)),
});
}).toThrow('maximumWindowInMinutes must be between 1 and 1440, got 0');
});
Expand Down

0 comments on commit ba4630b

Please sign in to comment.