Scheduling Actions
Every driver can schedule events to occur in a number of different ways. Schedules are automatically cleared when a driver is terminated.
  • Integer arguments are in milliseconds. 1000 == 1 second
  • Strings can be used for a friendly representation of the time
    • '30s' == 30 seconds
    • '5m' == 5 minutes
    • '1w2d3h5m' == 1 week, 2 days, 3 hours and 5 minutes
    • '2Y1M' == 2 years, 1 month
Function
Arguments
Description
schedule.in
String or Integer
schedule a task to run once in the time specified (formats above)
schedule.at
Time or String
schedule a task at a time represented by a Time object or a parsable time string
schedule.every
String or Integer
schedule a task to run every time period on repeat
schedule.cron
String
A schedule that will fire based on a CRON string
schedule.clear
shortcut for cancelling any active schedules

Examples

1
schedule.every('1m') do
2
# perform some action, such as polling
3
end
4
5
schedule.in(500) do
6
# ...
7
end
8
9
schedule.at(Time.now + 2.hours) do
10
# ...
11
end
12
13
schedule.at('2018-02-02T15:32:41+11:00') do
14
# ...
15
end
16
17
# Every day at 8am
18
schedule.cron('0 8 * * *') do
19
# ...
20
end
21
22
# Canceling an individual schedule
23
@email_sched = schedule.in(500) do
24
send_email
25
end
26
@email_sched.cancel
Copied!
There are often situations where you want to run the block immediately.
1
def connected
2
schedule.every('1m', :run_now) do
3
poll_current_state
4
end
5
end
Copied!
CRON also supports time zones - which should always be configured
1
schedule.cron('0 8 * * *', timezone: 'Sydney') do
2
# ...
3
end
Copied!
See the list of supported time zone strings and information about time zones.
Copy link
Contents
Examples