about summary refs log blame commit diff
path: root/app/lib/activity_tracker.rb
blob: ae3c11b6af5c99e6f852f2ac8d284218839184ed (plain) (tree)
1
2
3
4
5
6
7
8




                                
                     









                                            
                                     


           



                           
# frozen_string_literal: true

class ActivityTracker
  EXPIRE_AFTER = 90.days.seconds

  class << self
    include Redisable

    def increment(prefix)
      key = [prefix, current_week].join(':')

      redis.incrby(key, 1)
      redis.expire(key, EXPIRE_AFTER)
    end

    def record(prefix, value)
      key = [prefix, current_week].join(':')

      redis.pfadd(key, value)
      redis.expire(key, EXPIRE_AFTER)
    end

    private

    def current_week
      Time.zone.today.cweek
    end
  end
end