Sha256: 224b2ac72f6242f79ad0e92245439632126f8ce191685a38f687e72675e48e1a
Contents?: true
Size: 1.27 KB
Versions: 1
Compression:
Stored size: 1.27 KB
Contents
# -*- encoding: binary -*- module Upr # Keeps track of the status of all currently processing uploads # This uses any {Moneta}[http://github.com/wycats/moneta] # store to monitor upload progress. # # Usage (in config.ru with Moneta Memory store): # require 'upr' # require 'moneta' # use Upr, :backend => Upr::Monitor.new(Moneta.new(:Memory, :serializer => nil)) # run YourApplication.new class Monitor < Struct.new(:moneta) # nuke anything not read/updated in 60 seconds OPT = { :expires_in => 60 } def initialize(moneta_store = nil) super if moneta_store.nil? self.moneta = Moneta.new(:Memory, :serializer => nil) end end def start(upid, length) moneta.store(upid, Status.new(0, length), OPT) end def read(upid) moneta[upid] end def incr(upid, nr) status = moneta[upid] or return status.seen += nr if status.seen >= 0 moneta.store(upid, status, OPT) end def finish(upid) status = moneta[upid] or return status.length ||= status.seen status.seen = status.length moneta.store(upid, status, OPT) end def error!(upid) status = moneta[upid] or return status.seen = -1 moneta.store(upid, status, OPT) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
upr-0.3.0 | lib/upr/monitor.rb |