Created
December 30, 2014 10:18
-
-
Save gaurish/2982e526005619a81ea2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReceiptStatRefresh | |
include Sidekiq::Worker | |
START_TIME = '25-Dec-2014 3:30 IST' | |
END_TIME = '29-Dec-2014 5:30 IST' | |
def perform_async | |
RemoteReceipt.where(created_at: Time.parse(START_TIME)..Time.parse(START_TIME)).find_each do |receipt| | |
next if receipt.nil? | |
next if receipt.created_at.nil? | |
bump_stat(receipt) | |
end | |
end | |
private | |
def bump_stat(receipt) | |
receipt_time = receipt.created_at | |
current_hour = receipt_time.strftime("%Y_%m_%d_%H") | |
current_day = receipt_time.strftime("%Y_%m_%d") | |
current_month = receipt_time.strftime("%Y_%m") | |
redis.multi do |multi| | |
amt_in_cents = ((receipt.amount || 0.0).to_f*100.0).round(2).to_i | |
"BZLM:#{receipt.business_id}:#{receipt.location_id}:#{current_month}", | |
"BZD:#{receipt.business_id}:#{current_day}"].each do |count_key| | |
multi.sadd("C#{count_key}",key) | |
multi.zadd("S#{count_key}",amt_in_cents,key) | |
end | |
end | |
end | |
end | |
def redis | |
$isl_master_redis | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment