Class: Stormtroopers::Trooper
- Inherits:
-
Object
- Object
- Stormtroopers::Trooper
show all
- Defined in:
- lib/stormtroopers/trooper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(parameters = {}, &block) ⇒ Trooper
Returns a new instance of Trooper.
5
6
7
8
|
# File 'lib/stormtroopers/trooper.rb', line 5
def initialize(parameters = {}, &block)
@parameters = parameters
@task = block
end
|
Instance Attribute Details
#parameters ⇒ Object
Returns the value of attribute parameters.
3
4
5
|
# File 'lib/stormtroopers/trooper.rb', line 3
def parameters
@parameters
end
|
#started_at ⇒ Object
Returns the value of attribute started_at.
3
4
5
|
# File 'lib/stormtroopers/trooper.rb', line 3
def started_at
@started_at
end
|
#task ⇒ Object
Returns the value of attribute task.
3
4
5
|
# File 'lib/stormtroopers/trooper.rb', line 3
def task
@task
end
|
Instance Method Details
#after_run ⇒ Object
23
24
25
|
# File 'lib/stormtroopers/trooper.rb', line 23
def after_run
end
|
#before_run ⇒ Object
19
20
21
|
# File 'lib/stormtroopers/trooper.rb', line 19
def before_run
end
|
#exception(exception) ⇒ Object
27
28
29
30
31
32
|
# File 'lib/stormtroopers/trooper.rb', line 27
def exception(exception)
logger.error "Error processing #{name}: #{exception.message}"
logger.debug "Stacktrace #{name}:\n#{exception.backtrace.join("\n")}"
raise exception
end
|
#name ⇒ Object
10
11
12
13
|
# File 'lib/stormtroopers/trooper.rb', line 10
def name
@task.to_s
end
|
#run ⇒ Object
34
35
36
|
# File 'lib/stormtroopers/trooper.rb', line 34
def run
task.call
end
|
#start ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/stormtroopers/trooper.rb', line 38
def start
@started_at = Time.now
before_run
run
after_run
rescue => e
exception(e)
end
|
#status ⇒ Object
15
16
17
|
# File 'lib/stormtroopers/trooper.rb', line 15
def status
"#{name} running since #{started_at.strftime("%Y-%m-%d %H:%M:%S")} (#{(Time.now - started_at).to_i} seconds)" if started_at
end
|