Class: Epi::Trigger
- Inherits:
-
Object
- Object
- Epi::Trigger
- Defined in:
- lib/epi/trigger.rb
Direct Known Subclasses
Defined Under Namespace
Classes: JobTrigger, ProcessTrigger
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#job ⇒ Object
readonly
Returns the value of attribute job.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(job, handler, *args) ⇒ Trigger
constructor
A new instance of Trigger.
- #logger ⇒ Object
- #message ⇒ Object
- #try ⇒ Object
- #try_with(process) ⇒ Object
Constructor Details
#initialize(job, handler, *args) ⇒ Trigger
Returns a new instance of Trigger.
13 14 15 16 17 |
# File 'lib/epi/trigger.rb', line 13 def initialize(job, handler, *args) @job = job @handler = handler @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
11 12 13 |
# File 'lib/epi/trigger.rb', line 11 def args @args end |
#job ⇒ Object (readonly)
Returns the value of attribute job.
11 12 13 |
# File 'lib/epi/trigger.rb', line 11 def job @job end |
Class Method Details
.make(job, name, args, handler) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/epi/trigger.rb', line 4 def self.make(job, name, args, handler) klass_name = name.camelize klass = Triggers.const_defined?(klass_name) && Triggers.const_get(klass_name) raise Exceptions::Fatal, "No trigger exists named #{name}" unless Class === klass && klass < self klass.new job, handler, *args end |
Instance Method Details
#message ⇒ Object
23 24 25 |
# File 'lib/epi/trigger.rb', line 23 def nil end |
#try ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/epi/trigger.rb', line 27 def try case self when ProcessTrigger then job.running_processes.each_value { |process| try_with process } when JobTrigger then try_with nil else nil end end |
#try_with(process) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/epi/trigger.rb', line 35 def try_with(process) args = [process].reject(&:nil?) if test *args text = "Trigger on job #{job.id}" text << " (PID #{process.pid})" if process text << ": " << if logger.info text @handler.call process || job end end |