Class: Lambchop::WatchDog

Inherits:
Object
  • Object
show all
Defined in:
lib/lambchop/watch_dog.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(function_name, options = {}) ⇒ WatchDog

Returns a new instance of WatchDog.



8
9
10
11
12
13
14
15
16
17
# File 'lib/lambchop/watch_dog.rb', line 8

def initialize(function_name, options = {})
  @function_name  = function_name
  @log_group_name = "/aws/lambda/#{@function_name}"
  @client         = options[:client] || Aws::CloudWatchLogs::Client.new
  @start_time     = options[:start_time] || Time.now
  @out            = options[:out] || $stdout
  @last_timestamp = time_to_timestamp(@start_time) - 1
  @interval       = options[:interval] || 1
  @options        = options
end

Class Method Details

.start(function_name, options = {}) ⇒ Object



4
5
6
# File 'lib/lambchop/watch_dog.rb', line 4

def self.start(function_name, options = {})
  self.new(function_name, options).start
end

Instance Method Details

#startObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/lambchop/watch_dog.rb', line 19

def start
  @running = true

  Thread.start do
    while @running
      follow_logs
      sleep @interval
    end
  end
end

#stopObject



30
31
32
# File 'lib/lambchop/watch_dog.rb', line 30

def stop
  @running = false
end