Skip to content

(synthetics): add static cron method to schedule class #16402

@kaizencc

Description

@kaizencc

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-syntheticsRelated to Amazon CloudWatch Syntheticseffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.good first issueRelated to contributions. See CONTRIBUTING.mdp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions