Timer that sends messages to WebSocket connections
A timer is a trigger that sends messages to WebSocket connections on schedule. The schedule is entered as a cron expression. The cron expression uses UTC+0
A timer requires a service account to send messages to WebSocket connections.
For more information about creating a timer, see Creating a timer that sends messages to WebSocket connections.
Cron expression format
The fields in a cron expression are ordered as follows: Minutes Hours Day-of-month Month Day-of-week Year.
Possible field values
Note
Special characters, as well as months and days of the week, are case-insensitive: MON is the same as mon.
| Field name |
Required field |
Acceptable values |
Supported special characters |
|---|---|---|---|
Minutes |
Yes | 0-59 | ,, -, *, / |
Hours |
Yes | 0-23 | ,, -, *, / |
Day of month |
Yes | 1-31 | ,, -, *, ?, /, L, W |
Month |
Yes | 1-12, JAN-DEC |
,, -, *, / |
Day of week |
Yes | 1-7, SUN-SAT |
,, -, *, ?, /, L, # |
Year |
No | Empty, 1970-2099 | ,, -, *, / |
Special characters
You can use the following special characters in cron expressions:
-
*: Selects all values in the field.*in theMinutesfield: Trigger firesevery minute. -
?: Selects any field value. You cannot specifyDay of monthandDay of weekat the same time. If you have entered a value in one of these fields, put?in the other one.10inDay of monthand?inDay of week: Trigger fires on the 10th day of each month. -
-: Selects a range of values.10-12inHours: Trigger fires at 10 a.m., 11 a.m., and 12 p.m. -
,: Selects multiple values.MON,WED,FRIinDay of week: Trigger fires on Monday, Wednesday, and Friday. -
/: Increments the value.0/15inMinutes: Trigger fires at 0, 15, 30, and 45 minutes past each hour. -
L: This character has different meanings in the two fields it is valid for:- In the
Day of monthfield, it means the last day of the month. - In the
Day of weekfield, it means the last day of the week,7(Saturday,SAT).
LinDay of month: Trigger fires on January 31, February 28, and so on. - In the
-
W: Selects the weekday nearest to the specified date.15WinDay of month: Trigger fires on the weekday nearest to the 15th day of the month. If the 15th day falls on Saturday, the trigger fires on Friday the 14th.Note
LandWin theDay of monthfield can also merge into theLWcombination, firing the trigger on the last weekday of the month. -
#: Selects the Nth day of the month.6#3inDay of week: Trigger will fire on the third Friday of the month (6 for Friday; 3 for third Friday of the month).
Examples of cron expressions
| Cron expression | Description |
|---|---|
* * * * ? * |
The trigger fires every minute. |
0 * ? * * * |
The trigger fires every hour. |
15 10 ? * * * |
The trigger fires every day at 10:15. |
Roles required for timers to run correctly
- To create a timer, you need a permission for the service account under which the timer executes the operation. This permission comes with the iam.serviceAccounts.user and editor roles or higher.
- To activate a timer, the service account needs the
api-gateway.websocketBroadcasterrole for the folder containing the API gateway.
Read more about access management.
Timer message format
After the trigger fires, it will send the following message to WebSocket connections:
{
"messages": [
{
"event_metadata": {
"event_id": "a1s41g2n5g0o********",
"event_type": "yandex.cloud.events.serverless.triggers.TimerMessage",
"created_at": "2019-12-04T12:05:14.227761Z",
"cloud_id": "b1gvlrnlei4l********",
"folder_id": "b1g88tflru0e********"
},
"details": {
"trigger_id": "a1sfe084v4se********",
"payload": "payload-message"
}
}
]
}