-
Notifications
You must be signed in to change notification settings - Fork 4.4k
(synthetics): add static cron method to schedule class #16402
Copy link
Copy link
Closed
Labels
@aws-cdk/aws-syntheticsRelated to Amazon CloudWatch SyntheticsRelated to Amazon CloudWatch Syntheticseffort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortfeature-requestA feature should be added or improved.A feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdRelated to contributions. See CONTRIBUTING.mdp2
Description
cron expressions are now allowed on synthetic canaries. Similar to app-autoscaling and autoscaling and other modules, the synthetic Schedule class should support a static cron method that takes in cronOptions.
I think we can (and should) talk about moving Schedule to core. I tried that in #9250 and perhaps we can revive that conversation.
Use Case
Syntactic sugar and to offer the same user experience across modules.
Proposed Solution
Here's how its done in application autoscaling:
aws-cdk/packages/@aws-cdk/aws-applicationautoscaling/lib/schedule.ts
Lines 47 to 62 in 492d33b
| public static cron(options: CronOptions): Schedule { | |
| if (options.weekDay !== undefined && options.day !== undefined) { | |
| throw new Error('Cannot supply both \'day\' and \'weekDay\', use at most one'); | |
| } | |
| const minute = fallback(options.minute, '*'); | |
| const hour = fallback(options.hour, '*'); | |
| const month = fallback(options.month, '*'); | |
| const year = fallback(options.year, '*'); | |
| // Weekday defaults to '?' if not supplied. If it is supplied, day must become '?' | |
| const day = fallback(options.day, options.weekDay !== undefined ? '?' : '*'); | |
| const weekDay = fallback(options.weekDay, '?'); | |
| return new LiteralSchedule(`cron(${minute} ${hour} ${day} ${month} ${weekDay} ${year})`); | |
| } |
Other
The current work around is to use Schedule.expression('cron(* * * * *)').
Related: #16392.
- 👋 I may be able to implement this feature request
-
⚠️ This feature might incur a breaking change
This is a 🚀 Feature Request
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
@aws-cdk/aws-syntheticsRelated to Amazon CloudWatch SyntheticsRelated to Amazon CloudWatch Syntheticseffort/smallSmall work item – less than a day of effortSmall work item – less than a day of effortfeature-requestA feature should be added or improved.A feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdRelated to contributions. See CONTRIBUTING.mdp2