Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump sidekiq from 6.5.12 to 7.3.7 #2533

Merged
merged 9 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ gem "sass-rails", "~> 6.0"
gem "sentry-rails"
gem "sentry-ruby"
gem "shell-spinner"
gem "sidekiq", "<7"
gem "sidekiq", "<8"
gem "slim-rails", "~> 3.6"
gem "sprockets", "~> 4.2.1"

Expand Down
15 changes: 9 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ GEM
kaminari-core (1.2.2)
language_server-protocol (3.17.0.3)
libreconv (0.9.5)
logger (1.6.4)
lograge (0.12.0)
actionpack (>= 4)
activesupport (>= 4)
Expand Down Expand Up @@ -435,7 +436,8 @@ GEM
rdoc (6.7.0)
psych (>= 4.0.0)
recursive-open-struct (1.2.2)
redis (4.8.1)
redis-client (0.23.0)
connection_pool
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
Expand Down Expand Up @@ -539,10 +541,11 @@ GEM
colorize
shoulda-matchers (5.1.0)
activesupport (>= 5.2.0)
sidekiq (6.5.12)
connection_pool (>= 2.2.5, < 3)
rack (~> 2.0)
redis (>= 4.5.0, < 5)
sidekiq (7.3.7)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.22.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -688,7 +691,7 @@ DEPENDENCIES
sentry-ruby
shell-spinner
shoulda-matchers (~> 5.1)
sidekiq (< 7)
sidekiq (< 8)
simplecov
simplecov-json
site_prism (< 5.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/heartbeat_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def healthcheck
private

def redis_alive?
Sidekiq.redis_info
Sidekiq.redis(&:info)
true
rescue StandardError
false
Expand Down
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 { |r| r.set(report_guid, data, ex: 7.days.to_i) }

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 { |r| r.exists(report.guid).positive? }
report.status = Stats::BaseReport::COMPLETE
report.save!
redis.get(report.guid)
Sidekiq.redis { |r| r.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 { |r| r.set(report_job_guid, @stats.stats.to_json, ex: 7.days.to_i) }
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 { |r| r.exists(job_id).positive? }
data_collector << Sidekiq.redis { |r| r.get(job_id) }
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/db/database_anonymizer_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def execute_task(task_name, task_arguments)
end

def store_anonymise_status(task_arguments, tasks)
redis = Redis.new
tasks_ids = tasks.map { |task| task[:task_id] }
anonymizer_job_info = {
"start_time": task_arguments[:timestamp],
Expand All @@ -35,7 +34,7 @@ def store_anonymise_status(task_arguments, tasks)
"tasks": tasks_ids,
}
anonymizer_job_id = "anonymizer_job_#{task_arguments[:tag]}_#{Time.zone.today.strftime('%Y%m%d')}"
redis.set(anonymizer_job_id, anonymizer_job_info.to_json, ex: 7.days)
Sidekiq.redis { |r| r.set(anonymizer_job_id, anonymizer_job_info.to_json, ex: 7.days.to_i) }
end

private
Expand Down
9 changes: 0 additions & 9 deletions sidekiq_admin.ru

This file was deleted.

8 changes: 6 additions & 2 deletions spec/controllers/heartbeat_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
end

describe "#healthcheck" do
let(:redis) { double("Redis") } # rubocop:disable RSpec/VerifiedDoubles

before do
retry_set = instance_double(Sidekiq::RetrySet, size: 0)
allow(Sidekiq::RetrySet).to receive(:new).and_return(retry_set)
Expand All @@ -28,7 +30,8 @@
allow(Sidekiq::ProcessSet).to receive(:new).and_return(process_set)
dead_set = instance_double(Sidekiq::DeadSet, size: 1)
allow(Sidekiq::DeadSet).to receive(:new).and_return(dead_set)
allow(Sidekiq).to receive(:redis_info).and_raise(Errno::ECONNREFUSED)
allow(Sidekiq).to receive(:redis).and_yield(redis)
allow(redis).to receive(:info).and_raise(Errno::ECONNREFUSED)
allow(ActiveRecord::Base.connection)
.to receive(:execute).and_raise(PG::ConnectionBad)

Expand All @@ -55,7 +58,8 @@
allow(Sidekiq::ProcessSet).to receive(:new).and_return(process_set)
dead_set = instance_double(Sidekiq::DeadSet, size: 0)
allow(Sidekiq::DeadSet).to receive(:new).and_return(dead_set)
allow(Sidekiq).to receive(:redis_info).and_return({})
allow(Sidekiq).to receive(:redis).and_yield(redis)
allow(redis).to receive(:info).and_return({})

get :healthcheck
end
Expand Down
187 changes: 95 additions & 92 deletions spec/services/stats/base_monthly_performance_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,100 +126,103 @@ def case_scope
end
end

describe "#process" do
it "creates data in Redis with an expiry" do
guid = SecureRandom.uuid
redis_double = instance_double(Redis)
allow(Redis).to receive(:new).and_return(redis_double)
expect(redis_double).to receive(:set).with(guid, anything, ex: 7.days)

new_report = DummyPerformanceReport.new(
report_type_id: find_or_create(:report_type, :r205).id,
period_start: @period_start,
period_end: @period_end,
)
new_report.process(0, report_job_guid: guid)
context "with redis" do
let(:redis) { double("Redis") } # rubocop:disable RSpec/VerifiedDoubles

before do
allow(Sidekiq).to receive(:redis).and_yield(redis)
allow(redis).to receive(:exists).and_return(1)
end
end

describe "#report_details" do
it "more months compared with period from stats data" do
redis_double = instance_double(Redis)
allow(Redis).to receive(:new).and_return(redis_double)

allow(redis_double).to receive(:exists?).and_return(true)
allow(redis_double).to receive(:get).and_return(
'{"201811":
{"month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":30,
"non_trigger_open_late":5,
"trigger_performance":0,
"trigger_total":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":30,
"overall_open_late":5},
"201812":
{ "month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":20,
"non_trigger_open_late":10,
"trigger_performance":0,
"trigger_total":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":20,
"overall_open_late":10},
"total":
{ "month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":0,
"non_trigger_open_late":0,
"trigger_performance":0,
"trigger_total":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":50,
"overall_open_late":15}}',
)
new_report = Report.new(
report_type_id: find_or_create(:report_type, :r205).id,
period_start: @period_start,
period_end: @period_end,
)
new_report.job_ids = %w[job1]
result_data = JSON.parse(@report.report_details(new_report))
expect(result_data.key?("201812")).to eq true
expect(result_data.key?("total")).to eq true
expect(result_data.key?("201811")).to eq false
describe "#process" do
it "creates data in Redis with an expiry" do
guid = SecureRandom.uuid
expect(redis).to receive(:set).with(guid, anything, ex: 7.days.to_i)

new_report = DummyPerformanceReport.new(
report_type_id: find_or_create(:report_type, :r205).id,
period_start: @period_start,
period_end: @period_end,
)
new_report.process(0, report_job_guid: guid)
end
end

describe "#report_details" do
it "more months compared with period from stats data" do
allow(redis).to receive(:get).and_return(
'{"201811":
{"month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":30,
"non_trigger_open_late":5,
"trigger_performance":0,
"trigger_total":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":30,
"overall_open_late":5},
"201812":
{ "month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":20,
"non_trigger_open_late":10,
"trigger_performance":0,
"trigger_total":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":20,
"overall_open_late":10},
"total":
{ "month":0,
"non_trigger_performance":0,
"non_trigger_total":0,
"non_trigger_responded_in_time":0,
"non_trigger_responded_late":0,
"non_trigger_open_in_time":0,
"non_trigger_open_late":0,
"trigger_performance":0,
"trigger_total":0,
"trigger_open_in_time":0,
"trigger_open_late":0,
"trigger_responded_in_time":0,
"trigger_responded_late":0,
"overall_performance":0,
"overall_total":0,
"overall_responded_in_time":0,
"overall_responded_late":0,
"overall_open_in_time":50,
"overall_open_late":15}}',
)
new_report = Report.new(
report_type_id: find_or_create(:report_type, :r205).id,
period_start: @period_start,
period_end: @period_end,
)
new_report.job_ids = %w[job1]
result_data = JSON.parse(@report.report_details(new_report))
expect(result_data.key?("201812")).to eq true
expect(result_data.key?("total")).to eq true
expect(result_data.key?("201811")).to eq false
end
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions spec/services/stats/r007_closed_cases_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,18 @@ 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(Sidekiq).to receive(:redis).and_yield(redis)
allow(redis).to receive(:exists).with(report.guid).and_return(exists)
allow(redis).to receive(:get).with(report.guid).and_return(data)
end

context "when data is in redis" do
let(:exists) { true }
let(:exists) { 1 }

it "sets the report as complete" do
expect {
Expand All @@ -121,7 +121,7 @@ module Stats
end

context "when data is not in redis" do
let(:exists) { false }
let(:exists) { 0 }

it "doesn't change the report status" do
expect {
Expand Down
Loading