Module: Jets::Job::Helpers::S3Event

Included in:
Base
Defined in:
lib/jets/job/helpers/s3_event.rb

Instance Method Summary collapse

Instance Method Details

#s3_eventObject

Deprecated methods below



36
37
38
39
40
41
# File 'lib/jets/job/helpers/s3_event.rb', line 36

def s3_event
  puts "WARN: s3_event is deprecated".color(:yellow)
  puts "It can possibly drop events when they come in extremely fast."
  puts "Use s3_events instead"
  s3_events.first
end

#s3_eventsObject Also known as: s3_event_payloads



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jets/job/helpers/s3_event.rb', line 3

def s3_events
  encoded_messages = event["Records"].map do |record|
    record["Sns"]["Message"] # SNS message is JSON
  end
  # Decode the JSON messages
  messages = encoded_messages.map do |message|
    JSON.load(message)
  end
  # Extract the S3 event records
  messages.map do |message|
    message["Records"].map do |record|
      ActiveSupport::HashWithIndifferentAccess.new(record)
    end
  end.flatten
end

#s3_events?Boolean Also known as: s3_event_payloads?

Returns:

  • (Boolean)


20
21
22
# File 'lib/jets/job/helpers/s3_event.rb', line 20

def s3_events?
  event["Records"]&.any? { |r| r.dig("Sns", "Message") }
end

#s3_objectObject



43
44
45
46
47
48
# File 'lib/jets/job/helpers/s3_event.rb', line 43

def s3_object
  puts "WARN: s3_object is deprecated".color(:yellow)
  puts "It can possibly drop events when they come in extremely fast."
  puts "Use s3_objects instead"
  s3_objects.first
end

#s3_objectsObject



25
26
27
28
29
# File 'lib/jets/job/helpers/s3_event.rb', line 25

def s3_objects
  s3_events.map do |record|
    record["s3"]["object"]
  end
end

#s3_objects?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/jets/job/helpers/s3_event.rb', line 31

def s3_objects?
  s3_events.any? { |r| r.dig("s3", "object") }
end