Class: Mongrel::UploadProgress

Inherits:
Object
  • Object
show all
Defined in:
lib/haikulearning_mongrel_upload_progress/init.rb

Overview

Keeps track of the status of all currently processing uploads

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUploadProgress

Returns a new instance of UploadProgress.



51
52
53
54
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 51

def initialize
  @guard    = Mutex.new
  @counters = {}
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



50
51
52
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 50

def debug
  @debug
end

Instance Method Details

#add(upid, size) ⇒ Object



68
69
70
71
72
73
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 68

def add(upid, size)
  @guard.synchronize do
    @counters[upid] = [Time.now, {:size => size, :received => 0}]
    puts "#{upid}: Added" if @debug
  end
end

#check(upid) ⇒ Object



56
57
58
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 56

def check(upid)
  @counters[upid].last rescue nil
end

#finish(upid) ⇒ Object



81
82
83
84
85
86
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 81

def finish(upid)
  @guard.synchronize do
    puts "#{upid}: Finished" if @debug
    @counters.delete(upid)
  end
end

#last_checked(upid) ⇒ Object



60
61
62
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 60

def last_checked(upid)
  @counters[upid].first rescue nil
end

#listObject



88
89
90
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 88

def list
  @counters.keys.sort
end

#mark(upid, len) ⇒ Object



75
76
77
78
79
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 75

def mark(upid, len)
  return unless status = check(upid)
  puts "#{upid}: Marking" if @debug
  @guard.synchronize { status[:received] = status[:size] - len }
end

#update_checked_time(upid) ⇒ Object



64
65
66
# File 'lib/haikulearning_mongrel_upload_progress/init.rb', line 64

def update_checked_time(upid)
  @guard.synchronize { @counters[upid][0] = Time.now }
end