Class: Ductr::RufusTrigger
- Defined in:
- lib/ductr/rufus_trigger.rb
Overview
A time related trigger, used to trigger jobs or pipelines based on temporal events. The trigger is registered as ‘:schedule`:
trigger :schedule, every: "1min"
def every_minute
MyPipeline.perform_later
end
This trigger is based on the ‘rufus-scheduler` gem. Under the hood, the internal method `Rufus::Scheduler#do_schedule` is used.
There are 4 types of options available:
-
‘:once`, used to schedule at a given time
trigger :schedule, once: “10d” # Will run in ten days trigger :schedule, once: “2042/12/12 23:59:00” # Will run at the given date
-
‘:every`, triggers following the given frequency
trigger :schedule, every: “1min” # will run every minute.
-
‘:interval`, run the trigger then waits the given interval before running again
# Will run every 4 + 1 seconds trigger :schedule, interval: “4s” def every_interval
sleep(1) MyPipeline.perform_later
end
-
‘:cron`, run the trigger following the given crontab pattern
trigger :schedule, cron: “00 01 * * *” # Will run every day at 1am.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Trigger
Instance Method Summary collapse
-
#add(method, options) ⇒ void
Adds a new trigger into rufus-scheduler.
-
#stop ⇒ void
Shutdown rufus-scheduler.
Methods inherited from Trigger
Constructor Details
This class inherits a constructor from Ductr::Trigger
Instance Method Details
#add(method, options) ⇒ void
This method returns an undefined value.
Adds a new trigger into rufus-scheduler.
53 54 55 56 57 58 59 |
# File 'lib/ductr/rufus_trigger.rb', line 53 def add(method, ) rufus_type = .keys.first rufus_value = .values.first handler = callable(method, **) do_schedule(rufus_type, rufus_value, handler) end |
#stop ⇒ void
This method returns an undefined value.
Shutdown rufus-scheduler
66 67 68 |
# File 'lib/ductr/rufus_trigger.rb', line 66 def stop rufus.shutdown end |