Skip to content

Commit

Permalink
Access redis via sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
vertism committed Jan 7, 2025
1 parent 05a0d87 commit c8c0214
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
8 changes: 3 additions & 5 deletions app/services/stats/base_closed_cases_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ def process(report_guid:)
report = Report.find_by(guid: report_guid)

# Put the generated report into Redis for consumption by web app
redis = Redis.new
data = nil
File.open(etl_handler.results_filepath, "r") { |f| data = f.read }
redis.set(report_guid, data, ex: 7.days)
Sidekiq.redis.set(report_guid, data, ex: 7.days)

if report
report.report_data = {
Expand Down Expand Up @@ -74,11 +73,10 @@ def run(**args)
end

def report_details(report)
redis = Redis.new
if redis.exists?(report.guid)
if Sidekiq.redis.exists?(report.guid)
report.status = Stats::BaseReport::COMPLETE
report.save!
redis.get(report.guid)
Sidekiq.redis.get(report.guid)
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions app/services/stats/base_monthly_performance_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def process(offset, report_job_guid: nil, record_limit: ROWS_PER_FRAGMENT)
.each { |kase| analyse_case(kase) }

unless report_job_guid.nil?
redis = Redis.new
redis.set(report_job_guid, @stats.stats.to_json, ex: 7.days)
Sidekiq.redis.set(report_job_guid, @stats.stats.to_json, ex: 7.days)
end
end

Expand Down Expand Up @@ -102,11 +101,10 @@ def to_csv

# This function is only when the report is done via ETL (tasks)
def report_details(report)
redis = Redis.new
data_collector = []
report.job_ids.each do |job_id|
if redis.exists?(job_id)
data_collector << redis.get(job_id)
if Sidekiq.redis.exists?(job_id)
data_collector << Sidekiq.redis.get(job_id)
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/services/stats/r007_closed_cases_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ module Stats
end

describe "#report_details" do
let(:redis) { instance_double(Redis) }
let(:redis) { double("Redis") } # rubocop:disable RSpec/VerifiedDoubles
let(:report) { create(:report) }
let(:data) { "some data" }

before do
allow(Redis).to receive(:new).and_return(redis)
allow(redis).to receive(:exists?).with(report.guid).and_return(exists)
allow(redis).to receive(:get).with(report.guid).and_return(data)
allow(Sidekiq).to receive(:redis).and_return(redis)
allow(Sidekiq.redis).to receive(:exists?).with(report.guid).and_return(exists)
allow(Sidekiq.redis).to receive(:get).with(report.guid).and_return(data)
end

context "when data is in redis" do
Expand Down

0 comments on commit c8c0214

Please sign in to comment.