Class: Awful::Events

Inherits:
Cli show all
Defined in:
lib/awful/lambda_events.rb

Constant Summary collapse

COLORS =
{
  OK:       :green,
  PROBLEM:  :red,
  Enabled:  :green,
  Disabled: :red
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#create(name, src) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/awful/lambda_events.rb', line 53

def create(name, src)
  lambda.create_event_source_mapping(
    function_name: name,
    event_source_arn: src,
    enabled: options[:enabled],
    batch_size: options[:batch_size],
    starting_position: options[:starting_position]
  )
end

#delete(uuid) ⇒ Object



64
65
66
67
68
# File 'lib/awful/lambda_events.rb', line 64

def delete(uuid)
  if yes?("Really delete event source mapping #{uuid}?")
    lambda.delete_event_source_mapping(uuid: uuid)
  end
end

#dump(uuid) ⇒ Object



43
44
45
46
47
# File 'lib/awful/lambda_events.rb', line 43

def dump(uuid)
  lambda.get_event_source_mapping(uuid: uuid).tap do |details|
    puts YAML.dump(stringify_keys(details.to_hash))
  end
end

#ls(name = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/awful/lambda_events.rb', line 24

def ls(name = nil)
  lambda.list_event_source_mappings(function_name: name).event_source_mappings.tap do |sources|
    if options[:long]
      print_table sources.map { |s|
        [
          s.uuid,
          color(s.state),
          "Batch size: #{s.batch_size}",
          "Last result: #{color(s.last_processing_result.scan(/\w+/).first)}",
          s.last_modified
        ]
      }
    else
      puts sources.map(&:uuid)
    end
  end
end