mongo_mailer 0.0.0 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mongo_mailer might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/.gitignore +10 -13
- data/.travis.yml +6 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +112 -61
- data/README.md +112 -0
- data/Rakefile +7 -4
- data/bin/console +7 -0
- data/bin/mongo_mailer +11 -0
- data/bin/worker +6 -0
- data/config/boot.rb +12 -0
- data/config/mongo_mailer.yml.example +38 -0
- data/lib/generators/mongo_mailer/mongo_mailer_generator.rb +10 -0
- data/lib/generators/mongo_mailer/templates/mongo_mailer.yml +38 -0
- data/lib/mongo_mailer.rb +9 -2
- data/lib/mongo_mailer/capistrano.rb +33 -0
- data/lib/mongo_mailer/capistrano3.rb +49 -0
- data/lib/mongo_mailer/common/deliveries_counter.rb +18 -0
- data/lib/mongo_mailer/common/has_mongo_collection.rb +36 -0
- data/lib/mongo_mailer/common/mail_queue.rb +49 -0
- data/lib/mongo_mailer/configuration.rb +127 -0
- data/lib/mongo_mailer/core_ext/hash.rb +12 -0
- data/lib/mongo_mailer/delivery_methods/mongo_queue.rb +28 -0
- data/lib/mongo_mailer/delivery_methods/test.rb +38 -0
- data/lib/mongo_mailer/rails.rb +5 -0
- data/lib/mongo_mailer/standalone.rb +6 -0
- data/lib/mongo_mailer/standalone/final_deliverer.rb +35 -0
- data/lib/mongo_mailer/standalone/worker.rb +23 -0
- data/lib/mongo_mailer/version.rb +3 -0
- data/log/.gitkeep +0 -0
- data/mongo_mailer.gemspec +25 -26
- data/spec/lib/common/deliveries_counter_spec.rb +22 -0
- data/spec/lib/common/mail_queue_spec.rb +68 -0
- data/spec/lib/configuration_spec.rb +26 -0
- data/spec/lib/standalone/final_deliverer_spec.rb +40 -0
- data/spec/rails/delivery_methods/mongo_queue_spec.rb +33 -0
- data/spec/spec_helper.rb +29 -0
- metadata +97 -44
- data/LICENSE +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae32a268782ce6659964b4f2e4730c04daa55f77
|
4
|
+
data.tar.gz: f080335933a7bb536e31018fa5d0fb867b13f453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fde9a9f5b98b0ecf6df6024f98ea1a8e76700734bea9c104cb234dd29c3a3a04b9de0fd1b5be75523e969e6c2533dc49969b6ef62fe4b4e80d256b73a036cf7
|
7
|
+
data.tar.gz: 42f8b6b9d11754fd45a40d36de3d6cb5bfdaf9e0e621327a1fbeb3217c10a627aa2726937cbf643a9442c31504458299845ebe671f9cdbb6cdf0d126863ff38f
|
data/.gitignore
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
+
.rvmrc
|
2
|
+
.ruby-version
|
3
|
+
.ruby-gemset
|
1
4
|
*.gem
|
2
|
-
|
3
|
-
.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
pkg
|
10
|
-
rdoc
|
11
|
-
spec/reports
|
12
|
-
tmp
|
13
|
-
.coveralls.yml
|
14
|
-
spec/examples.txt
|
5
|
+
*.swp
|
6
|
+
.DS_Store
|
7
|
+
|
8
|
+
tmp/
|
9
|
+
log/
|
10
|
+
coverage/
|
11
|
+
config/*.yml
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,76 +1,127 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
mongo_mailer (0.
|
5
|
-
|
6
|
-
|
4
|
+
mongo_mailer (0.1.2)
|
5
|
+
activesupport (>= 4.2.8)
|
6
|
+
bson_ext (~> 1.9.2)
|
7
|
+
daemons (~> 1.1.9)
|
8
|
+
mail (~> 2.5.5)
|
9
|
+
mongo (~> 1.9.2)
|
7
10
|
|
8
11
|
GEM
|
9
|
-
remote:
|
12
|
+
remote: http://rubygems.org/
|
10
13
|
specs:
|
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
|
-
|
14
|
+
actionmailer (4.2.9)
|
15
|
+
actionpack (= 4.2.9)
|
16
|
+
actionview (= 4.2.9)
|
17
|
+
activejob (= 4.2.9)
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
19
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
20
|
+
actionpack (4.2.9)
|
21
|
+
actionview (= 4.2.9)
|
22
|
+
activesupport (= 4.2.9)
|
23
|
+
rack (~> 1.6)
|
24
|
+
rack-test (~> 0.6.2)
|
25
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
27
|
+
actionview (4.2.9)
|
28
|
+
activesupport (= 4.2.9)
|
29
|
+
builder (~> 3.1)
|
30
|
+
erubis (~> 2.7.0)
|
31
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
33
|
+
activejob (4.2.9)
|
34
|
+
activesupport (= 4.2.9)
|
35
|
+
globalid (>= 0.3.0)
|
36
|
+
activesupport (4.2.9)
|
37
|
+
i18n (~> 0.7)
|
38
|
+
minitest (~> 5.1)
|
39
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
40
|
+
tzinfo (~> 1.1)
|
41
|
+
bson (1.9.2)
|
42
|
+
bson_ext (1.9.2)
|
43
|
+
bson (~> 1.9.2)
|
44
|
+
builder (3.2.3)
|
45
|
+
coveralls (0.7.0)
|
46
|
+
multi_json (~> 1.3)
|
47
|
+
rest-client
|
48
|
+
simplecov (>= 0.7)
|
49
|
+
term-ansicolor
|
50
|
+
thor
|
51
|
+
daemons (1.1.9)
|
52
|
+
diff-lcs (1.3)
|
53
|
+
docile (1.1.5)
|
54
|
+
erubis (2.7.0)
|
55
|
+
globalid (0.4.0)
|
56
|
+
activesupport (>= 4.2.0)
|
57
|
+
i18n (0.8.4)
|
58
|
+
json (2.1.0)
|
59
|
+
loofah (2.0.3)
|
60
|
+
nokogiri (>= 1.5.9)
|
61
|
+
mail (2.5.5)
|
62
|
+
mime-types (~> 1.16)
|
63
|
+
treetop (~> 1.4.8)
|
64
|
+
mime-types (1.25.1)
|
65
|
+
mini_portile2 (2.2.0)
|
66
|
+
minitest (5.10.2)
|
67
|
+
mongo (1.9.2)
|
68
|
+
bson (~> 1.9.2)
|
69
|
+
multi_json (1.12.1)
|
70
|
+
nokogiri (1.8.0)
|
71
|
+
mini_portile2 (~> 2.2.0)
|
72
|
+
polyglot (0.3.5)
|
73
|
+
rack (1.6.8)
|
74
|
+
rack-test (0.6.3)
|
75
|
+
rack (>= 1.0)
|
76
|
+
rails-deprecated_sanitizer (1.0.3)
|
77
|
+
activesupport (>= 4.2.0.alpha)
|
78
|
+
rails-dom-testing (1.0.8)
|
79
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
80
|
+
nokogiri (~> 1.6)
|
81
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
82
|
+
rails-html-sanitizer (1.0.3)
|
83
|
+
loofah (~> 2.0)
|
84
|
+
rake (10.1.1)
|
85
|
+
rest-client (1.6.7)
|
86
|
+
mime-types (>= 1.16)
|
87
|
+
rspec (3.6.0)
|
88
|
+
rspec-core (~> 3.6.0)
|
89
|
+
rspec-expectations (~> 3.6.0)
|
90
|
+
rspec-mocks (~> 3.6.0)
|
91
|
+
rspec-core (3.6.0)
|
92
|
+
rspec-support (~> 3.6.0)
|
93
|
+
rspec-expectations (3.6.0)
|
38
94
|
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
-
rspec-support (~> 3.
|
40
|
-
rspec-mocks (3.
|
95
|
+
rspec-support (~> 3.6.0)
|
96
|
+
rspec-mocks (3.6.0)
|
41
97
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
|
-
rspec-support (~> 3.
|
43
|
-
rspec-support (3.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
rubocop-ast (>= 1.1.0)
|
60
|
-
ruby-progressbar (1.11.0)
|
61
|
-
unicode-display_width (2.0.0)
|
98
|
+
rspec-support (~> 3.6.0)
|
99
|
+
rspec-support (3.6.0)
|
100
|
+
simplecov (0.14.1)
|
101
|
+
docile (~> 1.1.0)
|
102
|
+
json (>= 1.8, < 3)
|
103
|
+
simplecov-html (~> 0.10.0)
|
104
|
+
simplecov-html (0.10.1)
|
105
|
+
term-ansicolor (1.2.2)
|
106
|
+
tins (~> 0.8)
|
107
|
+
thor (0.18.1)
|
108
|
+
thread_safe (0.3.6)
|
109
|
+
tins (0.13.1)
|
110
|
+
treetop (1.4.15)
|
111
|
+
polyglot
|
112
|
+
polyglot (>= 0.3.1)
|
113
|
+
tzinfo (1.2.3)
|
114
|
+
thread_safe (~> 0.1)
|
62
115
|
|
63
116
|
PLATFORMS
|
64
|
-
|
117
|
+
ruby
|
65
118
|
|
66
119
|
DEPENDENCIES
|
120
|
+
actionmailer (>= 4.2.8)
|
121
|
+
coveralls
|
67
122
|
mongo_mailer!
|
68
|
-
|
69
|
-
|
70
|
-
rspec
|
71
|
-
rubocop
|
72
|
-
rubocop-rake
|
73
|
-
rubocop-rspec
|
123
|
+
rake (>= 10.0.4)
|
124
|
+
rspec (>= 2.14.0)
|
74
125
|
|
75
126
|
BUNDLED WITH
|
76
|
-
|
127
|
+
1.15.1
|
data/README.md
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# MongoMailer
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mongo_mailer.png)][gem_version]
|
4
|
+
[![Build status](https://secure.travis-ci.org/infakt/mongo_mailer.png?branch=master)][travis]
|
5
|
+
[![Code Climate](https://codeclimate.com/github/infakt/mongo_mailer.png)][codeclimate]
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/infakt/mongo_mailer/badge.png?branch=master)][coveralls]
|
7
|
+
|
8
|
+
[gem_version]: https://rubygems.org/gems/mongo_mailer
|
9
|
+
[travis]: http://travis-ci.org/infakt/mongo_mailer
|
10
|
+
[codeclimate]: https://codeclimate.com/github/infakt/mongo_mailer
|
11
|
+
[coveralls]: https://coveralls.io/r/infakt/mongo_mailer
|
12
|
+
|
13
|
+
|
14
|
+
## Asynchronous mail delivery with mongodb for Rails
|
15
|
+
|
16
|
+
### Elements
|
17
|
+
|
18
|
+
* Rails plugin containing delivery_method, generators, capistrano recipies
|
19
|
+
* worker daemon fetching mails for queue and doing the final delivery using two methods: base and emergency, if base delivery fails, then emergency is being used.
|
20
|
+
|
21
|
+
### Rails plugin
|
22
|
+
|
23
|
+
Add mongo_mailer to your `Gemfile`:
|
24
|
+
<pre>
|
25
|
+
gem 'mongo_mailer', require: 'mongo_mailer/rails'
|
26
|
+
</pre>
|
27
|
+
|
28
|
+
Run the generator:
|
29
|
+
<pre>
|
30
|
+
bundle exec rails generate mongo_mailer
|
31
|
+
</pre>
|
32
|
+
which creates `config/mongo_mailer.yml.example`
|
33
|
+
|
34
|
+
Based on example configuration file, create `mongo_mailer.yml` and add it to gitignored.
|
35
|
+
`mongo_mailer.yml` contains configuration of mongo database and final delivery methods used by worker.
|
36
|
+
|
37
|
+
Set `ActionMailer::Base` delivery method in your environment file:
|
38
|
+
<pre>
|
39
|
+
config.action_mailer.delivery_method :mongo_queue
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
Add mongo_mailer capistrano recipies, by adding:
|
43
|
+
<pre>
|
44
|
+
require 'mongo_mailer/capistrano'
|
45
|
+
</pre>
|
46
|
+
to your `deploy.rb`. Since then you have access to `cap mongo_mailer:start|stop|restart` recipies.
|
47
|
+
|
48
|
+
### Standalone worker
|
49
|
+
|
50
|
+
Worker can be used within a rails app or as a standalone application. In both cases only mongo_mailer related stuff is used - rails are never being loaded.
|
51
|
+
|
52
|
+
Worker usees [daemons](https://rubygems.org/gems/daemons) to daemonize the process, continuously polls mongo queue for new mail and does the final delivery.
|
53
|
+
|
54
|
+
* to start, stop or restart worker just run:
|
55
|
+
<pre>
|
56
|
+
bundle exec mongo_mailer start|stop|restart [rails_env]
|
57
|
+
</pre>
|
58
|
+
within a rails app, or:
|
59
|
+
<pre>
|
60
|
+
bundle exec worker start|stop|restart [app_env]
|
61
|
+
</pre>
|
62
|
+
in a standalone version.
|
63
|
+
|
64
|
+
* by default workers activity and pids are being loged in the app's `log` directory:
|
65
|
+
<pre>
|
66
|
+
log/mongo_mailer.output
|
67
|
+
log/mongo_mailer.log
|
68
|
+
log/mongo_mailer.pid
|
69
|
+
</pre>
|
70
|
+
you can change it, by modifying proper daemon options in `mongo_mailer.yml`.
|
71
|
+
|
72
|
+
* all sent mail are logged into:
|
73
|
+
<pre>
|
74
|
+
log/mongo_queue.log
|
75
|
+
</pre>
|
76
|
+
|
77
|
+
### Debugging & stats
|
78
|
+
|
79
|
+
mongo_mailer doesn't have any web interface, so irb console is the only interface to get information :)
|
80
|
+
|
81
|
+
#### Getting number of sent messages for each delivery method:
|
82
|
+
|
83
|
+
<pre>
|
84
|
+
MongoMailer::DeliveriesCounter.instance.by_type(:base)
|
85
|
+
=> {"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11}
|
86
|
+
|
87
|
+
MongoMailer::DeliveriesCounter.instance.by_type(:emergency)
|
88
|
+
=> {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:base, "value"=>1}
|
89
|
+
|
90
|
+
MongoMailer::DeliveriesCounter.instance.all
|
91
|
+
=> [{"_id"=>BSON::ObjectId('5177ecb0df30cc350e3fbdf3'), "type"=>:base, "value"=>11}, {"_id"=>BSON::ObjectId('5178f501df30cc350e3fbdf4'), "type"=>:emergency, "value"=>1}]
|
92
|
+
</pre>
|
93
|
+
|
94
|
+
#### Getting list of unsent message due to errors:
|
95
|
+
|
96
|
+
<pre>
|
97
|
+
MongoMailer::MailQueue.instance.invalid_items
|
98
|
+
</pre>
|
99
|
+
|
100
|
+
#### Clearing the list of unsent messages:
|
101
|
+
|
102
|
+
<pre>
|
103
|
+
MongoMailer::MailQueue.instance.clear_invalid_items!
|
104
|
+
</pre>
|
105
|
+
|
106
|
+
## Contributing
|
107
|
+
|
108
|
+
1. Fork it
|
109
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
110
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
111
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
112
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
#!/usr/bin/env rake
|
1
2
|
require 'bundler/gem_tasks'
|
2
3
|
require 'rspec/core/rake_task'
|
3
|
-
require 'rubocop/rake_task'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
desc 'Run all specs'
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
+
t.pattern = './spec/**/*_spec.rb'
|
8
|
+
t.rspec_opts = ['--profile', '--color']
|
9
|
+
end
|
7
10
|
|
8
|
-
task default
|
11
|
+
task :default => :spec
|
data/bin/console
ADDED
data/bin/mongo_mailer
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
ENV['RAILS_ENV'] = ENV['APP_ENV'] = ARGV[1] || 'development'
|
3
|
+
|
4
|
+
require 'mongo_mailer/standalone'
|
5
|
+
|
6
|
+
rails_root = File.dirname(ENV['BUNDLE_GEMFILE'])
|
7
|
+
|
8
|
+
MongoMailer::Configuration.instance.root = rails_root
|
9
|
+
MongoMailer::Configuration.instance.load!
|
10
|
+
|
11
|
+
MongoMailer::Worker.new.run!
|
data/bin/worker
ADDED
data/config/boot.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
4
|
+
ENV['RAILS_ENV'] ||= 'development'
|
5
|
+
|
6
|
+
require 'bundler/setup'
|
7
|
+
Bundler.require
|
8
|
+
|
9
|
+
require 'mongo_mailer/standalone'
|
10
|
+
|
11
|
+
MongoMailer::Configuration.instance.root = File.expand_path("../..", __FILE__)
|
12
|
+
MongoMailer::Configuration.instance.load!
|
@@ -0,0 +1,38 @@
|
|
1
|
+
development: &development
|
2
|
+
mongodb:
|
3
|
+
host: localhost
|
4
|
+
port: 27017
|
5
|
+
name: mongo_mailer
|
6
|
+
base_delivery_method: smtp
|
7
|
+
base_delivery_settings:
|
8
|
+
user_name: "username"
|
9
|
+
password: "apikey"
|
10
|
+
domain: "example.com"
|
11
|
+
address: "smtp1.example.com"
|
12
|
+
port: 587
|
13
|
+
authentication: plain
|
14
|
+
enable_starttls_auto: true
|
15
|
+
emergency_delivery_method: smtp
|
16
|
+
emergency_delivery_settings:
|
17
|
+
user_name: "username"
|
18
|
+
password: "apikey"
|
19
|
+
domain: "example.com"
|
20
|
+
address: "smtp2.example.com"
|
21
|
+
port: 587
|
22
|
+
authentication: plain
|
23
|
+
enable_starttls_auto: true
|
24
|
+
log_level: info
|
25
|
+
daemon_options:
|
26
|
+
dir_mode: !ruby/symbol normal
|
27
|
+
log_dir: log
|
28
|
+
dir: log
|
29
|
+
log_output: true
|
30
|
+
backtrace: true
|
31
|
+
multiple: false
|
32
|
+
production:
|
33
|
+
<<: *development
|
34
|
+
test:
|
35
|
+
<<: *development
|
36
|
+
base_delivery_method: test1
|
37
|
+
emergency_delivery_method: test2
|
38
|
+
log_level: error
|