Class: Asger::Task
- Inherits:
-
Object
- Object
- Asger::Task
- Defined in:
- lib/asger/task.rb
Overview
A Task is a wrapper around an up and a down function. Up functions
are called when an auto-scaling group adds an instance, and Asger retrieves
the instance data for the task. Down functions are called when an
auto-scaling group downs an instance, and Asger passes along only the
instance ID (because it's all we've got).
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Class Method Summary collapse
Instance Method Summary collapse
-
#down {|instance_id, parameters| ... } ⇒ Object
private
Defines a 'down' function.
-
#initialize(logger, code, filename = "unknown_file.rb") ⇒ Task
constructor
A new instance of Task.
- #invoke_down(instance_id, parameters) ⇒ Object
- #invoke_sanity_check(parameters) ⇒ Object
- #invoke_up(instance, parameters) ⇒ Object
-
#sanity_check {|parameters| ... } ⇒ Object
private
Defines a sanity check function, which should raise and fail (which will halt Asger before it does anything with the actual queue) if there's a problem with the parameter set.
-
#up {|instance, parameters| ... } ⇒ Object
private
Defines an 'up' function.
Constructor Details
#initialize(logger, code, filename = "unknown_file.rb") ⇒ Task
Returns a new instance of Task.
12 13 14 15 16 |
# File 'lib/asger/task.rb', line 12 def initialize(logger, code, filename = "unknown_file.rb") @logger = logger @name = File.basename(filename) instance_eval(code, filename, 1) end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/asger/task.rb', line 10 def logger @logger end |
Class Method Details
Instance Method Details
#down {|instance_id, parameters| ... } ⇒ Object (private)
Defines a 'down' function.
74 75 76 |
# File 'lib/asger/task.rb', line 74 def down(&block) @down_proc = block end |
#invoke_down(instance_id, parameters) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/asger/task.rb', line 37 def invoke_down(instance_id, parameters) if @down_proc logger.debug "Invoking down for '#{@name}'..." @down_proc.call(instance_id, parameters) logger.debug "Down invoked for '#{@name}'..." else logger.debug "No down for '#{@name}'." end end |
#invoke_sanity_check(parameters) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/asger/task.rb', line 18 def invoke_sanity_check(parameters) if @sanity_check_proc logger.debug "Sanity checking for '#{@name}'..." @sanity_check_proc.call(parameters) else logger.debug "No sanity check for '#{@name}'." end end |
#invoke_up(instance, parameters) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/asger/task.rb', line 27 def invoke_up(instance, parameters) if @up_proc logger.debug "Invoking up for '#{@name}'..." @up_proc.call(instance, parameters) logger.debug "Up invoked for '#{@name}'..." else logger.debug "No up for '#{@name}'." end end |
#sanity_check {|parameters| ... } ⇒ Object (private)
Defines a sanity check function, which should raise and fail (which will halt Asger before it does anything with the actual queue) if there's a problem with the parameter set.
58 59 60 |
# File 'lib/asger/task.rb', line 58 def sanity_check(&block) @sanity_check_proc = block end |
#up {|instance, parameters| ... } ⇒ Object (private)
Defines an 'up' function.
66 67 68 |
# File 'lib/asger/task.rb', line 66 def up(&block) @up_proc = block end |