Class: Asger::Runner
- Inherits:
-
Object
- Object
- Asger::Runner
- Defined in:
- lib/asger/runner.rb
Instance Method Summary collapse
- #delete_message(msg) ⇒ Object private
-
#initialize(logger, sqs_client, ec2_client, queue_url, parameters, task_files) ⇒ Runner
constructor
A new instance of Runner.
- #step ⇒ Object
Constructor Details
#initialize(logger, sqs_client, ec2_client, queue_url, parameters, task_files) ⇒ Runner
Returns a new instance of Runner.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/asger/runner.rb', line 15 def initialize(logger, sqs_client, ec2_client, queue_url, parameters, task_files) @logger = logger @sqs_client = sqs_client @ec2_client = ec2_client @ec2_resource_client = Aws::EC2::Resource.new(client: @ec2_client) @queue_url = queue_url @parameters = Hashie::Mash.new(parameters) @tasks = task_files.map { |tf| Task.from_file(@logger, tf) } @logger.info "#{@tasks.length} task(s) set up." @tasks.each { |t| t.invoke_sanity_check(@parameters) } end |
Instance Method Details
#delete_message(msg) ⇒ Object (private)
71 72 73 |
# File 'lib/asger/runner.rb', line 71 def (msg) @sqs_client.(queue_url: @queue_url, receipt_handle: msg[:receipt_handle]) end |
#step ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/asger/runner.rb', line 30 def step() = @sqs_client.(queue_url: @queue_url)[:messages] .each do |msg| notification = JSON.parse(JSON.parse(msg[:body])["Message"]) if notification["Event"] != nil case notification["Event"].gsub("autoscaling:", "") when "EC2_INSTANCE_LAUNCH" instance_id = notification["EC2InstanceId"] @logger.info "Instance launched: #{instance_id}" instance = @ec2_resource_client.instance(instance_id) @tasks.each do |task| task.invoke_up(instance, @parameters) end (msg) when "EC2_INSTANCE_LAUNCH_ERROR" @logger.warn "Instance launch error received." (msg) when "EC2_INSTANCE_TERMINATE" instance_id = notification["EC2InstanceId"] @logger.info "Instance terminated: #{instance_id}" @tasks.reverse_each do |task| task.invoke_down(instance_id, @parameters) end (msg) when "EC2_INSTANCE_TERMINATE_ERROR" @logger.warn "Instance terminate error received." (msg) when "TEST_NOTIFICATION" @logger.debug "Found test notification in queue." (msg) else @logger.debug "Unrecognized notification '#{notification["Event"]}', ignoring." end end end end |