adzap-ar_mailer 2.1.8 → 2.1.9
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.
- data/History.txt +5 -0
- data/README.rdoc +58 -0
- data/lib/action_mailer/ar_sendmail.rb +71 -9
- data/share/linux/ar_sendmail +6 -1
- metadata +37 -13
data/History.txt
CHANGED
data/README.rdoc
CHANGED
|
@@ -118,6 +118,64 @@ be loaded, so you don't need another TLS plugin to add the capability. This
|
|
|
118
118
|
patch allows you to explicit set if the server supports TLS by setting the
|
|
119
119
|
:tls option to true in your smtp_settings.
|
|
120
120
|
|
|
121
|
+
|
|
122
|
+
=== EXPERIMENTAL: Minimal environment loading
|
|
123
|
+
|
|
124
|
+
The biggest downside to using ar_mailer is that it loads the entire Rails app
|
|
125
|
+
into memory. For larger apps this can be just a whole lot of wasted memory
|
|
126
|
+
given all you need is to access the email table and mailer settings. We can
|
|
127
|
+
get around this using a few conventions and save around 50% or more of the
|
|
128
|
+
memory used when loading the full app.
|
|
129
|
+
|
|
130
|
+
Loading the database is not much of a problem since the config sits in its own
|
|
131
|
+
yaml which is easy to load in isolation from the app. The mailer settings are
|
|
132
|
+
trickier since they are usually in the environment file which depends on loading
|
|
133
|
+
the Railties system and therefore the whole app.
|
|
134
|
+
|
|
135
|
+
To workaround for this we need to put all the SMTP settings in a yaml config
|
|
136
|
+
file like the database settings. Like so
|
|
137
|
+
|
|
138
|
+
in config/email.yml
|
|
139
|
+
|
|
140
|
+
development:
|
|
141
|
+
domain: example.com
|
|
142
|
+
address: smtp.example.com
|
|
143
|
+
port: 25
|
|
144
|
+
|
|
145
|
+
production:
|
|
146
|
+
domain: example.com
|
|
147
|
+
address: smtp.example.com
|
|
148
|
+
port: 25
|
|
149
|
+
|
|
150
|
+
You can still have ActionMailer settings in each environment file but just be sure
|
|
151
|
+
they don't override these SMTP settings. The other settings aren't needed when
|
|
152
|
+
running ar_sendmail since they only apply to the generation of an email which has
|
|
153
|
+
already happened inside the running application.
|
|
154
|
+
|
|
155
|
+
To avoid duplication of these settings you need to have an initializer which will
|
|
156
|
+
will read the same config file and load these settings. This is in case you switch
|
|
157
|
+
back the normal environment loading. Keeping the email settings here is good idea,
|
|
158
|
+
since just the like the database, they are external connection settings being stored
|
|
159
|
+
in the config folder.
|
|
160
|
+
|
|
161
|
+
The initializer in config/initializers/action_mailer.rb:
|
|
162
|
+
|
|
163
|
+
config_file = "#{Rails.root}/config/email.yml"
|
|
164
|
+
mailer_options = YAML::load(ERB.new(IO.read(config_file)).result)
|
|
165
|
+
if mailer_options[Rails.env]
|
|
166
|
+
ActionMailer::Base.smtp_settings = mailer_options[Rails.env].symbolize_keys
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
At the moment if you are using a database driver that doesn't come with Rails, the gem
|
|
170
|
+
will need to be installed on the target system.
|
|
171
|
+
|
|
172
|
+
Now to run ar_sendmail with minimal environment we do:
|
|
173
|
+
|
|
174
|
+
ar_sendmail -e production -c /path/to/app --minimal
|
|
175
|
+
|
|
176
|
+
If you have any troubles or find any bad assumptions in the minimal set up let me know.
|
|
177
|
+
|
|
178
|
+
|
|
121
179
|
=== Help
|
|
122
180
|
|
|
123
181
|
See ar_sendmail -h for options to ar_sendmail.
|
|
@@ -39,10 +39,13 @@ module ActionMailer; end
|
|
|
39
39
|
|
|
40
40
|
class ActionMailer::ARSendmail
|
|
41
41
|
|
|
42
|
+
class RailsEnvironmentFailed < StandardError; end
|
|
43
|
+
class MinimalEnvironmentFailed < StandardError; end
|
|
44
|
+
|
|
42
45
|
##
|
|
43
46
|
# The version of ActionMailer::ARSendmail you are running.
|
|
44
47
|
|
|
45
|
-
VERSION = '2.1.
|
|
48
|
+
VERSION = '2.1.9'
|
|
46
49
|
|
|
47
50
|
##
|
|
48
51
|
# Maximum number of times authentication will be consecutively retried
|
|
@@ -148,6 +151,7 @@ class ActionMailer::ARSendmail
|
|
|
148
151
|
options[:Once] = false
|
|
149
152
|
options[:RailsEnv] = ENV['RAILS_ENV']
|
|
150
153
|
options[:Pidfile] = options[:Chdir] + '/log/ar_sendmail.pid'
|
|
154
|
+
options[:Minimal] = false
|
|
151
155
|
|
|
152
156
|
opts = OptionParser.new do |opts|
|
|
153
157
|
opts.banner = "Usage: #{name} [options]"
|
|
@@ -194,6 +198,12 @@ class ActionMailer::ARSendmail
|
|
|
194
198
|
options[:Daemon] = true
|
|
195
199
|
end
|
|
196
200
|
|
|
201
|
+
opts.on( "--minimal",
|
|
202
|
+
"Load a minimal environment with settings from config/email.yml",
|
|
203
|
+
"Default: #{options[:Minimal]}") do |minimal|
|
|
204
|
+
options[:Minimal] = true
|
|
205
|
+
end
|
|
206
|
+
|
|
197
207
|
opts.on("-p", "--pidfile PIDFILE",
|
|
198
208
|
"Set the pidfile location",
|
|
199
209
|
"Default: #{options[:Chdir]}#{options[:Pidfile]}", String) do |pidfile|
|
|
@@ -247,21 +257,73 @@ class ActionMailer::ARSendmail
|
|
|
247
257
|
|
|
248
258
|
ENV['RAILS_ENV'] = options[:RailsEnv]
|
|
249
259
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
rescue LoadError
|
|
255
|
-
usage opts, <<-EOF
|
|
260
|
+
begin
|
|
261
|
+
options[:Minimal] ? load_minimal_environment(options[:Chdir]) : load_rails_environment(options[:Chdir])
|
|
262
|
+
rescue RailsEnvironmentFailed
|
|
263
|
+
usage opts, <<-EOF
|
|
256
264
|
#{name} must be run from a Rails application's root to deliver email.
|
|
257
265
|
#{Dir.pwd} does not appear to be a Rails application root.
|
|
258
|
-
|
|
259
|
-
|
|
266
|
+
EOF
|
|
267
|
+
rescue MinimalEnvironmentFailed => e
|
|
268
|
+
usage opts, "Minimal environment loading has failed with error '#{e.message}'. Check minimal environment instructions or use the normal Rails environment loading."
|
|
260
269
|
end
|
|
261
270
|
|
|
262
271
|
return options
|
|
263
272
|
end
|
|
264
273
|
|
|
274
|
+
# Load full Rails environment
|
|
275
|
+
#
|
|
276
|
+
def self.load_rails_environment(base_path)
|
|
277
|
+
Dir.chdir(base_path) do
|
|
278
|
+
require 'config/environment'
|
|
279
|
+
require 'action_mailer/ar_mailer'
|
|
280
|
+
end
|
|
281
|
+
rescue LoadError
|
|
282
|
+
raise RailsEnvironmentFailed
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Load a minimal environment to save memory by not loading the entire Rails app.
|
|
286
|
+
# Requires a vendored Rails or bundler, and a mailer config at config/email.yml.
|
|
287
|
+
#
|
|
288
|
+
def self.load_minimal_environment(base_path)
|
|
289
|
+
Dir.chdir(base_path) do
|
|
290
|
+
Dir.glob('vendor/rails/*/lib').each { |dir| $:.unshift File.expand_path(dir) }
|
|
291
|
+
require 'yaml'
|
|
292
|
+
require 'erb'
|
|
293
|
+
require 'active_record'
|
|
294
|
+
require 'action_mailer'
|
|
295
|
+
require 'action_mailer/ar_mailer'
|
|
296
|
+
require 'app/models/email'
|
|
297
|
+
|
|
298
|
+
env = ENV['RAILS_ENV']
|
|
299
|
+
|
|
300
|
+
logger = ActiveSupport::BufferedLogger.new(File.join('log', "#{env}.log"))
|
|
301
|
+
logger.level = ActiveSupport::BufferedLogger.const_get((env == 'production' ? 'info' : 'debug').upcase)
|
|
302
|
+
ActiveRecord::Base.logger = ActionMailer::Base.logger = logger
|
|
303
|
+
|
|
304
|
+
db_config = read_config('config/database.yml')
|
|
305
|
+
ActiveRecord::Base.establish_connection db_config[env]
|
|
306
|
+
|
|
307
|
+
mailer_config = read_config('config/email.yml')
|
|
308
|
+
ActionMailer::Base.smtp_settings = mailer_config[env].symbolize_keys
|
|
309
|
+
end
|
|
310
|
+
rescue => e
|
|
311
|
+
raise MinimalEnvironmentFailed, e.message
|
|
312
|
+
end
|
|
313
|
+
def default_log_path
|
|
314
|
+
File.join(root_path, 'log', "#{environment}.log")
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def default_log_level
|
|
318
|
+
environment == 'production' ? :info : :debug
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Open yaml config file and parse with ERB
|
|
322
|
+
#
|
|
323
|
+
def self.read_config(file)
|
|
324
|
+
YAML::load(ERB.new(IO.read(file)).result)
|
|
325
|
+
end
|
|
326
|
+
|
|
265
327
|
##
|
|
266
328
|
# Processes +args+ and runs as appropriate
|
|
267
329
|
|
data/share/linux/ar_sendmail
CHANGED
|
@@ -29,7 +29,12 @@ def start(app, options)
|
|
|
29
29
|
switches = ""
|
|
30
30
|
options.each {|k, v| switches << " --#{k} #{v}"}
|
|
31
31
|
STDOUT.write "Starting mailer for #{app} in #{options['environment']} mode ... "
|
|
32
|
-
status =
|
|
32
|
+
status = nil
|
|
33
|
+
Dir.chdir(options.delete('chdir')) do
|
|
34
|
+
command = 'ar_sendmail'
|
|
35
|
+
command = 'bundle exec ' + command if File.exists?('Gemfile')
|
|
36
|
+
status = system("#{command} -d #{switches}") ? "started" : "failed"
|
|
37
|
+
end
|
|
33
38
|
puts status
|
|
34
39
|
end
|
|
35
40
|
|
metadata
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: adzap-ar_mailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 25
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 2
|
|
8
|
+
- 1
|
|
9
|
+
- 9
|
|
10
|
+
version: 2.1.9
|
|
5
11
|
platform: ruby
|
|
6
12
|
authors:
|
|
7
13
|
- Eric Hodel
|
|
@@ -10,29 +16,41 @@ autorequire:
|
|
|
10
16
|
bindir: bin
|
|
11
17
|
cert_chain: []
|
|
12
18
|
|
|
13
|
-
date:
|
|
19
|
+
date: 2011-11-09 00:00:00 +11:00
|
|
14
20
|
default_executable: ar_sendmail
|
|
15
21
|
dependencies:
|
|
16
22
|
- !ruby/object:Gem::Dependency
|
|
17
23
|
name: minitest
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
prerelease: false
|
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
26
|
+
none: false
|
|
21
27
|
requirements:
|
|
22
28
|
- - ">="
|
|
23
29
|
- !ruby/object:Gem::Version
|
|
30
|
+
hash: 3
|
|
31
|
+
segments:
|
|
32
|
+
- 1
|
|
33
|
+
- 5
|
|
34
|
+
- 0
|
|
24
35
|
version: 1.5.0
|
|
25
|
-
|
|
36
|
+
type: :development
|
|
37
|
+
version_requirements: *id001
|
|
26
38
|
- !ruby/object:Gem::Dependency
|
|
27
39
|
name: mocha
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
prerelease: false
|
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
42
|
+
none: false
|
|
31
43
|
requirements:
|
|
32
44
|
- - ">="
|
|
33
45
|
- !ruby/object:Gem::Version
|
|
46
|
+
hash: 43
|
|
47
|
+
segments:
|
|
48
|
+
- 0
|
|
49
|
+
- 9
|
|
50
|
+
- 8
|
|
34
51
|
version: 0.9.8
|
|
35
|
-
|
|
52
|
+
type: :development
|
|
53
|
+
version_requirements: *id002
|
|
36
54
|
description: Even delivering email to the local machine may take too long when you have to send hundreds of messages. ar_mailer allows you to store messages into the database for later delivery by a separate process, ar_sendmail.
|
|
37
55
|
email: adam.meehan@gmail.com
|
|
38
56
|
executables:
|
|
@@ -74,21 +92,27 @@ rdoc_options:
|
|
|
74
92
|
require_paths:
|
|
75
93
|
- lib
|
|
76
94
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
|
+
none: false
|
|
77
96
|
requirements:
|
|
78
97
|
- - ">="
|
|
79
98
|
- !ruby/object:Gem::Version
|
|
99
|
+
hash: 3
|
|
100
|
+
segments:
|
|
101
|
+
- 0
|
|
80
102
|
version: "0"
|
|
81
|
-
version:
|
|
82
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
none: false
|
|
83
105
|
requirements:
|
|
84
106
|
- - ">="
|
|
85
107
|
- !ruby/object:Gem::Version
|
|
108
|
+
hash: 3
|
|
109
|
+
segments:
|
|
110
|
+
- 0
|
|
86
111
|
version: "0"
|
|
87
|
-
version:
|
|
88
112
|
requirements: []
|
|
89
113
|
|
|
90
114
|
rubyforge_project: seattlerb
|
|
91
|
-
rubygems_version: 1.
|
|
115
|
+
rubygems_version: 1.5.2
|
|
92
116
|
signing_key:
|
|
93
117
|
specification_version: 3
|
|
94
118
|
summary: A two-phase delivery agent for ActionMailer
|