1 # -*- encoding: binary -*-
4 # Keeps track of the status of all currently processing uploads
5 # This uses any {Moneta}[http://github.com/wycats/moneta]
6 # store to monitor upload progress.
8 # Usage (in config.ru with Moneta::Memory store):
10 # require 'moneta/memory'
11 # use Upr, :backend => Upr::Monitor.new(Moneta::Memory.new)
12 # run YourApplication.new
13 class Monitor < Struct.new(:moneta)
14 # nuke anything not read/updated in 60 seconds
15 OPT = { :expires_in => 60 }
17 def initialize(moneta_store = nil)
20 require 'moneta/memory' # moneta does not autoload :<
21 self.moneta = Moneta::Memory.new
25 def start(upid, length)
26 moneta.store(upid, Status.new(0, length), OPT)
34 status = moneta[upid] or return
35 status.seen += nr if status.seen >= 0
36 moneta.store(upid, status, OPT)
40 status = moneta[upid] or return
41 status.length ||= status.seen
42 status.seen = status.length
43 moneta.store(upid, status, OPT)
47 status = moneta[upid] or return
49 moneta.store(upid, status, OPT)