Sha256: 1357a0607f646520a99534f8336341a57a3e70cbc20f246d592dc287ba4b1a82

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'json'
require 'time'

module Keen
  module Async
    module Storage
      class BaseStorageHandler

        def initialize(client)
          @logging = client.logging
          @client = client
        end

        # Key stuff
        # ----

        def global_key_prefix
          "keen.#{@client.options[:storage_namespace]}"
        end
        
        def active_queue_key
          "#{global_key_prefix}.active_queue"
        end

        def failed_queue_key
          "#{global_key_prefix}.failed_queue"
        end

        def add_to_active_queue(value)
          @redis.lpush active_queue_key, value
          if @logging
            puts "added #{value} to active queue; length is now #{@redis.llen active_queue_key}"
          end
        end

        def record_job(job)
          add_to_active_queue JSON.generate(job)
        end

        def handle_prior_failures
          # TODO consume the failed_queue and do something with it (loggly? retry? flat file?)
        end

        def count_active_queue
          raise NotImplementedError
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
keen-0.2.0 lib/keen/async/storage/base_storage_handler.rb
keen-0.1.12 lib/keen/async/storage/base_storage_handler.rb