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 10 seconds
15 OPT = { :expires_in => 10 }
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)
30 moneta.update_key(upid, OPT)
37 moneta.store(upid, status, OPT)
42 status.length ||= status.seen
43 status.seen = status.length
44 moneta.store(upid, status, OPT)