rpush 2.7.0 → 3.0.0.rc1
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 +41 -0
- data/README.md +36 -15
- data/lib/generators/rpush_migration_generator.rb +1 -0
- data/lib/generators/templates/add_adm.rb +1 -1
- data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
- data/lib/generators/templates/add_app_to_rapns.rb +1 -1
- data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
- data/lib/generators/templates/add_gcm.rb +1 -1
- data/lib/generators/templates/add_rpush.rb +11 -11
- data/lib/generators/templates/add_wpns.rb +1 -1
- data/lib/generators/templates/create_rapns_apps.rb +1 -1
- data/lib/generators/templates/create_rapns_feedback.rb +1 -1
- data/lib/generators/templates/create_rapns_notifications.rb +1 -1
- data/lib/generators/templates/rename_rapns_to_rpush.rb +1 -1
- data/lib/generators/templates/rpush.rb +1 -1
- data/lib/generators/templates/rpush_2_0_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
- data/lib/generators/templates/rpush_3_0_0_updates.rb +11 -0
- data/lib/rpush.rb +2 -9
- data/lib/rpush/apns_feedback.rb +4 -0
- data/lib/rpush/cli.rb +2 -2
- data/lib/rpush/client/active_model.rb +3 -0
- data/lib/rpush/client/active_model/apns/notification.rb +11 -1
- data/lib/rpush/client/active_model/apns2/app.rb +15 -0
- data/lib/rpush/client/active_model/apns2/notification.rb +9 -0
- data/lib/rpush/client/active_record.rb +3 -0
- data/lib/rpush/client/active_record/apns/feedback.rb +0 -4
- data/lib/rpush/client/active_record/apns2/app.rb +11 -0
- data/lib/rpush/client/active_record/apns2/notification.rb +10 -0
- data/lib/rpush/client/active_record/app.rb +0 -4
- data/lib/rpush/client/active_record/notification.rb +0 -7
- data/lib/rpush/client/redis.rb +3 -0
- data/lib/rpush/client/redis/apns2/app.rb +11 -0
- data/lib/rpush/client/redis/apns2/notification.rb +11 -0
- data/lib/rpush/client/redis/notification.rb +1 -0
- data/lib/rpush/daemon.rb +5 -3
- data/lib/rpush/daemon/apns2.rb +10 -0
- data/lib/rpush/daemon/apns2/delivery.rb +127 -0
- data/lib/rpush/daemon/dispatcher/apns_http2.rb +50 -0
- data/lib/rpush/daemon/dispatcher/apns_tcp.rb +1 -1
- data/lib/rpush/daemon/dispatcher/http.rb +1 -1
- data/lib/rpush/daemon/gcm/delivery.rb +5 -5
- data/lib/rpush/daemon/service_config_methods.rb +4 -3
- data/lib/rpush/daemon/store/active_record/reconnectable.rb +11 -3
- data/lib/rpush/daemon/synchronizer.rb +14 -12
- data/lib/rpush/version.rb +12 -1
- data/spec/functional/apns2_spec.rb +232 -0
- data/spec/functional/apns_spec.rb +1 -2
- data/spec/functional/synchronization_spec.rb +29 -0
- data/spec/spec_helper.rb +0 -5
- data/spec/support/active_record_setup.rb +2 -1
- data/spec/unit/apns_feedback_spec.rb +9 -2
- data/spec/unit/client/active_record/apns/notification_spec.rb +34 -2
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +30 -0
- data/spec/unit_spec_helper.rb +2 -21
- metadata +256 -29
- data/lib/rpush/client/mongoid.rb +0 -36
- data/lib/rpush/client/mongoid/adm/app.rb +0 -14
- data/lib/rpush/client/mongoid/adm/notification.rb +0 -11
- data/lib/rpush/client/mongoid/apns/app.rb +0 -11
- data/lib/rpush/client/mongoid/apns/feedback.rb +0 -24
- data/lib/rpush/client/mongoid/apns/notification.rb +0 -15
- data/lib/rpush/client/mongoid/app.rb +0 -23
- data/lib/rpush/client/mongoid/gcm/app.rb +0 -11
- data/lib/rpush/client/mongoid/gcm/notification.rb +0 -11
- data/lib/rpush/client/mongoid/notification.rb +0 -51
- data/lib/rpush/client/mongoid/wns/app.rb +0 -14
- data/lib/rpush/client/mongoid/wns/badge_notification.rb +0 -15
- data/lib/rpush/client/mongoid/wns/notification.rb +0 -11
- data/lib/rpush/client/mongoid/wns/raw_notification.rb +0 -11
- data/lib/rpush/client/mongoid/wpns/app.rb +0 -11
- data/lib/rpush/client/mongoid/wpns/notification.rb +0 -11
- data/lib/rpush/daemon/store/mongoid.rb +0 -157
- data/spec/support/config/mongoid.yml +0 -69
- data/spec/support/mongoid_setup.rb +0 -10
- data/spec/unit/daemon/store/mongoid_spec.rb +0 -339
data/lib/rpush/client/mongoid.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
|
2
|
-
# :nocov:
|
3
|
-
begin
|
4
|
-
require 'mongoid'
|
5
|
-
require 'autoinc'
|
6
|
-
rescue LoadError
|
7
|
-
puts
|
8
|
-
str = "* Please add 'rpush-mongoid' to your Gemfile to use the Mongoid client. *"
|
9
|
-
puts "*" * str.size
|
10
|
-
puts str
|
11
|
-
puts "*" * str.size
|
12
|
-
puts
|
13
|
-
end
|
14
|
-
|
15
|
-
require 'rpush/client/active_model'
|
16
|
-
|
17
|
-
require 'rpush/client/mongoid/notification'
|
18
|
-
require 'rpush/client/mongoid/app'
|
19
|
-
|
20
|
-
require 'rpush/client/mongoid/apns/notification'
|
21
|
-
require 'rpush/client/mongoid/apns/feedback'
|
22
|
-
require 'rpush/client/mongoid/apns/app'
|
23
|
-
|
24
|
-
require 'rpush/client/mongoid/gcm/notification'
|
25
|
-
require 'rpush/client/mongoid/gcm/app'
|
26
|
-
|
27
|
-
require 'rpush/client/mongoid/wpns/notification'
|
28
|
-
require 'rpush/client/mongoid/wpns/app'
|
29
|
-
|
30
|
-
require 'rpush/client/mongoid/wns/notification'
|
31
|
-
require 'rpush/client/mongoid/wns/raw_notification'
|
32
|
-
require 'rpush/client/mongoid/wns/badge_notification'
|
33
|
-
require 'rpush/client/mongoid/wns/app'
|
34
|
-
|
35
|
-
require 'rpush/client/mongoid/adm/notification'
|
36
|
-
require 'rpush/client/mongoid/adm/app'
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
module Adm
|
5
|
-
class App < Rpush::Client::Mongoid::App
|
6
|
-
include Rpush::Client::ActiveModel::Adm::App
|
7
|
-
|
8
|
-
field :access_token, type: String
|
9
|
-
field :access_token_expiration, type: Time
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
module Apns
|
5
|
-
class Feedback
|
6
|
-
include ::Mongoid::Document
|
7
|
-
|
8
|
-
field :device_token, type: String
|
9
|
-
field :failed_at, type: Time
|
10
|
-
|
11
|
-
belongs_to :app
|
12
|
-
|
13
|
-
validates :device_token, presence: true
|
14
|
-
validates :failed_at, presence: true
|
15
|
-
|
16
|
-
index device_token: 1
|
17
|
-
index app_id: 1
|
18
|
-
|
19
|
-
validates_with Rpush::Client::ActiveModel::Apns::DeviceTokenFormatValidator
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
module Apns
|
5
|
-
class Notification < Rpush::Client::Mongoid::Notification
|
6
|
-
include Rpush::Client::ActiveModel::Apns::Notification
|
7
|
-
|
8
|
-
def to_binary(options = {})
|
9
|
-
super(options.merge(id_attribute: :integer_id))
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
class App
|
5
|
-
include ::Mongoid::Document
|
6
|
-
|
7
|
-
field :name, type: String
|
8
|
-
field :environment, type: String
|
9
|
-
field :certificate, type: String
|
10
|
-
field :password, type: String
|
11
|
-
field :connections, type: Integer, default: 1
|
12
|
-
field :auth_key, type: String
|
13
|
-
field :client_id, type: String
|
14
|
-
field :client_secret, type: String
|
15
|
-
|
16
|
-
index name: 1
|
17
|
-
|
18
|
-
validates :name, presence: true
|
19
|
-
validates_numericality_of :connections, greater_than: 0, only_integer: true
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
class Notification
|
5
|
-
include ::Mongoid::Document
|
6
|
-
include ::Mongoid::Timestamps
|
7
|
-
include ::Mongoid::Autoinc
|
8
|
-
include Rpush::MultiJsonHelper
|
9
|
-
include Rpush::Client::ActiveModel::Notification
|
10
|
-
|
11
|
-
field :badge, type: Integer
|
12
|
-
field :device_token, type: String
|
13
|
-
field :sound, type: String, default: 'default'
|
14
|
-
field :alert, type: String
|
15
|
-
field :data, type: Hash
|
16
|
-
field :expiry, type: Integer, default: 1.day.to_i
|
17
|
-
field :delivered, type: Boolean, default: false
|
18
|
-
field :delivered_at, type: Time
|
19
|
-
field :processing, type: Boolean, default: false
|
20
|
-
field :failed, type: Boolean, default: false
|
21
|
-
field :failed_at, type: Time
|
22
|
-
field :fail_after, type: Time
|
23
|
-
field :retries, type: Integer, default: 0
|
24
|
-
field :error_code, type: Integer
|
25
|
-
field :error_description, type: String
|
26
|
-
field :deliver_after, type: Time
|
27
|
-
field :alert_is_json, type: Boolean
|
28
|
-
field :collapse_key, type: String
|
29
|
-
field :delay_while_idle, type: Boolean
|
30
|
-
field :registration_ids, type: Array
|
31
|
-
field :uri, type: String
|
32
|
-
field :priority, type: Integer
|
33
|
-
field :url_args, type: Array
|
34
|
-
field :category, type: String
|
35
|
-
field :content_available, type: Boolean, default: false
|
36
|
-
field :notification, type: Hash
|
37
|
-
|
38
|
-
field :integer_id, type: Integer
|
39
|
-
increments :integer_id, model_name: name
|
40
|
-
index integer_id: 1
|
41
|
-
|
42
|
-
index delivered: 1, failed: 1, deliver_after: 1, processing: 1
|
43
|
-
index delivered: 1, failed: 1
|
44
|
-
index device_token: 1
|
45
|
-
index app_id: 1
|
46
|
-
|
47
|
-
belongs_to :app
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
module Wns
|
5
|
-
class App < Rpush::Client::Mongoid::App
|
6
|
-
include Rpush::Client::ActiveModel::Wns::App
|
7
|
-
|
8
|
-
field :access_token, type: String
|
9
|
-
field :access_token_expiration, type: Time
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Client
|
3
|
-
module Mongoid
|
4
|
-
module Wns
|
5
|
-
class BadgeNotification < Rpush::Client::Mongoid::Notification
|
6
|
-
include Rpush::Client::ActiveModel::Wns::Notification
|
7
|
-
|
8
|
-
def skip_data_validation?
|
9
|
-
true
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
module Rpush
|
2
|
-
module Daemon
|
3
|
-
module Store
|
4
|
-
class Mongoid
|
5
|
-
DEFAULT_MARK_OPTIONS = { persist: true }
|
6
|
-
|
7
|
-
def app(app_id)
|
8
|
-
Rpush::Client::Mongoid::App.find(app_id)
|
9
|
-
end
|
10
|
-
|
11
|
-
def all_apps
|
12
|
-
Rpush::Client::Mongoid::App.all
|
13
|
-
end
|
14
|
-
|
15
|
-
def deliverable_notifications(limit)
|
16
|
-
relation = ready_for_delivery.limit(limit)
|
17
|
-
claim_notifications(relation)
|
18
|
-
end
|
19
|
-
|
20
|
-
def mark_delivered(notification, time, opts = {})
|
21
|
-
opts = DEFAULT_MARK_OPTIONS.dup.merge(opts)
|
22
|
-
notification.delivered = true
|
23
|
-
notification.delivered_at = time
|
24
|
-
notification.save!(validate: false) if opts[:persist]
|
25
|
-
end
|
26
|
-
|
27
|
-
def mark_batch_delivered(notifications)
|
28
|
-
return if notifications.empty?
|
29
|
-
|
30
|
-
now = Time.now
|
31
|
-
ids = []
|
32
|
-
notifications.each do |n|
|
33
|
-
mark_delivered(n, now, persist: false)
|
34
|
-
ids << n.id
|
35
|
-
end
|
36
|
-
Rpush::Client::Mongoid::Notification.in(id: ids).update_all(processing: false, delivered: true, delivered_at: now)
|
37
|
-
end
|
38
|
-
|
39
|
-
def mark_failed(notification, code, description, time, opts = {})
|
40
|
-
opts = DEFAULT_MARK_OPTIONS.dup.merge(opts)
|
41
|
-
notification.delivered = false
|
42
|
-
notification.delivered_at = nil
|
43
|
-
notification.failed = true
|
44
|
-
notification.failed_at = time
|
45
|
-
notification.error_code = code
|
46
|
-
notification.error_description = description
|
47
|
-
notification.save!(validate: false) if opts[:persist]
|
48
|
-
end
|
49
|
-
|
50
|
-
def mark_batch_failed(notifications, code, description)
|
51
|
-
now = Time.now
|
52
|
-
ids = []
|
53
|
-
notifications.each do |n|
|
54
|
-
mark_failed(n, code, description, now, persist: false)
|
55
|
-
ids << n.id
|
56
|
-
end
|
57
|
-
mark_ids_failed(ids, code, description, now)
|
58
|
-
end
|
59
|
-
|
60
|
-
def mark_ids_failed(ids, code, description, time)
|
61
|
-
return if ids.empty?
|
62
|
-
|
63
|
-
Rpush::Client::Mongoid::Notification.in(id: ids).update_all(processing: false, delivered: false, delivered_at: nil, failed: true, failed_at: time, error_code: code, error_description: description)
|
64
|
-
end
|
65
|
-
|
66
|
-
def mark_retryable(notification, deliver_after, opts = {})
|
67
|
-
opts = DEFAULT_MARK_OPTIONS.dup.merge(opts)
|
68
|
-
notification.delivered = false
|
69
|
-
notification.delivered_at = nil
|
70
|
-
notification.failed = false
|
71
|
-
notification.failed_at = nil
|
72
|
-
notification.retries += 1
|
73
|
-
notification.deliver_after = deliver_after
|
74
|
-
|
75
|
-
return unless opts[:persist]
|
76
|
-
|
77
|
-
notification.save!(validate: false)
|
78
|
-
end
|
79
|
-
|
80
|
-
def mark_batch_retryable(notifications, deliver_after)
|
81
|
-
ids = []
|
82
|
-
notifications.each do |n|
|
83
|
-
mark_retryable(n, deliver_after, persist: false)
|
84
|
-
ids << n.id
|
85
|
-
end
|
86
|
-
mark_ids_retryable(ids, deliver_after)
|
87
|
-
end
|
88
|
-
|
89
|
-
def mark_ids_retryable(ids, deliver_after)
|
90
|
-
return if ids.empty?
|
91
|
-
|
92
|
-
Rpush::Client::Mongoid::Notification.in(id: ids).update_all(processing: false, delivered: false, delivered_at: nil, failed: false, failed_at: nil, deliver_after: deliver_after, '$inc' => { retries: 1 })
|
93
|
-
end
|
94
|
-
|
95
|
-
def create_apns_feedback(failed_at, device_token, app)
|
96
|
-
Rpush::Client::Mongoid::Apns::Feedback.create!(failed_at: failed_at, device_token: device_token, app: app)
|
97
|
-
end
|
98
|
-
|
99
|
-
def create_gcm_notification(attrs, data, registration_ids, deliver_after, app)
|
100
|
-
notification = Rpush::Client::Mongoid::Gcm::Notification.new
|
101
|
-
create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app)
|
102
|
-
end
|
103
|
-
|
104
|
-
def create_adm_notification(attrs, data, registration_ids, deliver_after, app)
|
105
|
-
notification = Rpush::Client::Mongoid::Adm::Notification.new
|
106
|
-
create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app)
|
107
|
-
end
|
108
|
-
|
109
|
-
def update_app(app)
|
110
|
-
app.save!
|
111
|
-
end
|
112
|
-
|
113
|
-
def update_notification(notification)
|
114
|
-
notification.save!
|
115
|
-
end
|
116
|
-
|
117
|
-
def release_connection
|
118
|
-
end
|
119
|
-
|
120
|
-
def reopen_log
|
121
|
-
end
|
122
|
-
|
123
|
-
def pending_delivery_count
|
124
|
-
ready_for_delivery.count
|
125
|
-
end
|
126
|
-
|
127
|
-
def translate_integer_notification_id(id)
|
128
|
-
Rpush::Client::Mongoid::Notification.find_by(integer_id: id).id
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
|
133
|
-
def ready_for_delivery
|
134
|
-
Rpush::Client::Mongoid::Notification.where(processing: false, delivered: false, failed: false).or({ deliver_after: nil }, :deliver_after.lt => Time.now)
|
135
|
-
end
|
136
|
-
|
137
|
-
def claim_notifications(relation)
|
138
|
-
ids = relation.map(:id)
|
139
|
-
relation.where('$isolated' => 1).in(id: ids).update_all(processing: true, processing_pid: Process.pid)
|
140
|
-
Rpush::Client::Mongoid::Notification.where(processing: true, processing_pid: Process.pid).in(id: ids).asc('created_at')
|
141
|
-
end
|
142
|
-
|
143
|
-
def create_gcm_like_notification(notification, attrs, data, registration_ids, deliver_after, app) # rubocop:disable ParameterLists
|
144
|
-
notification.assign_attributes(attrs)
|
145
|
-
notification.data = data
|
146
|
-
notification.registration_ids = registration_ids
|
147
|
-
notification.deliver_after = deliver_after
|
148
|
-
notification.app = app
|
149
|
-
notification.save!
|
150
|
-
notification
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
Rpush::Daemon::Store::Interface.check(Rpush::Daemon::Store::Mongoid)
|