diff --git a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/schedule.ts b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/schedule.ts index 3954b0a81efaf..cfa078e2804ca 100644 --- a/packages/aws-cdk-lib/aws-applicationautoscaling/lib/schedule.ts +++ b/packages/aws-cdk-lib/aws-applicationautoscaling/lib/schedule.ts @@ -17,7 +17,7 @@ export abstract class Schedule extends CoreSchedule { * Construct a schedule from an interval and a time unit. Must be a whole number of seconds. */ public static rate(duration: Duration): Schedule { - return super.protectedRate(duration); + return new LiteralSchedule(super.protectedRate(duration)); } /** @@ -45,3 +45,14 @@ export abstract class Schedule extends CoreSchedule { * @deprecated use core.CronOptions instead */ export interface CronOptions extends CoreCronOptions {} + +class LiteralSchedule extends Schedule { + constructor( + public readonly expressionString: string, + public readonly timeZone?: TimeZone, + ) { + super(); + } + + public _bind() {} +} diff --git a/packages/aws-cdk-lib/aws-events/lib/schedule.ts b/packages/aws-cdk-lib/aws-events/lib/schedule.ts index d4d6549e8b611..bd4b306095b2a 100644 --- a/packages/aws-cdk-lib/aws-events/lib/schedule.ts +++ b/packages/aws-cdk-lib/aws-events/lib/schedule.ts @@ -1,4 +1,4 @@ -import { Duration, Schedule as CoreSchedule } from '../../core'; +import { Duration, Schedule as CoreSchedule, TimeZone } from '../../core'; /** * Schedule for scheduled event rules @@ -23,7 +23,7 @@ export abstract class Schedule extends CoreSchedule { * Rates may be defined with any unit of time, but when converted into minutes, the duration must be a positive whole number of minutes. */ public static rate(duration: Duration): Schedule { - return super.protectedRate(duration); + return new LiteralSchedule(super.protectedRate(duration)); } /** @@ -34,6 +34,17 @@ export abstract class Schedule extends CoreSchedule { } } +class LiteralSchedule extends Schedule { + constructor( + public readonly expressionString: string, + public readonly timeZone?: TimeZone, + ) { + super(); + } + + public _bind() {} +} + /** * Options to configure a cron expression * diff --git a/packages/aws-cdk-lib/core/lib/schedule.ts b/packages/aws-cdk-lib/core/lib/schedule.ts index 4c30eb3a86a96..483e7f374a61d 100644 --- a/packages/aws-cdk-lib/core/lib/schedule.ts +++ b/packages/aws-cdk-lib/core/lib/schedule.ts @@ -44,13 +44,13 @@ export abstract class Schedule { * * Rates may be defined with any unit of time, but when converted into minutes, the duration must be a positive whole number of minutes. */ - protected static protectedRate(duration: Duration): Schedule { + protected static protectedRate(duration: Duration): string { if (duration.isUnresolved()) { const validDurationUnit = ['minute', 'minutes', 'hour', 'hours', 'day', 'days']; if (validDurationUnit.indexOf(duration.unitLabel()) === -1) { throw new Error("Allowed units for scheduling are: 'minute', 'minutes', 'hour', 'hours', 'day', 'days'"); } - return new LiteralSchedule(`rate(${duration.formatTokenToNumber()})`); + return `rate(${duration.formatTokenToNumber()})`; } if (duration.toMinutes() === 0) { throw new Error('Duration cannot be 0'); @@ -59,7 +59,7 @@ export abstract class Schedule { let rate = maybeRate(duration.toDays({ integral: false }), 'day'); if (rate === undefined) { rate = maybeRate(duration.toHours({ integral: false }), 'hour'); } if (rate === undefined) { rate = makeRate(duration.toMinutes({ integral: true }), 'minute'); } - return new LiteralSchedule(rate); + return rate; } /**