Sha256: 145490e3bc0084a351658b00955d1e4a03d7b837951650429531d702b6fa90ac

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module Merb
  # Keeps track of the status of all currently processing uploads
  class UploadProgress
    include DRbUndumped
    attr_accessor :debug
    def initialize
      @guard    = Mutex.new
      @counters = {}
    end
  
    def check(upid)
      @counters[upid].last rescue nil
    end
  
    def last_checked(upid)
      @counters[upid].first rescue nil
    end
  
    def update_checked_time(upid)
      @guard.synchronize { @counters[upid][0] = Time.now }
    end
  
    def add(upid, size)
      @guard.synchronize do
        @counters[upid] = [Time.now, {:size => size, :received => 0}]
        puts "#{upid}: Added" if @debug
      end
    end
  
    def mark(upid, len)
      return unless status = check(upid)
      puts "#{upid}: Marking" if @debug
      @guard.synchronize { status[:received] = status[:size] - len }
    end
  
    def finish(upid)
      @guard.synchronize do
        puts "#{upid}: Finished" if @debug
        @counters.delete(upid)
      end
    end
  
    def list
      @counters.keys.sort
    end
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
merb-0.3.4 lib/merb/merb_upload_progress.rb
merb-0.2.0 lib/merb/merb_upload_progress.rb
merb-0.3.0 lib/merb/merb_upload_progress.rb
merb-0.3.1 lib/merb/merb_upload_progress.rb
merb-0.3.3 lib/merb/merb_upload_progress.rb
merb-0.3.7 lib/merb/merb_upload_progress.rb