finish up pruning for stats

This commit is contained in:
Kyle Drake 2015-05-02 14:34:21 -07:00
parent 918231ea0f
commit 704011a1c0
6 changed files with 61 additions and 35 deletions

View file

@ -1,11 +1,15 @@
class StatPath < Sequel::Model
RETAINMENT_PERIOD = 7.days
RETAINMENT_DAYS = 7
many_to_one :site
def self.prune!
where{created_at < (RETAINMENT_DAYS-2).days.ago.to_date}.delete
end
def self.create_or_get(site_id, name)
opts = {site_id: site_id, name: name}
stat_path = where(opts).where{created_at > RETAINMENT_PERIOD.ago}.first
stat_path = where(opts).where{created_at > RETAINMENT_DAYS.days.ago}.first
DB[table_name].lock('EXCLUSIVE') {
stat_path = create opts.merge created_at: Date.today
} if stat_path.nil?