Class: LambdaPunch::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_punch/notifier.rb

Constant Summary collapse

FILE =
"#{Dir.tmpdir}/lambdapunch-handled"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNotifier

Returns a new instance of Notifier.



24
25
26
27
# File 'lib/lambda_punch/notifier.rb', line 24

def initialize
  @notifier = INotify::Notifier.new
  File.open(FILE, 'w') { |f| f.write('') } unless File.exist?(FILE)
end

Class Method Details

.handled!(context) ⇒ Object



8
9
10
11
12
# File 'lib/lambda_punch/notifier.rb', line 8

def handled!(context)
  File.open(FILE, 'w') do |f|
    f.write context.aws_request_id
  end
end

.request_idObject



14
15
16
# File 'lib/lambda_punch/notifier.rb', line 14

def request_id
  File.read(FILE)
end

.tmp_fileObject



18
19
20
# File 'lib/lambda_punch/notifier.rb', line 18

def tmp_file
  FILE
end

Instance Method Details

#closeObject



37
38
39
40
# File 'lib/lambda_punch/notifier.rb', line 37

def close
  logger.debug "Notifier#close"
  @notifier.close rescue true
end

#processObject



33
34
35
# File 'lib/lambda_punch/notifier.rb', line 33

def process
  @notifier.process
end

#request_idObject



42
43
44
# File 'lib/lambda_punch/notifier.rb', line 42

def request_id
  self.class.request_id
end

#watchObject



29
30
31
# File 'lib/lambda_punch/notifier.rb', line 29

def watch
  @notifier.watch(FILE, :modify, :oneshot) { yield(request_id) }
end