actionmailer-balancer 1.2.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +55 -43
- data/README.md +40 -0
- data/lib/actionmailer/balancer/delivery_method.rb +51 -16
- data/lib/actionmailer/balancer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31b0398b89e3cd5701358f565f74d7f38d1d2a29dfeb1bf6844d35c032a875f1
|
|
4
|
+
data.tar.gz: cb51555f81e1a0d9afab8bfbfef9af54f4a46c7f1a71de03c677ca9ee1038b3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3b2ba56df40593989425eebb058f3e98827bf117b25b0cd092bce9718366e42ce9fcbff7f37cb586ee78fd10219ba42f8bc4912a6f7514231ec65e6f94000b4
|
|
7
|
+
data.tar.gz: 007c96c0664751a74a48bd4b1e89b6e7c1cf9e373ae4f84714649cab32b2d9fa7765710d052ec5bb6cb83a8f67c233cc39d36cdd27939c67870c10b9d185da5e
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.3.0] - 2026-11-19
|
|
2
|
+
|
|
3
|
+
## What's Changed
|
|
4
|
+
* Bump crass from 1.0.7 to 1.0.8 by @dependabot[bot] in https://github.com/mailtrap/actionmailer-balancer/pull/70
|
|
5
|
+
* Fix double callbacks and validate balancer settings by @SergeyKorolev in https://github.com/mailtrap/actionmailer-balancer/pull/66
|
|
6
|
+
* Update development dependencies to patched versions by @mklocek in https://github.com/mailtrap/actionmailer-balancer/pull/72
|
|
7
|
+
|
|
8
|
+
## New Contributors
|
|
9
|
+
* @SergeyKorolev made their first contribution in https://github.com/mailtrap/actionmailer-balancer/pull/66
|
|
10
|
+
|
|
11
|
+
**Full Changelog**: https://github.com/mailtrap/actionmailer-balancer/compare/v1.2.3...v1.3.0
|
|
12
|
+
|
|
13
|
+
## [1.2.3] - 2026-11-12
|
|
14
|
+
|
|
15
|
+
## What's Changed
|
|
16
|
+
* Bump rails-html-sanitizer from 1.7.0 to 1.7.1 by @dependabot[bot] in https://github.com/mailtrap/actionmailer-balancer/pull/63
|
|
17
|
+
* Bump loofah from 2.25.1 to 2.25.2 by @dependabot[bot] in https://github.com/mailtrap/actionmailer-balancer/pull/62
|
|
18
|
+
* Bump mail from 2.8.1 to 2.9.1 by @dependabot[bot] in https://github.com/mailtrap/actionmailer-balancer/pull/64
|
|
19
|
+
* run CI on pull requests by @oshchyhol in https://github.com/mailtrap/actionmailer-balancer/pull/65
|
|
20
|
+
* Test against the latest patch of each Ruby by @IgorDobryn in https://github.com/mailtrap/actionmailer-balancer/pull/69
|
|
21
|
+
* Bump rack from 3.2.6 to 3.2.8 by @dependabot[bot] in https://github.com/mailtrap/actionmailer-balancer/pull/67
|
|
22
|
+
* Add release workflow by @IgorDobryn in https://github.com/mailtrap/actionmailer-balancer/pull/68
|
|
23
|
+
|
|
24
|
+
## New Contributors
|
|
25
|
+
* @oshchyhol made their first contribution in https://github.com/mailtrap/actionmailer-balancer/pull/65
|
|
26
|
+
|
|
27
|
+
**Full Changelog**: https://github.com/mailtrap/actionmailer-balancer/compare/v1.2.2...v1.2.3
|
|
28
|
+
|
|
1
29
|
## [1.2.2] - 2026-07-02
|
|
2
30
|
|
|
3
31
|
## What's Changed
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,115 +1,123 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
actionmailer-balancer (1.
|
|
4
|
+
actionmailer-balancer (1.3.0)
|
|
5
5
|
actionmailer (> 4.0)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
actionmailer (
|
|
11
|
-
actionpack (=
|
|
12
|
-
actionview (=
|
|
13
|
-
activejob (=
|
|
14
|
-
activesupport (=
|
|
10
|
+
actionmailer (8.1.4.1)
|
|
11
|
+
actionpack (= 8.1.4.1)
|
|
12
|
+
actionview (= 8.1.4.1)
|
|
13
|
+
activejob (= 8.1.4.1)
|
|
14
|
+
activesupport (= 8.1.4.1)
|
|
15
15
|
mail (>= 2.8.0)
|
|
16
16
|
rails-dom-testing (~> 2.2)
|
|
17
|
-
actionpack (
|
|
18
|
-
actionview (=
|
|
19
|
-
activesupport (=
|
|
20
|
-
cgi
|
|
17
|
+
actionpack (8.1.4.1)
|
|
18
|
+
actionview (= 8.1.4.1)
|
|
19
|
+
activesupport (= 8.1.4.1)
|
|
21
20
|
nokogiri (>= 1.8.5)
|
|
22
|
-
|
|
23
|
-
rack (>= 2.2.4, < 3.3)
|
|
21
|
+
rack (>= 2.2.4)
|
|
24
22
|
rack-session (>= 1.0.1)
|
|
25
23
|
rack-test (>= 0.6.3)
|
|
26
24
|
rails-dom-testing (~> 2.2)
|
|
27
25
|
rails-html-sanitizer (~> 1.6)
|
|
28
26
|
useragent (~> 0.16)
|
|
29
|
-
actionview (
|
|
30
|
-
activesupport (=
|
|
27
|
+
actionview (8.1.4.1)
|
|
28
|
+
activesupport (= 8.1.4.1)
|
|
31
29
|
builder (~> 3.1)
|
|
32
|
-
cgi
|
|
33
30
|
erubi (~> 1.11)
|
|
34
31
|
rails-dom-testing (~> 2.2)
|
|
35
|
-
rails-html-sanitizer (~> 1.6)
|
|
36
|
-
activejob (
|
|
37
|
-
activesupport (=
|
|
32
|
+
rails-html-sanitizer (~> 1.6, >= 1.7.2)
|
|
33
|
+
activejob (8.1.4.1)
|
|
34
|
+
activesupport (= 8.1.4.1)
|
|
38
35
|
globalid (>= 0.3.6)
|
|
39
|
-
activesupport (
|
|
36
|
+
activesupport (8.1.4.1)
|
|
40
37
|
base64
|
|
41
|
-
benchmark (>= 0.3)
|
|
42
38
|
bigdecimal
|
|
43
39
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
44
40
|
connection_pool (>= 2.2.5)
|
|
45
41
|
drb
|
|
46
42
|
i18n (>= 1.6, < 2)
|
|
43
|
+
json
|
|
47
44
|
logger (>= 1.4.2)
|
|
48
|
-
minitest (>= 5.1
|
|
45
|
+
minitest (>= 5.1)
|
|
49
46
|
securerandom (>= 0.3)
|
|
50
47
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
48
|
+
uri (>= 0.13.1)
|
|
51
49
|
ast (2.4.2)
|
|
52
50
|
base64 (0.3.0)
|
|
53
51
|
benchmark (0.5.0)
|
|
54
|
-
bigdecimal (4.
|
|
52
|
+
bigdecimal (4.1.3)
|
|
55
53
|
builder (3.3.0)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
date (3.5.1)
|
|
54
|
+
concurrent-ruby (1.3.8)
|
|
55
|
+
connection_pool (3.0.3)
|
|
56
|
+
crass (1.0.8)
|
|
57
|
+
date (3.6.0)
|
|
61
58
|
diff-lcs (1.5.1)
|
|
62
59
|
drb (2.2.3)
|
|
63
60
|
erubi (1.13.1)
|
|
64
|
-
globalid (1.
|
|
61
|
+
globalid (1.4.0)
|
|
65
62
|
activesupport (>= 6.1)
|
|
66
|
-
i18n (1.
|
|
63
|
+
i18n (1.15.2)
|
|
67
64
|
concurrent-ruby (~> 1.0)
|
|
68
65
|
json (2.7.2)
|
|
69
66
|
language_server-protocol (3.17.0.3)
|
|
70
67
|
logger (1.7.0)
|
|
71
|
-
loofah (2.25.
|
|
68
|
+
loofah (2.25.3)
|
|
72
69
|
crass (~> 1.0.2)
|
|
73
|
-
nokogiri (>= 1.
|
|
74
|
-
mail (2.
|
|
70
|
+
nokogiri (>= 1.19.5)
|
|
71
|
+
mail (2.9.1)
|
|
72
|
+
logger
|
|
75
73
|
mini_mime (>= 0.1.1)
|
|
76
74
|
net-imap
|
|
77
75
|
net-pop
|
|
78
76
|
net-smtp
|
|
79
77
|
mini_mime (1.1.5)
|
|
80
78
|
mini_portile2 (2.8.9)
|
|
81
|
-
minitest (
|
|
82
|
-
|
|
79
|
+
minitest (6.1.0)
|
|
80
|
+
drb (~> 2.0)
|
|
81
|
+
prism (>= 1.5, < 3)
|
|
82
|
+
net-imap (0.6.8)
|
|
83
83
|
date
|
|
84
84
|
net-protocol
|
|
85
85
|
net-pop (0.1.2)
|
|
86
86
|
net-protocol
|
|
87
|
-
net-protocol (0.
|
|
87
|
+
net-protocol (0.4.0)
|
|
88
88
|
timeout
|
|
89
|
-
net-smtp (0.5.
|
|
89
|
+
net-smtp (0.5.2)
|
|
90
90
|
net-protocol
|
|
91
|
-
nokogiri (1.
|
|
91
|
+
nokogiri (1.19.7)
|
|
92
92
|
mini_portile2 (~> 2.8.2)
|
|
93
93
|
racc (~> 1.4)
|
|
94
|
-
nokogiri (1.
|
|
94
|
+
nokogiri (1.19.7-arm64-darwin)
|
|
95
|
+
racc (~> 1.4)
|
|
96
|
+
nokogiri (1.19.7-x86_64-darwin)
|
|
97
|
+
racc (~> 1.4)
|
|
98
|
+
nokogiri (1.19.7-x86_64-linux-gnu)
|
|
95
99
|
racc (~> 1.4)
|
|
96
100
|
parallel (1.26.2)
|
|
97
101
|
parser (3.3.4.2)
|
|
98
102
|
ast (~> 2.4.1)
|
|
99
103
|
racc
|
|
104
|
+
prism (2.1.0)
|
|
105
|
+
prism (2.1.0-arm64-darwin)
|
|
106
|
+
prism (2.1.0-x86_64-darwin)
|
|
107
|
+
prism (2.1.0-x86_64-linux-gnu)
|
|
100
108
|
racc (1.8.1)
|
|
101
|
-
rack (3.2.
|
|
109
|
+
rack (3.2.8)
|
|
102
110
|
rack-session (2.1.2)
|
|
103
111
|
base64 (>= 0.1.0)
|
|
104
112
|
rack (>= 3.0.0)
|
|
105
|
-
rack-test (2.
|
|
113
|
+
rack-test (2.3.0)
|
|
106
114
|
rack (>= 1.3)
|
|
107
115
|
rails-dom-testing (2.3.0)
|
|
108
116
|
activesupport (>= 5.0.0)
|
|
109
117
|
minitest
|
|
110
118
|
nokogiri (>= 1.6)
|
|
111
|
-
rails-html-sanitizer (1.7.
|
|
112
|
-
loofah (~> 2.25)
|
|
119
|
+
rails-html-sanitizer (1.7.2)
|
|
120
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
113
121
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
114
122
|
rainbow (3.1.1)
|
|
115
123
|
rake (13.2.1)
|
|
@@ -151,14 +159,18 @@ GEM
|
|
|
151
159
|
tzinfo (2.0.6)
|
|
152
160
|
concurrent-ruby (~> 1.0)
|
|
153
161
|
unicode-display_width (2.5.0)
|
|
162
|
+
uri (1.1.2)
|
|
154
163
|
useragent (0.16.11)
|
|
155
164
|
|
|
156
165
|
PLATFORMS
|
|
166
|
+
arm64-darwin
|
|
157
167
|
ruby
|
|
158
168
|
x86_64-darwin-20
|
|
169
|
+
x86_64-linux
|
|
159
170
|
|
|
160
171
|
DEPENDENCIES
|
|
161
172
|
actionmailer-balancer!
|
|
173
|
+
benchmark
|
|
162
174
|
mail
|
|
163
175
|
rake (~> 13.0)
|
|
164
176
|
rspec (~> 3.0)
|
|
@@ -167,4 +179,4 @@ DEPENDENCIES
|
|
|
167
179
|
rubocop-rspec
|
|
168
180
|
|
|
169
181
|
BUNDLED WITH
|
|
170
|
-
2.
|
|
182
|
+
2.7.2
|
data/README.md
CHANGED
|
@@ -61,6 +61,46 @@ end
|
|
|
61
61
|
|
|
62
62
|
Now, just use ActionMailer as usual, and mail will be auto-balanced.
|
|
63
63
|
|
|
64
|
+
### Mixing SMTP and API delivery methods
|
|
65
|
+
|
|
66
|
+
Delivery methods don't have to use SMTP. Any delivery method registered with ActionMailer works, including ones that send through a provider's HTTP API. For example, to keep 90% of mail on your current SMTP provider and move 10% to the [Mailtrap Email API](https://github.com/mailtrap/mailtrap-ruby#actionmailer):
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
# Gemfile
|
|
70
|
+
gem 'actionmailer-balancer'
|
|
71
|
+
gem 'mailtrap' # registers the :mailtrap delivery method
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
```ruby
|
|
75
|
+
Your::Application.configure do
|
|
76
|
+
config.action_mailer.delivery_method = :balancer
|
|
77
|
+
config.action_mailer.balancer_settings = {
|
|
78
|
+
delivery_methods: [
|
|
79
|
+
{
|
|
80
|
+
method: :smtp,
|
|
81
|
+
settings: {
|
|
82
|
+
address: 'smtp.example.com',
|
|
83
|
+
port: 587,
|
|
84
|
+
user_name: ENV.fetch('SMTP_USERNAME'),
|
|
85
|
+
password: ENV.fetch('SMTP_PASSWORD'),
|
|
86
|
+
authentication: :plain
|
|
87
|
+
},
|
|
88
|
+
weight: 90
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
method: :mailtrap,
|
|
92
|
+
settings: {
|
|
93
|
+
api_key: ENV.fetch('MAILTRAP_API_KEY')
|
|
94
|
+
},
|
|
95
|
+
weight: 10
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
end
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`settings` are passed to each delivery method as they are, so use the keys that method expects (for `:mailtrap`, see the [mailtrap gem](https://github.com/mailtrap/mailtrap-ruby#actionmailer)). To move more mail to the new provider, change the weights. A weight of `0` turns a delivery method off without removing its configuration.
|
|
103
|
+
|
|
64
104
|
## Development
|
|
65
105
|
|
|
66
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -3,19 +3,21 @@
|
|
|
3
3
|
module ActionMailer
|
|
4
4
|
module Balancer
|
|
5
5
|
class DeliveryMethod
|
|
6
|
-
attr_reader :delivery_methods, :weights_sum
|
|
6
|
+
attr_reader :settings, :delivery_methods, :weights_sum
|
|
7
7
|
|
|
8
8
|
def initialize(settings = {})
|
|
9
|
+
@settings = settings
|
|
9
10
|
add_delivery_methods(settings)
|
|
10
11
|
end
|
|
11
12
|
|
|
13
|
+
# Switches the message to the chosen delivery method, so observers can see
|
|
14
|
+
# which one was used, and delivers through it directly. Calling
|
|
15
|
+
# message.deliver! instead would run interceptors and observers a second
|
|
16
|
+
# time, since ActionMailer has already run them for this message.
|
|
12
17
|
def deliver!(message)
|
|
13
18
|
delivery_method = choose_delivery_method
|
|
14
|
-
message.delivery_method(
|
|
15
|
-
|
|
16
|
-
delivery_method[:settings] || {}
|
|
17
|
-
)
|
|
18
|
-
message.deliver!
|
|
19
|
+
message.delivery_method(delivery_class(delivery_method[:method]), delivery_method[:settings] || {})
|
|
20
|
+
message.delivery_method.deliver!(message)
|
|
19
21
|
end
|
|
20
22
|
|
|
21
23
|
private
|
|
@@ -24,30 +26,63 @@ module ActionMailer
|
|
|
24
26
|
validate_settings!(settings)
|
|
25
27
|
|
|
26
28
|
@delivery_methods = settings[:delivery_methods]
|
|
27
|
-
@weights_sum = delivery_methods.sum
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
@weights_sum = delivery_methods.sum { |method| method[:weight] }
|
|
30
|
+
# Weights near Float::MAX add up to Infinity or, with Array#sum's compensated summation, NaN.
|
|
31
|
+
# A huge Integer sum stays finite itself but turns into Infinity once rand scales it.
|
|
32
|
+
raise ActionMailer::Balancer::SettingsError, 'The sum of weights is too large' unless weights_sum.to_f.finite?
|
|
33
|
+
return if weights_sum.positive?
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
end
|
|
35
|
+
raise ActionMailer::Balancer::SettingsError, 'At least one delivery method must have a weight above 0'
|
|
34
36
|
end
|
|
35
37
|
|
|
36
38
|
def choose_delivery_method
|
|
37
|
-
target = rand
|
|
39
|
+
target = rand * weights_sum
|
|
38
40
|
delivery_methods.each do |method|
|
|
39
|
-
return method if target
|
|
41
|
+
return method if target < method[:weight]
|
|
40
42
|
|
|
41
43
|
target -= method[:weight]
|
|
42
44
|
end
|
|
45
|
+
# Float rounding can leave target just past the last weight.
|
|
46
|
+
delivery_methods.reverse.find { |method| method[:weight].positive? }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def delivery_class(name)
|
|
50
|
+
::ActionMailer::Base.delivery_methods.fetch(name.to_sym) do
|
|
51
|
+
raise ActionMailer::Balancer::SettingsError,
|
|
52
|
+
"Unknown delivery method #{name.inspect}, " \
|
|
53
|
+
"known methods: #{::ActionMailer::Base.delivery_methods.keys.map(&:inspect).join(", ")}"
|
|
54
|
+
end
|
|
43
55
|
end
|
|
44
56
|
|
|
45
57
|
def validate_settings!(settings)
|
|
46
58
|
raise ActionMailer::Balancer::SettingsError, 'No settings set' if settings.empty?
|
|
47
59
|
|
|
48
|
-
|
|
60
|
+
unless settings[:delivery_methods].is_a?(Array) && !settings[:delivery_methods].empty?
|
|
61
|
+
raise ActionMailer::Balancer::SettingsError, 'No delivery methods set'
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
settings[:delivery_methods].each { |method| validate_delivery_method!(method) }
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def validate_delivery_method!(method)
|
|
68
|
+
name = method[:method]
|
|
69
|
+
unless name.respond_to?(:to_sym)
|
|
70
|
+
raise ActionMailer::Balancer::SettingsError, 'No method set for delivery method'
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if delivery_class(name) <= DeliveryMethod
|
|
74
|
+
raise ActionMailer::Balancer::SettingsError, "Delivery method #{name} can't be a balancer itself"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
validate_weight!(name, method[:weight])
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def validate_weight!(name, weight)
|
|
81
|
+
raise ActionMailer::Balancer::SettingsError, "No weight set for delivery method #{name}" unless weight
|
|
82
|
+
return if weight.is_a?(Numeric) && weight.real? && weight.finite? && !weight.negative?
|
|
49
83
|
|
|
50
|
-
raise ActionMailer::Balancer::SettingsError,
|
|
84
|
+
raise ActionMailer::Balancer::SettingsError,
|
|
85
|
+
"Weight for delivery method #{name} must be a finite, non-negative number, got #{weight.inspect}"
|
|
51
86
|
end
|
|
52
87
|
end
|
|
53
88
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: actionmailer-balancer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Railsware Products Studio, Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionmailer
|