It has become fairly common to use the heartbeats to schedule hourly and daily events. However, this results in many of the events happening at the same minute of the hour or day.
A nice feature would be to automate scheduling against the heart beats that can keep track of which slots are filled and slot in an event.
The API would look something like this:
QueueBus.dispatch("app") do
hourly 'do_every_hour' do |attrs|
end
# Is equivalent to the following, where `next_minute` looks up the next available slot
# the minute. Easily done with a cycle, but for this we should make sure it fits into the other
# subscriptions in redis to achieve maximum efficiency
subscribe 'subscribe_to_hour', bus_event_type: 'heartbeat_minutes', minute: next_minute do |attrs|
end
hourly 'do_every_hour_but_on_back_half_hour', range: 30..59 do |attrs|
end
# Will block out a five minute span. Defaults to 1 minute.
# Useful for events that will trigger long running work
hourly 'do_long_running_every_hour', minutes_long: 5 do |attrs|
end
# Will take an hour of every day.
daily 'do_every_day' do |attrs|
end
# Is equivalent to the following, similar to above
subscribe 'subscribe_to_hour', bus_event_type: 'heartbeat_minutes', hour: next_hour, minute: next_minute do |attrs|
end
# Ranges should still consider how it conflicts with others and only doubles up if there are no
# open slots.
daily 'do_every_day_starting_at_midnight', range: 0..6 do |attrs|
end
# There is no `hours_long` for daily, but you can still use `minutes_long` for
# long running events.
daily 'do_long_running_event_every_day', minutes_long: 30 do |attrs|
end
end
It has become fairly common to use the heartbeats to schedule hourly and daily events. However, this results in many of the events happening at the same minute of the hour or day.
A nice feature would be to automate scheduling against the heart beats that can keep track of which slots are filled and slot in an event.
The API would look something like this: