Sha256: 218ef11ec2e91c0a29560d02d92e8e766aef89864b0b4121aacebe93201a45da

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module BarnyardHarvester
  class Queue

    def initialize(args)

      @debug = args.fetch(:debug) { false }

      @log = args.fetch(:logger) { Logger.new(STDOUT) }

      @my_id = "#{args[:crop_number]}-#{self.class}"

      @queue = Hash.new

    end

    def push(harvester_uuid, change_uuid, crop_number, primary_key, transaction_type, value, old_value=Hash.new)
      check_key primary_key

      @queue[primary_key] = value.to_json

      @log.debug "HashQueue: Now: #{DateTime.now}, Harvester:#{harvester_uuid}, Change:#{change_uuid} crop_number: #{crop_number}, key: #{primary_key}, transaction_type: #{transaction_type})"

    end

    def flush
      File.open("#{@my_id}.yml", "w") { |file| file.puts(@queue.to_yaml) }
    end

    private

    def check_key(primary_key)
      # Raise an exception here if the key must conform to a specific format
      # Example: raise "key must be a string object" unless key.is_a? String
    end

  end

  # AddQueue
  #
  class AddQueue < Queue
  end

  # ChangeQueue
  #
  class ChangeQueue < Queue
  end

  # DeleteQueue
  #
  class DeleteQueue < Queue
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
barnyard_harvester-0.0.13 lib/barnyard_harvester/hash_queue.rb
barnyard_harvester-0.0.12 lib/barnyard_harvester/hash_queue.rb
barnyard_harvester-0.0.10 lib/barnyard_harvester/hash_queue.rb
barnyard_harvester-0.0.9 lib/barnyard_harvester/hash_queue.rb