diff options
Diffstat (limited to 'examples/rails_app-2.3.4/app/models/upr_status.rb')
-rw-r--r-- | examples/rails_app-2.3.4/app/models/upr_status.rb | 35 |
1 files changed, 35 insertions, 0 deletions
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 new file mode 100644 index 0000000..81031c2 --- /dev/null +++ b/examples/rails_app-2.3.4/app/models/upr_status.rb @@ -0,0 +1,35 @@ +class UprStatus < ActiveRecord::Base + cattr_accessor :gc_cutoff + @@gc_cutoff = 10 + + class << self + def read(upid) + if rv = find_by_upid(upid) + rv.time = Time.now.to_i + rv.save + rv + end + end + + def start(upid, length) + # this must be a find_or_create_by since some users have twitchy + # fingers and hit the upload button prematurely + find_or_create_by_upid(upid) do |x| + x.length = length + x.time = Time.now.to_i + x.seen = 0 + end + end + + def incr(upid, nr) + update_all("seen = seen + #{nr.to_i}, time = #{Time.now.to_i}", + { :upid => upid }) + end + + def gc + cutoff = Time.now.to_i - @@gc_cutoff + delete_all "time < #{cutoff}" + end + end + +end |