-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathsidekiq.rb
More file actions
99 lines (79 loc) · 2.5 KB
/
sidekiq.rb
File metadata and controls
99 lines (79 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# frozen_string_literal: true
require "sidekiq/throttled"
require "sidekiq-unique-jobs"
redis_config = { url: ENV["SIDEKIQ_REDIS_URL"] || ENV["REDIS_URL"] }
if Rails.env.production? || Rails.env.staging?
redis_config[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE }
redis_config[:timeout] = 10
end
Sidekiq.configure_server do |config|
config.redis = redis_config
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
config.server_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Server
chain.add(
Class.new do
def call(_worker, job, _queue)
execution_id = SecureRandom.urlsafe_base64(8)
SemanticLogger.tagged(execution_id:) do
Sentry.set_tags(execution_id:, jid: job["jid"])
yield
end
end
end
)
end
SidekiqUniqueJobs::Server.configure(config)
if ENV["EXPORT_SIDEKIQ_METRICS"] == "true"
require "prometheus_exporter/instrumentation"
config.server_middleware do |chain|
chain.add PrometheusExporter::Instrumentation::Sidekiq
end
config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
config.on :startup do
PrometheusExporter::Instrumentation::Process.start type: "sidekiq"
PrometheusExporter::Instrumentation::ActiveRecord.start
PrometheusExporter::Instrumentation::SidekiqProcess.start
# SidekiqStats and SidekiqQueue are global Redis-backed metrics published
# by the metrics task (bin/metrics-publisher) to avoid duplicate
# series across Sidekiq containers.
end
at_exit do
PrometheusExporter::Client.default.stop(wait_timeout_seconds: 10)
end
end
end
Sidekiq.configure_client do |config|
config.redis = redis_config
config.client_middleware do |chain|
chain.add SidekiqUniqueJobs::Middleware::Client
end
end
Sidekiq::Throttled.configure do |config|
config.cooldown_period = 1.0
config.cooldown_threshold = 1000
end
Sidekiq::Throttled::Registry.add(
:immunisations_api,
threshold: {
limit: Settings.immunisations_api.rate_limit_per_second.to_i,
period: 1.second
}
)
# https://docs.notifications.service.gov.uk/rest-api.html#rate-limits
Sidekiq::Throttled::Registry.add(
:govuk_notify,
threshold: {
limit: Settings.govuk_notify.rate_limit_per_second.to_i,
period: 1.second
}
)
Sidekiq::Throttled::Registry.add(
:pds,
threshold: {
limit: Settings.pds.rate_limit_per_second.to_i,
period: 1.second
}
)