Class: Ductr::Scheduler
- Inherits:
-
Object
- Object
- Ductr::Scheduler
- Extended by:
- Annotable
- Defined in:
- lib/ductr/scheduler.rb
Overview
Base class to declare event driven scheduling. Example using the schedule trigger:
class MyScheduler < Ductr::Scheduler
trigger :schedule, every: "10min"
def every_ten_minutes
MyJob.perform_later
end
end
Class Method Summary collapse
-
.start ⇒ void
Calls #start on all created triggers.
-
.stop ⇒ void
Calls #stop on all created triggers.
-
.trigger(trigger_type, adapter_name = nil, **trigger_options) ⇒ void
Annotation to define a trigger method.
-
.triggers ⇒ Hash<Symbol: Trigger>
All trigger instances are stored in a singleton hash, avoiding to create the same trigger multiple times.
Instance Method Summary collapse
-
#initialize ⇒ Scheduler
constructor
Parses trigger annotations, creates triggers if needed and calls #add on trigger instances.
Constructor Details
#initialize ⇒ Scheduler
Parses trigger annotations, creates triggers if needed and calls #add on trigger instances.
69 70 71 72 73 74 75 76 77 |
# File 'lib/ductr/scheduler.rb', line 69 def initialize self.class.annotated_methods.each do |method| annotation = method.find_annotation(:trigger) trigger = find_trigger(*annotation.params.reverse) callable = self.method(method.name) trigger.add(callable, annotation.) end end |
Class Method Details
.start ⇒ void
This method returns an undefined value.
Calls #start on all created triggers.
52 53 54 |
# File 'lib/ductr/scheduler.rb', line 52 def start triggers.values.each(&:start) end |
.stop ⇒ void
This method returns an undefined value.
Calls #stop on all created triggers.
61 62 63 |
# File 'lib/ductr/scheduler.rb', line 61 def stop triggers.values.each(&:stop) end |
.trigger(trigger_type, adapter_name = nil, **trigger_options) ⇒ void
This method returns an undefined value.
Annotation to define a trigger method
35 |
# File 'lib/ductr/scheduler.rb', line 35 annotable :trigger |
.triggers ⇒ Hash<Symbol: Trigger>
All trigger instances are stored in a singleton hash, avoiding to create the same trigger multiple times.
43 44 45 |
# File 'lib/ductr/scheduler.rb', line 43 def triggers @triggers ||= {} end |