Sha256: 1b0c9e4f8ebb6b5220eb7cd750dda95d402e12f3b037032fc51b1f8a1519fc82

Contents?: true

Size: 738 Bytes

Versions: 6

Compression:

Stored size: 738 Bytes

Contents

module Jets::Job::Helpers
  module SnsEvent
    def sns_events
      records = event["Records"]
      return [] unless records
      records.map do |record|
        message = record["Sns"]["Message"]
        ActiveSupport::HashWithIndifferentAccess.new(JSON.load(message))
      end
    end
    alias sns_event_payloads sns_events

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

    # Deprecated methods below
    def sns_event_payload
      puts "WARN: sns_event_payload is deprecated".color(:yellow)
      puts "It can possibly drop events when they come in extremely fast."
      puts "Use sns_events instead"
      sns_events.first
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/job/helpers/sns_event.rb
jets-5.0.12 lib/jets/job/helpers/sns_event.rb
jets-5.0.11 lib/jets/job/helpers/sns_event.rb
jets-5.0.10 lib/jets/job/helpers/sns_event.rb
jets-5.0.9 lib/jets/job/helpers/sns_event.rb
jets-5.0.8 lib/jets/job/helpers/sns_event.rb