Skip to main content

Schedule

The cloud.Schedule resource is used to trigger events at a regular interval. Schedules are useful for periodic tasks, such as running backups or sending daily reports. The timezone used in cron expressions is always UTC.

Usage​

From cron​

bring cloud;

let schedule = new cloud.Schedule(cron: "* * * * *");

schedule.onTick(inflight () => {
log("schedule: triggered");
});

From rate​

bring cloud;

let schedule = new cloud.Schedule(rate: 1m);

schedule.onTick(inflight () => {
log("schedule: triggered");
});

Simulator (sim)​

A standard JavaScript setTimeout function triggers ticks as callbacks.

AWS (tf-aws and awscdk)​

See Amazon CloudWatch.

Azure (tf-azure)​

🚧 Not supported yet (tracking issue: #1291).

GCP (tf-gcp)​

🚧 Not supported yet (tracking issue: #1292).

API Reference ​

Schedule ​

A schedule.

Initializers ​

bring cloud;

new cloud.Schedule(props?: ScheduleProps);
NameTypeDescription
props
ScheduleProps
No description.

propsOptional ​

Methods ​

Preflight Methods​
NameDescription
onTick
Create a function that runs when receiving the scheduled event.

onTick ​
onTick(inflight: IScheduleOnTickHandler, props?: ScheduleOnTickOptions): Function

Create a function that runs when receiving the scheduled event.

inflightRequired ​

propsOptional ​

Static Functions ​

NameDescription
onLiftType
A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.
toInflight
Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.

onLiftType ​
bring cloud;

cloud.Schedule.onLiftType(host: IInflightHost, ops: MutArray<str>);

A hook called by the Wing compiler once for each inflight host that needs to use this type inflight.

The list of requested inflight methods needed by the inflight host are given by ops.

This method is commonly used for adding permissions, environment variables, or other capabilities to the inflight host.

hostRequired ​

opsRequired ​
  • Type: MutArray<str>

toInflight ​
bring cloud;

cloud.Schedule.toInflight(obj: IResource);

Generates an asynchronous JavaScript statement which can be used to create an inflight client for a resource.

NOTE: This statement must be executed within an async context.

objRequired ​

Properties ​

NameTypeDescription
node
constructs.NodeThe tree node.

nodeRequired ​
node: Node;
  • Type: constructs.Node

The tree node.


Structs ​

ScheduleOnTickOptions ​

Options for Schedule.onTick.

Initializer ​

bring cloud;

let ScheduleOnTickOptions = cloud.ScheduleOnTickOptions{ ... };

Properties ​

NameTypeDescription
concurrency
numThe maximum concurrent invocations that can run at one time.
env
MutMap<str>Environment variables to pass to the function.
logRetentionDays
numSpecifies the number of days that function logs will be kept.
memory
numThe amount of memory to allocate to the function, in MB.
timeout
duration
The maximum amount of time the function can run.

concurrencyOptional ​
concurrency: num;
  • Type: num
  • Default: platform specific limits (100 on the simulator)

The maximum concurrent invocations that can run at one time.


envOptional ​
env: MutMap<str>;
  • Type: MutMap<str>
  • Default: No environment variables.

Environment variables to pass to the function.


logRetentionDaysOptional ​
logRetentionDays: num;
  • Type: num
  • Default: 30

Specifies the number of days that function logs will be kept.

Setting negative value means logs will not expire.


memoryOptional ​
memory: num;
  • Type: num
  • Default: 1024

The amount of memory to allocate to the function, in MB.


timeoutOptional ​
timeout: duration;

The maximum amount of time the function can run.


ScheduleProps ​

Options for Schedule.

Initializer ​

bring cloud;

let ScheduleProps = cloud.ScheduleProps{ ... };

Properties ​

NameTypeDescription
cron
strTrigger events according to a cron schedule using the UNIX cron format.
rate
duration
Trigger events at a periodic rate.

cronOptional ​
cron: str;
  • Type: str
  • Default: undefined

Trigger events according to a cron schedule using the UNIX cron format.

Timezone is UTC. [minute] [hour] [day of month] [month] [day of week] '*' means all possible values. '-' means a range of values. ',' means a list of values. [minute] allows 0-59. [hour] allows 0-23. [day of month] allows 1-31. [month] allows 1-12 or JAN-DEC. [day of week] allows 0-6 or SUN-SAT.


Example

"* * * * *"
rateOptional ​
rate: duration;

Trigger events at a periodic rate.


Example

1m

Protocols ​

IScheduleOnTickHandler ​

Inflight client: @winglang/sdk.cloud.IScheduleOnTickHandlerClient

A resource with an inflight "handle" method that can be passed to Schedule.on_tick.

IScheduleOnTickHandlerClient ​

Inflight client for IScheduleOnTickHandler.

Methods ​

NameDescription
handle
Function that will be called when a message is received from the schedule.

handle ​
inflight handle(): void

Function that will be called when a message is received from the schedule.