delivery_uncle 0.1.2
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/delivery_uncle/application.js +13 -0
- data/app/assets/stylesheets/delivery_uncle/application.css +15 -0
- data/app/controllers/delivery_uncle/application_controller.rb +3 -0
- data/app/controllers/delivery_uncle/email_requests_controller.rb +108 -0
- data/app/helpers/delivery_uncle/application_helper.rb +4 -0
- data/app/models/delivery_uncle/activity.rb +25 -0
- data/app/models/delivery_uncle/email_request.rb +23 -0
- data/app/services/delivery_uncle/deliver.rb +29 -0
- data/app/services/delivery_uncle/email_queue.rb +58 -0
- data/app/services/delivery_uncle/paginate.rb +35 -0
- data/app/views/delivery_uncle/email_requests/configure.html.erb +25 -0
- data/app/views/delivery_uncle/email_requests/index.html.erb +44 -0
- data/app/views/delivery_uncle/email_requests/show.html.erb +8 -0
- data/app/views/layouts/delivery_uncle/application.html.erb +14 -0
- data/app/workers/delivery_uncle/send_email_request.rb +29 -0
- data/config/routes.rb +13 -0
- data/lib/delivery_uncle/engine.rb +25 -0
- data/lib/delivery_uncle/version.rb +3 -0
- data/lib/delivery_uncle.rb +4 -0
- data/lib/generators/delivery_uncle/install/install_generator.rb +25 -0
- data/lib/generators/delivery_uncle/install/templates/create_table_activities.rb +18 -0
- data/lib/generators/delivery_uncle/install/templates/create_table_email_requests.rb +14 -0
- data/lib/tasks/delivery_uncle_tasks.rake +4 -0
- data/spec/dummy/README.rdoc +261 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/agent.rb +2 -0
- data/spec/dummy/app/models/coupon.rb +2 -0
- data/spec/dummy/app/models/customer.rb +6 -0
- data/spec/dummy/app/models/denormalized_booking.rb +2 -0
- data/spec/dummy/app/models/departure.rb +3 -0
- data/spec/dummy/app/models/destination.rb +2 -0
- data/spec/dummy/app/models/discount.rb +3 -0
- data/spec/dummy/app/models/line_item.rb +5 -0
- data/spec/dummy/app/models/order.rb +7 -0
- data/spec/dummy/app/models/tour.rb +4 -0
- data/spec/dummy/app/models/tour_destination_assignment.rb +6 -0
- data/spec/dummy/app/models/tour_participant.rb +5 -0
- data/spec/dummy/app/models/tour_reservation.rb +6 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config/application.rb +59 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +67 -0
- data/spec/dummy/config/environments/test.rb +37 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140723105014_create_table_email_requests.rb +14 -0
- data/spec/dummy/db/migrate/20140723105015_create_table_activities.rb +18 -0
- data/spec/dummy/db/schema.rb +59 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +5 -0
- data/spec/dummy/log/test.log +34479 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/pids/redis-test.pid +1 -0
- data/spec/services/delivery_uncle/deliver_spec.rb +32 -0
- data/spec/services/delivery_uncle/email_queue_spec.rb +60 -0
- data/spec/services/delivery_uncle/paginate_spec.rb +54 -0
- data/spec/spec_helper.rb +45 -0
- metadata +245 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c82ca7fd6f9519d2be47f9a80ebc224ddaaee316
|
|
4
|
+
data.tar.gz: 567fa4e2d40269dd757215fe540ed4a7f624735c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fdbc42aeff0635ddcc6400a82f6cfa8767cc7cd251d4a30bd5f1f6327c1620cac42af7053c9327acb1bef8fff5c9335acc7c880decef4e236548ff8e70134350
|
|
7
|
+
data.tar.gz: 0a477d7668f1714688f562f61845de9287216a65314ef4956eb4d95333a2a7cd5fbe946cdffb30a0581801c32cce02eb6b0cd814e2f86596180aff09625153e7
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2014 YOURNAME
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'DeliveryUncle'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Bundler::GemHelper.install_tasks
|
|
21
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
|
2
|
+
// listed below.
|
|
3
|
+
//
|
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
|
6
|
+
//
|
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
|
8
|
+
// compiled file.
|
|
9
|
+
//
|
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
|
11
|
+
// about supported directives.
|
|
12
|
+
//
|
|
13
|
+
//= require_tree .
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
|
11
|
+
* file per style scope.
|
|
12
|
+
*
|
|
13
|
+
*= require_tree .
|
|
14
|
+
*= require_self
|
|
15
|
+
*/
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require_dependency "delivery_uncle/application_controller"
|
|
2
|
+
|
|
3
|
+
module DeliveryUncle
|
|
4
|
+
class EmailRequestsController < ApplicationController
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
requests = EmailRequest.order_by_latest
|
|
8
|
+
pagination = paginate.page(requests, params)
|
|
9
|
+
|
|
10
|
+
@requests = pagination.data
|
|
11
|
+
@pagination = pagination
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def show
|
|
15
|
+
@request = email_request
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def pause
|
|
19
|
+
EmailQueue.pause(email_request) if email_request.present?
|
|
20
|
+
redirect_to email_requests_url
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def pause_all
|
|
24
|
+
if email_request.present?
|
|
25
|
+
EmailRequest.
|
|
26
|
+
not_sent.
|
|
27
|
+
with_mailer_method(email_request.mailer, email_request.mailer_method).
|
|
28
|
+
each do |entry|
|
|
29
|
+
EmailQueue.pause(entry)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
redirect_to email_requests_url
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def retry
|
|
36
|
+
EmailQueue.retry(email_request) if email_request.present?
|
|
37
|
+
redirect_to email_requests_url
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def retry_all
|
|
41
|
+
if email_request.present?
|
|
42
|
+
EmailRequest.
|
|
43
|
+
not_sent.
|
|
44
|
+
with_mailer_method(email_request.mailer, email_request.mailer_method).
|
|
45
|
+
each do |entry|
|
|
46
|
+
EmailQueue.retry(entry)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
redirect_to email_requests_url
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def configure
|
|
53
|
+
@mailers = union_of_mailers - Activity.blocked_mailers
|
|
54
|
+
@blocked_mailers = Activity.blocked_mailers
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def block
|
|
58
|
+
mailer ?
|
|
59
|
+
act_on_mailer(:block_mailer, mailer) :
|
|
60
|
+
error_mailer_not_found
|
|
61
|
+
redirect_to action: :configure
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def unblock
|
|
65
|
+
mailer ?
|
|
66
|
+
act_on_mailer(:unblock_mailer, mailer) :
|
|
67
|
+
error_mailer_not_found
|
|
68
|
+
redirect_to action: :configure
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
def error_mailer_not_found
|
|
73
|
+
flash[:error] = "Mailer not found."
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def mailer
|
|
77
|
+
return nil if params[:mailer].blank?
|
|
78
|
+
union_of_mailers.include?(params[:mailer]) ?
|
|
79
|
+
params[:mailer] : nil
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def union_of_mailers
|
|
83
|
+
(MAILERS | EmailRequest.mailers).sort
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def act_on_mailer(verb, mailer)
|
|
87
|
+
activity = Activity.new
|
|
88
|
+
activity.actor = current_user_email
|
|
89
|
+
activity.verb = verb
|
|
90
|
+
activity.object_type = mailer
|
|
91
|
+
activity.save!
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def current_user_email
|
|
95
|
+
:user
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def email_request
|
|
99
|
+
return nil if params[:id].blank?
|
|
100
|
+
@email_request ||= EmailRequest.find(params[:id])
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
PER_PAGE = 20
|
|
104
|
+
def paginate
|
|
105
|
+
Paginate.new(PER_PAGE)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class Activity < ActiveRecord::Base
|
|
3
|
+
scope :not_expired, -> { where("expired is null or expired = 0")}
|
|
4
|
+
scope :with_object_type, ->(object_type) { where(object_type: object_type) }
|
|
5
|
+
scope :with_verb, ->(verb) { where(verb: verb) }
|
|
6
|
+
|
|
7
|
+
validates_presence_of :actor, :verb, :object_type
|
|
8
|
+
after_create :expire_blocked_mailers
|
|
9
|
+
|
|
10
|
+
def expire_blocked_mailers
|
|
11
|
+
case verb
|
|
12
|
+
when :unblock_mailer
|
|
13
|
+
self.class.with_verb(:block_mailer).with_object_type(object_type).each do |activity|
|
|
14
|
+
activity.expired = true
|
|
15
|
+
activity.save
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.blocked_mailers
|
|
21
|
+
not_expired.with_verb(:block_mailer).map(&:object_type)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class EmailRequest < ActiveRecord::Base
|
|
3
|
+
scope :order_by_latest, -> { order('created_at DESC') }
|
|
4
|
+
scope :not_sent, -> { where('status != ?', 'sent') }
|
|
5
|
+
scope :with_mailer_method, ->(mailer, mailer_method) { where(mailer: mailer, mailer_method: mailer_method) }
|
|
6
|
+
|
|
7
|
+
def mail
|
|
8
|
+
::Mail.new(mail_body)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def paused?
|
|
12
|
+
status == :paused || status == 'paused'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def sent?
|
|
16
|
+
status == :sent || status == 'sent'
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.mailers
|
|
20
|
+
group(:mailer).order('mailer ASC').map(&:mailer)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class Deliver
|
|
3
|
+
|
|
4
|
+
def initialize(mailer, mailer_method, *args)
|
|
5
|
+
mail = mailer.send(mailer_method, *args)
|
|
6
|
+
|
|
7
|
+
raise 'mail with attachment is not supported yet' if mail.has_attachments?
|
|
8
|
+
|
|
9
|
+
@request = DeliveryUncle::EmailRequest.new
|
|
10
|
+
@request.mail_body = mail.to_s
|
|
11
|
+
@request.mailer = mailer.to_s
|
|
12
|
+
@request.mailer_method = mailer_method
|
|
13
|
+
@request.status = :new
|
|
14
|
+
@request.mail_type = :deliver
|
|
15
|
+
@request.request_from = caller[1][/`.*'/][1..-2]
|
|
16
|
+
|
|
17
|
+
deliver(@request) if @request.save!
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def request
|
|
21
|
+
@request
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
def deliver(request)
|
|
26
|
+
EmailQueue.queue(request)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class EmailQueue
|
|
3
|
+
module ClassMethods
|
|
4
|
+
def queue(request)
|
|
5
|
+
return if not_allowed?(request)
|
|
6
|
+
|
|
7
|
+
save_status(request, :enqueue)
|
|
8
|
+
QueueRequest.new(request)
|
|
9
|
+
save_status(request, :queued)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def pause(request)
|
|
13
|
+
return if not_allowed?(request)
|
|
14
|
+
|
|
15
|
+
save_status(request, :paused)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def retry(request)
|
|
19
|
+
return if not_allowed?(request)
|
|
20
|
+
|
|
21
|
+
save_status(request, :retrying)
|
|
22
|
+
RetryRequest.new(request)
|
|
23
|
+
save_status(request, :queued)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def not_allowed?(request)
|
|
27
|
+
return true if request.blank? || request.sent?
|
|
28
|
+
|
|
29
|
+
if Activity.blocked_mailers.include?(request.mailer)
|
|
30
|
+
save_status(request, :blocked)
|
|
31
|
+
return true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
return false
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
def save_status(request, status)
|
|
39
|
+
request.status = status
|
|
40
|
+
request.save
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
extend ClassMethods
|
|
44
|
+
|
|
45
|
+
protected
|
|
46
|
+
class QueueRequest
|
|
47
|
+
def initialize(request)
|
|
48
|
+
Resque.enqueue(DeliveryUncle::SendEmailRequest, request.id)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class RetryRequest
|
|
53
|
+
def initialize(request)
|
|
54
|
+
QueueRequest.new(request)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class Paginate
|
|
3
|
+
def initialize(per_page=20)
|
|
4
|
+
@per_page = per_page
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def page(model, params)
|
|
8
|
+
@page = params[:page].present? ? params[:page].to_i : 1
|
|
9
|
+
@params = params
|
|
10
|
+
start = (@page-1) * @per_page
|
|
11
|
+
start = 0 if start < 0
|
|
12
|
+
@size = model.count
|
|
13
|
+
@model = model.limit(@per_page).offset(start)
|
|
14
|
+
self
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def data
|
|
18
|
+
@model
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def prev_page_url
|
|
22
|
+
return nil unless @page > 1
|
|
23
|
+
@params.merge({page: @page-1})
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def next_page_url
|
|
27
|
+
return nil if end_of_page?
|
|
28
|
+
@params.merge(page: @page +1)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def end_of_page?
|
|
32
|
+
@page*@per_page > @size
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<h1>Configure</h1>
|
|
2
|
+
|
|
3
|
+
<% if message = flash[:error] %>
|
|
4
|
+
<div>
|
|
5
|
+
<strong style="color: red;">Error: <%= message %></strong>
|
|
6
|
+
</div>
|
|
7
|
+
<% end %>
|
|
8
|
+
|
|
9
|
+
<div>
|
|
10
|
+
<%= form_tag({action: :block, method: :post}, multipart: true) do %>
|
|
11
|
+
<b>Block Mailer:</b>
|
|
12
|
+
<br><%=select_tag(:mailer, options_for_select(@mailers)) %>
|
|
13
|
+
<br><%= submit_tag 'Block', class: 'btn', confirm: 'The chosen mailer will not be blocked, Continue?'%>
|
|
14
|
+
<% end %>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<div>
|
|
18
|
+
<%= form_tag({action: :unblock, method: :post}, multipart: true) do %>
|
|
19
|
+
<b>Unblock Mailer:</b>
|
|
20
|
+
<br><%=select_tag(:mailer, options_for_select(@blocked_mailers)) %>
|
|
21
|
+
<br><%= submit_tag 'Unblock', class: 'btn', confirm: 'The chosen mailer will be unblocked, Continue?'%>
|
|
22
|
+
<% end %>
|
|
23
|
+
</div>
|
|
24
|
+
|
|
25
|
+
<%=link_to '< back to mails', action: :index %>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<h1>Mails</h1>
|
|
2
|
+
<div style="float:right"><%=link_to 'configure', action: :configure %></div>
|
|
3
|
+
<table class="table table-striped">
|
|
4
|
+
<thead>
|
|
5
|
+
<tr>
|
|
6
|
+
<th>ID</th>
|
|
7
|
+
<th>Mailer</th>
|
|
8
|
+
<th>Mailer Method</th>
|
|
9
|
+
<th>Request Date</th>
|
|
10
|
+
<th>Last Update</th>
|
|
11
|
+
<th>Status</th>
|
|
12
|
+
<th>Actions</th>
|
|
13
|
+
</tr>
|
|
14
|
+
</thead>
|
|
15
|
+
<tbody>
|
|
16
|
+
<% @requests.each do |request| %>
|
|
17
|
+
<tr>
|
|
18
|
+
<td><%=link_to request.id, request %></td>
|
|
19
|
+
<td><%=request.mailer %></td>
|
|
20
|
+
<td>
|
|
21
|
+
<%=request.mailer_method %>
|
|
22
|
+
<% if !request.sent? %>
|
|
23
|
+
<%=link_to('pause all', pause_all_email_request_path(request)) unless request.paused?%>
|
|
24
|
+
<%=link_to('retry all', retry_all_email_request_path(request)) %>
|
|
25
|
+
<% end %>
|
|
26
|
+
</td>
|
|
27
|
+
<td><%=time_ago_in_words(request.created_at) %> ago</td>
|
|
28
|
+
<td><%=time_ago_in_words(request.updated_at) %> ago</td>
|
|
29
|
+
<td><%=request.status %></td>
|
|
30
|
+
<td>
|
|
31
|
+
<% if !request.sent? %>
|
|
32
|
+
<%=link_to('pause', pause_email_request_path(request)) unless request.paused? %>
|
|
33
|
+
<%=link_to 'retry', retry_email_request_path(request) %>
|
|
34
|
+
<% end %>
|
|
35
|
+
</td>
|
|
36
|
+
</tr>
|
|
37
|
+
<% end %>
|
|
38
|
+
</tbody>
|
|
39
|
+
</table>
|
|
40
|
+
|
|
41
|
+
<% if @pagination %>
|
|
42
|
+
<%=link_to '< prev', @pagination.prev_page_url if @pagination.prev_page_url%>
|
|
43
|
+
<%=link_to 'next >', @pagination.next_page_url if @pagination.next_page_url%>
|
|
44
|
+
<% end %>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>DeliveryUncle</title>
|
|
5
|
+
<%= stylesheet_link_tag "delivery_uncle/application", media: "all" %>
|
|
6
|
+
<%= javascript_include_tag "delivery_uncle/application" %>
|
|
7
|
+
<%= csrf_meta_tags %>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
|
|
11
|
+
<%= yield %>
|
|
12
|
+
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class SendEmailRequest
|
|
3
|
+
@queue = "delivery_uncle:email_request"
|
|
4
|
+
|
|
5
|
+
def self.perform(request_id)
|
|
6
|
+
request = DeliveryUncle::EmailRequest.find(request_id)
|
|
7
|
+
|
|
8
|
+
return if request.paused? || EmailQueue.not_allowed?(request)
|
|
9
|
+
change_status(request, :processing)
|
|
10
|
+
|
|
11
|
+
@queue = "delivery_uncle:#{request.mail_type}" if request.mail_type
|
|
12
|
+
|
|
13
|
+
begin
|
|
14
|
+
mail = request.mail
|
|
15
|
+
method = ActionMailer::Base.delivery_method
|
|
16
|
+
mail.delivery_method method, ActionMailer::Base.send(:"#{method}_settings")
|
|
17
|
+
mail.deliver
|
|
18
|
+
change_status(request, :sent)
|
|
19
|
+
rescue
|
|
20
|
+
change_status(request, :error_when_deliver)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.change_status(request, status)
|
|
25
|
+
request.status = status
|
|
26
|
+
request.save
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
data/config/routes.rb
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
DeliveryUncle::Engine.routes.draw do
|
|
2
|
+
resources :email_requests, only: [:index, :show] do
|
|
3
|
+
get :pause_all, on: :member
|
|
4
|
+
get :pause, on: :member
|
|
5
|
+
get :retry_all, on: :member
|
|
6
|
+
get :retry, on: :member
|
|
7
|
+
get :configure, on: :collection
|
|
8
|
+
post :block, on: :collection
|
|
9
|
+
post :unblock, on: :collection
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
root to: 'email_requests#index'
|
|
13
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module DeliveryUncle
|
|
2
|
+
class Engine < ::Rails::Engine
|
|
3
|
+
isolate_namespace DeliveryUncle
|
|
4
|
+
|
|
5
|
+
config.autoload_paths << File.expand_path("../app/workers", __FILE__)
|
|
6
|
+
config.autoload_paths << File.expand_path("../app/services", __FILE__)
|
|
7
|
+
|
|
8
|
+
config.generators do |g|
|
|
9
|
+
g.test_framework :rspec, fixture: false
|
|
10
|
+
g.fixture_replacement :factory_girl, dir: 'spec/factories'
|
|
11
|
+
g.assets false
|
|
12
|
+
g.helper false
|
|
13
|
+
g.factory_girl dir: 'spec/factories'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
initializer "static assets" do |app|
|
|
17
|
+
app.middleware.use ::ActionDispatch::Static, "#{root}/public"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
config.after_initialize do
|
|
21
|
+
require_dependency root.join('app/models/delivery_uncle/email_request.rb').to_s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'rails/generators/migration'
|
|
2
|
+
|
|
3
|
+
module DeliveryUncle
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
|
6
|
+
include Rails::Generators::Migration
|
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
8
|
+
desc "add the migrations"
|
|
9
|
+
|
|
10
|
+
def self.next_migration_number(path)
|
|
11
|
+
unless @prev_migration_nr
|
|
12
|
+
@prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
|
|
13
|
+
else
|
|
14
|
+
@prev_migration_nr += 1
|
|
15
|
+
end
|
|
16
|
+
@prev_migration_nr.to_s
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def copy_migrations
|
|
20
|
+
migration_template "create_table_email_requests.rb", "db/migrate/create_table_email_requests.rb"
|
|
21
|
+
migration_template "create_table_activities.rb", "db/migrate/create_table_activities.rb"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class CreateTableActivities < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :delivery_uncle_activities do |t|
|
|
4
|
+
t.string :actor
|
|
5
|
+
t.text :actor_desc
|
|
6
|
+
|
|
7
|
+
t.string :verb
|
|
8
|
+
t.text :verb_desc
|
|
9
|
+
|
|
10
|
+
t.string :object_type
|
|
11
|
+
t.text :object_details
|
|
12
|
+
|
|
13
|
+
t.boolean :expired
|
|
14
|
+
|
|
15
|
+
t.timestamps
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class CreateTableEmailRequests < ActiveRecord::Migration
|
|
2
|
+
def change
|
|
3
|
+
create_table :delivery_uncle_email_requests do |t|
|
|
4
|
+
t.text :mail_body
|
|
5
|
+
t.string :mailer
|
|
6
|
+
t.string :mailer_method
|
|
7
|
+
t.string :mail_type
|
|
8
|
+
t.string :request_from
|
|
9
|
+
t.string :status
|
|
10
|
+
|
|
11
|
+
t.timestamps
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|