From a3977a51ae30fd2856c969e2e7897535715d19c6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 11 Nov 2009 15:41:44 -0800 Subject: monitor: add "finish" method This lets us finish up connections by setting seen == length when the client is finished uploading. --- examples/rails_app-2.3.4/app/models/upr_status.rb | 12 ++++++++++++ lib/upr/monitor.rb | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/examples/rails_app-2.3.4/app/models/upr_status.rb b/examples/rails_app-2.3.4/app/models/upr_status.rb index 81031c2..61d39bc 100644 --- a/examples/rails_app-2.3.4/app/models/upr_status.rb +++ b/examples/rails_app-2.3.4/app/models/upr_status.rb @@ -26,6 +26,18 @@ class UprStatus < ActiveRecord::Base { :upid => upid }) end + def finish(upid) + transaction do + if rv = find_by_upid(upid) + rv.time = Time.now.to_i + rv.length ||= rv.seen + rv.seen = rv.length + rv.save + rv + end + end + end + def gc cutoff = Time.now.to_i - @@gc_cutoff delete_all "time < #{cutoff}" diff --git a/lib/upr/monitor.rb b/lib/upr/monitor.rb index d1955f9..2ccb447 100644 --- a/lib/upr/monitor.rb +++ b/lib/upr/monitor.rb @@ -37,5 +37,12 @@ module Upr moneta.store(upid, status, OPT) end + def finish(upid) + status = moneta[upid] + status.length ||= status.seen + status.seen = status.length + moneta.store(upid, status, OPT) + end + end end -- cgit v1.2.3-24-ge0c7