tolliver 1.0.0 → 2.0.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/README.md +21 -11
- data/app/models/tolliver/notification.rb +0 -1
- data/app/models/tolliver/notification_attachment.rb +16 -0
- data/app/models/tolliver/notification_delivery.rb +1 -3
- data/app/models/tolliver/notification_receiver.rb +0 -2
- data/app/models/tolliver/notification_template.rb +0 -1
- data/app/views/{notification_mailer → tolliver/notification_mailer}/notify.html.erb +0 -0
- data/app/views/tolliver/notification_mailer/notify.text.erb +1 -0
- data/config/locales/en.yml +1 -1
- data/db/migrate/20160121093817_create_notifications.rb +1 -12
- data/db/migrate/20160121094838_create_notification_receivers.rb +6 -4
- data/db/migrate/20160509144238_create_notification_templates.rb +4 -4
- data/db/migrate/20170630190600_create_notification_deliveries.rb +10 -3
- data/db/migrate/20201027150000_create_notification_attachments.rb +17 -0
- data/lib/tolliver.rb +44 -47
- data/lib/tolliver/errors/bad_request.rb +17 -0
- data/lib/tolliver/errors/not_found.rb +17 -0
- data/lib/tolliver/errors/standard_error.rb +17 -0
- data/lib/tolliver/mailers/notification_mailer.rb +10 -13
- data/lib/tolliver/models/notification.rb +11 -64
- data/lib/tolliver/models/notification_attachment.rb +35 -0
- data/lib/tolliver/models/notification_delivery.rb +32 -40
- data/lib/tolliver/models/notification_receiver.rb +3 -25
- data/lib/tolliver/models/notification_template.rb +6 -10
- data/lib/tolliver/services/delivery.rb +52 -8
- data/lib/tolliver/services/methods/email.rb +42 -0
- data/lib/tolliver/services/methods/sms.rb +51 -0
- data/lib/tolliver/services/methods/sms/plivo.rb +51 -0
- data/lib/tolliver/services/notification.rb +109 -178
- data/lib/tolliver/services/policies/batch.rb +90 -0
- data/lib/tolliver/services/policies/instantly.rb +50 -0
- metadata +20 -14
- data/app/views/notification_mailer/notify.text.erb +0 -1
- data/lib/tolliver/models/notification_delivery/batch.rb +0 -77
- data/lib/tolliver/models/notification_delivery/instantly.rb +0 -55
- data/lib/tolliver/models/notification_receiver/email.rb +0 -46
- data/lib/tolliver/models/notification_receiver/sms.rb +0 -45
- data/lib/tolliver/services/sms/plivo.rb +0 -49
@@ -0,0 +1,90 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Notification receiver
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 21. 1. 2016
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
module Tolliver
|
13
|
+
module Services
|
14
|
+
module Policies
|
15
|
+
class Batch
|
16
|
+
|
17
|
+
def deliver(notification_delivery, batch_size = 10)
|
18
|
+
|
19
|
+
# Input validation
|
20
|
+
return nil if notification_delivery.nil? || notification_delivery.policy != :batch
|
21
|
+
|
22
|
+
# Enqueue in QC
|
23
|
+
QC.enqueue("#{self.class.to_s}.deliver", notification_delivery.id, batch_size)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Entry point for QC
|
27
|
+
def self.deliver(notification_delivery_id, batch_size = 10)
|
28
|
+
|
29
|
+
# Instantiate notification delivery object
|
30
|
+
notification_delivery = Tolliver.notification_delivery_model.find_by_id(notification_delivery_id)
|
31
|
+
return nil if notification_delivery.nil? || notification_delivery.policy != :batch
|
32
|
+
|
33
|
+
# Call internal logic
|
34
|
+
policy_service = self.new
|
35
|
+
policy_service.send(:deliver_batch_and_enqueue, notification_delivery, batch_size)
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
|
40
|
+
def deliver_batch_and_enqueue(notification_delivery, batch_size = 10)
|
41
|
+
|
42
|
+
# Send single batch
|
43
|
+
remaining = deliver_batch(notification_delivery, batch_size)
|
44
|
+
|
45
|
+
# If still some receivers remaining, enqueue next batch
|
46
|
+
if remaining > 0
|
47
|
+
|
48
|
+
# Sleep for a while to prevent SMTP/SMS service overflow
|
49
|
+
sleep 5 # seconds
|
50
|
+
|
51
|
+
# Queue next batch
|
52
|
+
deliver(notification_delivery, batch_size)
|
53
|
+
false
|
54
|
+
else
|
55
|
+
true
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def deliver_batch(notification_delivery, batch_size = 10)
|
61
|
+
|
62
|
+
# Nothing to do
|
63
|
+
return 0 if notification_delivery.sent_count == notification_delivery.receivers_count
|
64
|
+
|
65
|
+
# Get batch of receivers prepared for send
|
66
|
+
notification_receivers = notification_delivery.notification_receivers.where(sent_at: nil).limit(batch_size)
|
67
|
+
|
68
|
+
# Send entire batch
|
69
|
+
sent_counter = 0
|
70
|
+
notification_receivers.each do |notification_receiver|
|
71
|
+
sent_counter += 1 if notification_delivery.method_service.deliver(notification_receiver)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Is postponed
|
75
|
+
notification_delivery.is_postponed = false
|
76
|
+
|
77
|
+
# Update statistics
|
78
|
+
notification_delivery.sent_count += sent_counter
|
79
|
+
notification_delivery.sent_at = Time.current if notification_delivery.sent_count == notification_delivery.receivers_count
|
80
|
+
|
81
|
+
# Save
|
82
|
+
notification_delivery.save
|
83
|
+
|
84
|
+
(notification_delivery.receivers_count - notification_delivery.sent_count)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# *****************************************************************************
|
2
|
+
# * Copyright (c) 2019 Matěj Outlý
|
3
|
+
# *****************************************************************************
|
4
|
+
# *
|
5
|
+
# * Notification receiver
|
6
|
+
# *
|
7
|
+
# * Author: Matěj Outlý
|
8
|
+
# * Date : 21. 1. 2016
|
9
|
+
# *
|
10
|
+
# *****************************************************************************
|
11
|
+
|
12
|
+
module Tolliver
|
13
|
+
module Services
|
14
|
+
module Policies
|
15
|
+
class Instantly
|
16
|
+
|
17
|
+
def deliver(notification_delivery)
|
18
|
+
|
19
|
+
# Input validation
|
20
|
+
return nil if notification_delivery.nil? || notification_delivery.policy != :instantly
|
21
|
+
|
22
|
+
# Nothing to do
|
23
|
+
return 0 if notification_delivery.sent_count == notification_delivery.receivers_count
|
24
|
+
|
25
|
+
# Get batch of receivers prepared for send
|
26
|
+
notification_receivers = notification_delivery.notification_receivers #.where(sent_at: nil)
|
27
|
+
|
28
|
+
# Send entire batch
|
29
|
+
sent_counter = 0
|
30
|
+
notification_receivers.each do |notification_receiver|
|
31
|
+
sent_counter += 1 if notification_delivery.method_service.deliver(notification_receiver)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Is postponed
|
35
|
+
notification_delivery.is_postponed = false
|
36
|
+
|
37
|
+
# Update statistics
|
38
|
+
notification_delivery.sent_count += sent_counter
|
39
|
+
notification_delivery.sent_at = Time.current if notification_delivery.sent_count == notification_delivery.receivers_count
|
40
|
+
|
41
|
+
# Save
|
42
|
+
notification_delivery.save
|
43
|
+
|
44
|
+
(notification_delivery.receivers_count - notification_delivery.sent_count)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tolliver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matěj Outlý
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '6.0'
|
27
27
|
description: Tolliver is an engine for event notification and distribution among users
|
28
28
|
via e-mail, SMS or other 3rd party systems.
|
29
29
|
email:
|
@@ -36,11 +36,12 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- app/mailers/tolliver/notification_mailer.rb
|
38
38
|
- app/models/tolliver/notification.rb
|
39
|
+
- app/models/tolliver/notification_attachment.rb
|
39
40
|
- app/models/tolliver/notification_delivery.rb
|
40
41
|
- app/models/tolliver/notification_receiver.rb
|
41
42
|
- app/models/tolliver/notification_template.rb
|
42
|
-
- app/views/notification_mailer/notify.html.erb
|
43
|
-
- app/views/notification_mailer/notify.text.erb
|
43
|
+
- app/views/tolliver/notification_mailer/notify.html.erb
|
44
|
+
- app/views/tolliver/notification_mailer/notify.text.erb
|
44
45
|
- config/locales/cs.yml
|
45
46
|
- config/locales/en.yml
|
46
47
|
- config/routes.rb
|
@@ -48,26 +49,31 @@ files:
|
|
48
49
|
- db/migrate/20160121094838_create_notification_receivers.rb
|
49
50
|
- db/migrate/20160509144238_create_notification_templates.rb
|
50
51
|
- db/migrate/20170630190600_create_notification_deliveries.rb
|
52
|
+
- db/migrate/20201027150000_create_notification_attachments.rb
|
51
53
|
- lib/tolliver.rb
|
52
54
|
- lib/tolliver/engine.rb
|
55
|
+
- lib/tolliver/errors/bad_request.rb
|
56
|
+
- lib/tolliver/errors/not_found.rb
|
57
|
+
- lib/tolliver/errors/standard_error.rb
|
53
58
|
- lib/tolliver/mailers/notification_mailer.rb
|
54
59
|
- lib/tolliver/models/notification.rb
|
60
|
+
- lib/tolliver/models/notification_attachment.rb
|
55
61
|
- lib/tolliver/models/notification_delivery.rb
|
56
|
-
- lib/tolliver/models/notification_delivery/batch.rb
|
57
|
-
- lib/tolliver/models/notification_delivery/instantly.rb
|
58
62
|
- lib/tolliver/models/notification_receiver.rb
|
59
|
-
- lib/tolliver/models/notification_receiver/email.rb
|
60
|
-
- lib/tolliver/models/notification_receiver/sms.rb
|
61
63
|
- lib/tolliver/models/notification_template.rb
|
62
64
|
- lib/tolliver/services/delivery.rb
|
65
|
+
- lib/tolliver/services/methods/email.rb
|
66
|
+
- lib/tolliver/services/methods/sms.rb
|
67
|
+
- lib/tolliver/services/methods/sms/plivo.rb
|
63
68
|
- lib/tolliver/services/notification.rb
|
64
|
-
- lib/tolliver/services/
|
69
|
+
- lib/tolliver/services/policies/batch.rb
|
70
|
+
- lib/tolliver/services/policies/instantly.rb
|
65
71
|
- lib/tolliver/utils/enum.rb
|
66
72
|
homepage: https://github.com/matej-outly/tolliver
|
67
73
|
licenses:
|
68
74
|
- MIT
|
69
75
|
metadata: {}
|
70
|
-
post_install_message:
|
76
|
+
post_install_message:
|
71
77
|
rdoc_options: []
|
72
78
|
require_paths:
|
73
79
|
- lib
|
@@ -83,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
89
|
version: '0'
|
84
90
|
requirements: []
|
85
91
|
rubygems_version: 3.0.6
|
86
|
-
signing_key:
|
92
|
+
signing_key:
|
87
93
|
specification_version: 4
|
88
94
|
summary: Event notification and distribution
|
89
95
|
test_files: []
|
@@ -1 +0,0 @@
|
|
1
|
-
<%= @notification.message.to_s.strip_tags %>
|
@@ -1,77 +0,0 @@
|
|
1
|
-
# *****************************************************************************
|
2
|
-
# * Copyright (c) 2019 Matěj Outlý
|
3
|
-
# *****************************************************************************
|
4
|
-
# *
|
5
|
-
# * Notification receiver
|
6
|
-
# *
|
7
|
-
# * Author: Matěj Outlý
|
8
|
-
# * Date : 21. 1. 2016
|
9
|
-
# *
|
10
|
-
# *****************************************************************************
|
11
|
-
|
12
|
-
module Tolliver
|
13
|
-
module Models
|
14
|
-
module NotificationDelivery
|
15
|
-
module Batch
|
16
|
-
extend ActiveSupport::Concern
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
|
20
|
-
protected
|
21
|
-
|
22
|
-
def deliver_batch(notification_delivery_id, batch_size = 10)
|
23
|
-
|
24
|
-
# Find notification delivery object
|
25
|
-
notification_delivery = Tolliver.notification_delivery_model.find_by_id(notification_delivery_id)
|
26
|
-
return nil if notification_delivery.nil? || notification_delivery.policy != :batch
|
27
|
-
|
28
|
-
# Nothing to do
|
29
|
-
return 0 if notification_delivery.sent_count == notification_delivery.receivers_count
|
30
|
-
|
31
|
-
# Get batch of receivers prepared for send
|
32
|
-
notification_receivers = notification_delivery.notification_receivers.where(sent_at: nil).limit(batch_size)
|
33
|
-
|
34
|
-
# Send entire batch
|
35
|
-
sent_counter = 0
|
36
|
-
notification_receivers.each do |notification_receiver|
|
37
|
-
sent_counter += 1 if notification_receiver.deliver
|
38
|
-
end
|
39
|
-
|
40
|
-
# Update statistics
|
41
|
-
notification_delivery.sent_count += sent_counter
|
42
|
-
notification_delivery.sent_at = Time.current if notification_delivery.sent_count == notification_delivery.receivers_count
|
43
|
-
|
44
|
-
# Save
|
45
|
-
notification_delivery.save
|
46
|
-
|
47
|
-
return (notification_delivery.receivers_count - notification_delivery.sent_count)
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
def deliver_batch_and_enqueue(notification_delivery_id, batch_size = 10)
|
52
|
-
|
53
|
-
# Send single batch
|
54
|
-
remaining = deliver_batch(notification_delivery_id, batch_size)
|
55
|
-
return nil if remaining.nil?
|
56
|
-
|
57
|
-
# If still some receivers remaining, enqueue next batch
|
58
|
-
if remaining > 0
|
59
|
-
|
60
|
-
# Sleep for a while to prevent SMTP/SMS service overflow
|
61
|
-
sleep 5 # seconds
|
62
|
-
|
63
|
-
# Queue next batch
|
64
|
-
QC.enqueue("#{self.to_s}.deliver_batch_and_enqueue", notification_delivery_id, batch_size)
|
65
|
-
return false
|
66
|
-
else
|
67
|
-
return true
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# *****************************************************************************
|
2
|
-
# * Copyright (c) 2019 Matěj Outlý
|
3
|
-
# *****************************************************************************
|
4
|
-
# *
|
5
|
-
# * Notification receiver
|
6
|
-
# *
|
7
|
-
# * Author: Matěj Outlý
|
8
|
-
# * Date : 21. 1. 2016
|
9
|
-
# *
|
10
|
-
# *****************************************************************************
|
11
|
-
|
12
|
-
module Tolliver
|
13
|
-
module Models
|
14
|
-
module NotificationDelivery
|
15
|
-
module Instantly
|
16
|
-
extend ActiveSupport::Concern
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
|
20
|
-
protected
|
21
|
-
|
22
|
-
def deliver_instantly(notification_delivery_id)
|
23
|
-
|
24
|
-
# Find notification delivery object
|
25
|
-
notification_delivery = Tolliver.notification_delivery_model.find_by_id(notification_delivery_id)
|
26
|
-
return nil if notification_delivery.nil? || notification_delivery.policy != :instantly
|
27
|
-
|
28
|
-
# Nothing to do
|
29
|
-
return 0 if notification_delivery.sent_count == notification_delivery.receivers_count
|
30
|
-
|
31
|
-
# Get batch of receivers prepared for send
|
32
|
-
notification_receivers = notification_delivery.notification_receivers #.where(sent_at: nil)
|
33
|
-
|
34
|
-
# Send entire batch
|
35
|
-
sent_counter = 0
|
36
|
-
notification_receivers.each do |notification_receiver|
|
37
|
-
sent_counter += 1 if notification_receiver.deliver
|
38
|
-
end
|
39
|
-
|
40
|
-
# Update statistics
|
41
|
-
notification_delivery.sent_count += sent_counter
|
42
|
-
notification_delivery.sent_at = Time.current if notification_delivery.sent_count == notification_delivery.receivers_count
|
43
|
-
|
44
|
-
# Save
|
45
|
-
notification_delivery.save
|
46
|
-
|
47
|
-
return (notification_delivery.receivers_count - notification_delivery.sent_count)
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# *****************************************************************************
|
2
|
-
# * Copyright (c) 2019 Matěj Outlý
|
3
|
-
# *****************************************************************************
|
4
|
-
# *
|
5
|
-
# * Notification receiver
|
6
|
-
# *
|
7
|
-
# * Author: Matěj Outlý
|
8
|
-
# * Date : 21. 1. 2016
|
9
|
-
# *
|
10
|
-
# *****************************************************************************
|
11
|
-
|
12
|
-
module Tolliver
|
13
|
-
module Models
|
14
|
-
module NotificationReceiver
|
15
|
-
module Email
|
16
|
-
extend ActiveSupport::Concern
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
# Send notification by e-mail
|
21
|
-
def deliver_by_email
|
22
|
-
notification = self.notification_delivery.notification
|
23
|
-
|
24
|
-
# Send email
|
25
|
-
begin
|
26
|
-
Tolliver::NotificationMailer.notify(notification, self.receiver).deliver_now
|
27
|
-
self.state = "sent"
|
28
|
-
#rescue Net::SMTPFatalError, Net::SMTPSyntaxError
|
29
|
-
rescue StandardError => e
|
30
|
-
self.state = "error"
|
31
|
-
self.error_message = e.message
|
32
|
-
end
|
33
|
-
|
34
|
-
# Mark as sent
|
35
|
-
self.sent_at = Time.current
|
36
|
-
|
37
|
-
# Save
|
38
|
-
self.save
|
39
|
-
|
40
|
-
return true
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# *****************************************************************************
|
2
|
-
# * Copyright (c) 2019 Matěj Outlý
|
3
|
-
# *****************************************************************************
|
4
|
-
# *
|
5
|
-
# * Notification receiver
|
6
|
-
# *
|
7
|
-
# * Author: Matěj Outlý
|
8
|
-
# * Date : 21. 1. 2016
|
9
|
-
# *
|
10
|
-
# *****************************************************************************
|
11
|
-
|
12
|
-
module Tolliver
|
13
|
-
module Models
|
14
|
-
module NotificationReceiver
|
15
|
-
module Sms
|
16
|
-
extend ActiveSupport::Concern
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
# Send notification by SMS
|
21
|
-
def deliver_by_sms
|
22
|
-
notification = self.notification_delivery.notification
|
23
|
-
|
24
|
-
# Send SMS
|
25
|
-
begin
|
26
|
-
Tolliver.sms_provider_obj.deliver(self.receiver.phone, notification.message.strip_tags)
|
27
|
-
self.state = "sent"
|
28
|
-
rescue StandardError => e
|
29
|
-
self.state = "error"
|
30
|
-
self.error_message = e.message
|
31
|
-
end
|
32
|
-
|
33
|
-
# Mark as sent
|
34
|
-
self.sent_at = Time.current
|
35
|
-
|
36
|
-
# Save
|
37
|
-
self.save
|
38
|
-
|
39
|
-
return true
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|