Sha256: 8fa3c0d822f0146412ea4e9205c0a124620d4428920ca24b45e33e5629508402

Contents?: true

Size: 1006 Bytes

Versions: 4

Compression:

Stored size: 1006 Bytes

Contents

require 'date'

module Alephant
  module Publisher
    module Queue
      module SQSHelper
        class Archiver
          attr_reader :cache, :async

          def initialize(cache, async = true)
            @async = async
            @cache = cache
          end

          def see(message)
            return if message.nil?
            message.tap { |m| async ? async_store(m) : store(m) }
          end

          private

          def async_store(m)
            Thread.new { store(m) }
          end

          def store(m)
            cache.put("archive/#{date_key}/#{m.id}", m.body, meta_for(m))
          end

          def date_key
            DateTime.now.strftime('%d-%m-%Y_%H')
          end

          def meta_for(m)
            {
              :id                => m.id,
              :md5               => m.md5,
              :logged_at         => DateTime.now.to_s,
              :queue             => m.queue.url,
            }
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
alephant-publisher-queue-1.1.0 lib/alephant/publisher/queue/sqs_helper/archiver.rb
alephant-publisher-queue-1.0.0 lib/alephant/publisher/queue/sqs_helper/archiver.rb
alephant-publisher-queue-0.1.0 lib/alephant/publisher/queue/sqs_helper/archiver.rb
alephant-publisher-queue-0.0.1 lib/alephant/publisher/queue/sqs_helper/archiver.rb