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

Additional logging and handling for missing schedule errors #406

Merged
merged 1 commit into from
May 22, 2024
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 db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/sidekiq_scheduler_backoff_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ def record_success
initial_interval = current_interval
target_interval = [initial_interval - 1, min_interval].max
restart_schedule(target_interval) if target_interval != initial_interval
rescue StandardError
notify_missing_schedule
end

def record_failure
initial_interval = current_interval
target_interval = [initial_interval * 2, max_interval].min
restart_schedule(target_interval) if target_interval != initial_interval
rescue StandardError
notify_missing_schedule
end

private
Expand All @@ -30,4 +34,11 @@ def restart_schedule(target_interval)
schedule = Sidekiq.get_schedule[name]
Sidekiq.set_schedule(name, schedule.merge("every" => "#{target_interval}s"))
end

def notify_missing_schedule
GovukError.notify(
"Queue schedule missing",
extra: { available_schedules: Sidekiq.get_schedule.keys },
)
end
end
18 changes: 18 additions & 0 deletions spec/lib/sidekiq_scheduler_backoff_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
expect(scheduled_interval).to eq("#{max_interval}s")
end
end

context "when the schedule is missing" do
subject { SidekiqSchedulerBackoffService.new(name: "non-existing-queue", min_interval:, max_interval:) }

it "records the problem to GovukError" do
expect(GovukError).to receive(:notify)
subject.record_failure
end
end
end

describe "#record_success" do
Expand Down Expand Up @@ -96,6 +105,15 @@
expect(scheduled_interval).to eq("#{max_interval}s")
end
end

context "when the schedule is missing" do
subject { SidekiqSchedulerBackoffService.new(name: "non-existing-queue", min_interval:, max_interval:) }

it "records the problem to GovukError" do
expect(GovukError).to receive(:notify)
subject.record_success
end
end
end
end

Expand Down