Sha256: 127a243969d9c90c34e3b0049425fc757434ffb16f64c7a684a447c12990e069

Contents?: true

Size: 919 Bytes

Versions: 15

Compression:

Stored size: 919 Bytes

Contents

require 'date'

module Alephant
  module Publisher
    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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
alephant-publisher-0.6.10 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.9 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.8 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.7 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.6 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.5 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.4 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.3 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.2 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.6.1 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.5.1 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.5.0 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.4.0 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.3.1 lib/alephant/publisher/sqs_helper/archiver.rb
alephant-publisher-0.3.0 lib/alephant/publisher/sqs_helper/archiver.rb