Sha256: fbb9d20474a812b07754cf96ddf80e7fc822aba394a9e6599ec7d94edaea1826

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "socrates/core/state_data"

module Socrates
  module Storage
    module Storage
      def initialize
        @logger = Socrates.config.logger
      end

      def fetch(client_id)
        key = generate_key(client_id)

        snapshot = get(key)

        return if snapshot.nil?

        begin
          Socrates::Core::StateData.deserialize(snapshot)
        rescue StandardError => e
          @logger.warn "Error while fetching state_data for client id '#{client_id}', resetting state: #{e.message}"
          @logger.warn e
        end
      end

      def persist(client_id, state_data)
        key = generate_key(client_id)
        state_data.reset_elapsed_time
        put(key, state_data.serialize)
      end

      def generate_key(client_id)
        client_id
      end

      def has_key?(key)
        raise NotImplementedError
      end

      def clear(key)
        raise NotImplementedError
      end

      def get(key)
        raise NotImplementedError
      end

      def put(key, value)
        raise NotImplementedError
      end

      def clear_all
        raise NotImplementedError
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
socrates-0.1.26 lib/socrates/storage/storage.rb