File tree Expand file tree Collapse file tree 7 files changed +33
-13
lines changed Expand file tree Collapse file tree 7 files changed +33
-13
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ module NotifyThrottlingConcern
4
+ extend ActiveSupport ::Concern
5
+
6
+ include Sidekiq ::Job
7
+ include Sidekiq ::Throttled ::Job
8
+
9
+ included do
10
+ self . queue_adapter = :sidekiq unless Rails . env . test?
11
+
12
+ sidekiq_throttle_as :notify
13
+
14
+ queue_as :notifications
15
+ end
16
+ end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
class EmailDeliveryJob < NotifyDeliveryJob
4
+ include NotifyThrottlingConcern
5
+
4
6
def perform (
5
7
template_name ,
6
8
consent : nil ,
Original file line number Diff line number Diff line change 3
3
require "notifications/client"
4
4
5
5
class NotifyDeliveryJob < ApplicationJob
6
- self . queue_adapter = :sidekiq unless Rails . env . test?
7
-
8
- queue_as :notifications
9
-
10
- retry_on Notifications ::Client ::ServerError , wait : :polynomially_longer
11
-
12
6
def self . client
13
7
@client ||=
14
8
Notifications ::Client . new (
@@ -20,13 +14,9 @@ def self.deliveries
20
14
@deliveries ||= [ ]
21
15
end
22
16
23
- def self . send_via_notify?
24
- Settings . govuk_notify &.enabled
25
- end
17
+ def self . send_via_notify? = Settings . govuk_notify &.enabled
26
18
27
- def self . send_via_test?
28
- Rails . env . test?
29
- end
19
+ def self . send_via_test? = Rails . env . test?
30
20
31
21
class UnknownTemplate < StandardError
32
22
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
class SMSDeliveryJob < NotifyDeliveryJob
4
+ include NotifyThrottlingConcern
5
+
4
6
def perform (
5
7
template_name ,
6
8
consent : nil ,
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
- class StatusUpdaterJob < NotifyDeliveryJob
3
+ class StatusUpdaterJob < ApplicationJob
4
4
include GoodJob ::ActiveJobExtensions ::Concurrency
5
5
6
6
queue_as :statuses
Original file line number Diff line number Diff line change 18
18
config . cooldown_threshold = 1000
19
19
end
20
20
21
+ # https://docs.notifications.service.gov.uk/rest-api.html#rate-limits
22
+ Sidekiq ::Throttled ::Registry . add (
23
+ :notify ,
24
+ threshold : {
25
+ limit : Settings . govuk_notify . rate_limit_per_minute . to_i ,
26
+ period : 1 . minute
27
+ }
28
+ )
29
+
21
30
Sidekiq ::Throttled ::Registry . add (
22
31
:pds ,
23
32
threshold : {
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ govuk_notify:
28
28
team_key : <%= Rails.application.credentials.govuk_notify&.team_key %>
29
29
live_key : <%= Rails.application.credentials.govuk_notify&.live_key %>
30
30
callback_bearer_token : <%= Rails.application.credentials.govuk_notify&.callback_bearer_token %>
31
+ rate_limit_per_minute : 3000
31
32
32
33
nhs_api :
33
34
api_key : <%= Rails.application.credentials.nhs_api&.api_key %>
You can’t perform that action at this time.
0 commit comments