Class: Upr::Monitor

Inherits:
Struct
  • Object
show all
Defined in:
lib/upr/monitor.rb

Overview

Keeps track of the status of all currently processing uploads This uses any 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

Constant Summary collapse

OPT =

nuke anything not read/updated in 60 seconds

{ :expires_in => 60 }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(moneta_store = nil) ⇒ Monitor

Returns a new instance of Monitor.



17
18
19
20
21
22
# File 'lib/upr/monitor.rb', line 17

def initialize(moneta_store = nil)
  super
  if moneta_store.nil?
    self.moneta = Moneta.new(:Memory, :serializer => nil)
  end
end

Instance Attribute Details

#monetaObject

Returns the value of attribute moneta

Returns:

  • (Object)

    the current value of moneta



13
14
15
# File 'lib/upr/monitor.rb', line 13

def moneta
  @moneta
end

Instance Method Details

#error!(upid) ⇒ Object



45
46
47
48
49
# File 'lib/upr/monitor.rb', line 45

def error!(upid)
  status = moneta[upid] or return
  status.seen = -1
  moneta.store(upid, status, OPT)
end

#finish(upid) ⇒ Object



38
39
40
41
42
43
# File 'lib/upr/monitor.rb', line 38

def finish(upid)
  status = moneta[upid] or return
  status.length ||= status.seen
  status.seen = status.length
  moneta.store(upid, status, OPT)
end

#incr(upid, nr) ⇒ Object



32
33
34
35
36
# File 'lib/upr/monitor.rb', line 32

def incr(upid, nr)
  status = moneta[upid] or return
  status.seen += nr if status.seen >= 0
  moneta.store(upid, status, OPT)
end

#read(upid) ⇒ Object



28
29
30
# File 'lib/upr/monitor.rb', line 28

def read(upid)
  moneta[upid]
end

#start(upid, length) ⇒ Object



24
25
26
# File 'lib/upr/monitor.rb', line 24

def start(upid, length)
  moneta.store(upid, Status.new(0, length), OPT)
end