Skip to content

Commit

Permalink
Hardcode expected date format so we don't depend on global state, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Jul 14, 2015
1 parent 4433e68 commit 5133344
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/sidekiq/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,15 @@ def date_stat_hash(stat)

while i < @days_previous
date = @start_date - i
keys << "stat:#{stat}:#{date}"
dates << date
datestr = date.strftime("%Y-%m-%d".freeze)
keys << "stat:#{stat}:#{datestr}"
dates << datestr
i += 1
end

Sidekiq.redis do |conn|
conn.mget(keys).each_with_index do |value, idx|
stat_hash[dates[idx].to_s] = value ? value.to_i : 0
stat_hash[dates[idx]] = value ? value.to_i : 0
end
end

Expand Down
6 changes: 6 additions & 0 deletions test/test_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ class TestApi < Sidekiq::Test

describe "stats" do
before do
@before = DateTime::DATE_FORMATS[:default]
DateTime::DATE_FORMATS[:default] = "%d/%m/%Y %H:%M:%S"
Sidekiq.redis = REDIS
Sidekiq.redis {|c| c.flushdb }
end

after do
DateTime::DATE_FORMATS[:default] = @before
end

describe "processed" do
it "is initially zero" do
s = Sidekiq::Stats.new
Expand Down

0 comments on commit 5133344

Please sign in to comment.