Sha256: 0981ba13eb0327fc3bc563484c886ec611b7135622c304205747b6117e26ee77

Contents?: true

Size: 862 Bytes

Versions: 5

Compression:

Stored size: 862 Bytes

Contents

module NFAgent
  class ChunkHandler

    # TODO: Rename this to Controller later
    def initialize(chunk_size = 500)
      @chunk = Chunk.new(chunk_size)
    end

    def append(line)
      # if current day is > day of last entry on current_chunk 
      # then submit and reset the chunk before adding the line
      current_day = Time.now.day
      if current_day != @chunk.created_at.day
        Log.info("Expiring chunk due to date rollover")
        reset_chunk
      end
      @chunk << line
    end

    def check_full_or_expired
      if @chunk.full? || @chunk.expired?
        reset_chunk
      end
    end

    private
      def reset_chunk
        submitter = Submitter.new(@chunk.dump)
        submitter.errback { |payload|
          payload.write_to_disk(Config.dump_dir)
        }
        @chunk.clear
        submitter.perform
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nfagent-0.9.10 lib/nfagent/chunk_handler.rb
nfagent-0.9.9 lib/nfagent/chunk_handler.rb
nfagent-0.9.8 lib/nfagent/chunk_handler.rb
nfagent-0.9.6 lib/nfagent/chunk_handler.rb
nfagent-0.9.5 lib/nfagent/chunk_handler.rb