Class: Epi::Trigger
- Inherits:
-
Object
show all
- Defined in:
- lib/epi/trigger.rb
Defined Under Namespace
Classes: JobTrigger, ProcessTrigger
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
Returns the value of attribute args.
11
12
13
|
# File 'lib/epi/trigger.rb', line 11
def args
@args
end
|
#job ⇒ Object
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
#logger ⇒ Object
19
20
21
|
# File 'lib/epi/trigger.rb', line 19
def logger
Epi.logger
end
|
#message ⇒ Object
23
24
25
|
# File 'lib/epi/trigger.rb', line 23
def message
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 << ": " << message if message
logger.info text
@handler.call process || job
end
end
|