Class: Rpush::Daemon::Batch
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Loggable
#log_debug, #log_error, #log_info, #log_warn
#reflect
Constructor Details
#initialize(notifications) ⇒ Batch
Returns a new instance of Batch.
9
10
11
12
13
14
15
16
|
# File 'lib/rpush/daemon/batch.rb', line 9
def initialize(notifications)
@notifications = notifications
@num_processed = 0
@delivered = []
@failed = {}
@retryable = {}
@mutex = Mutex.new
end
|
Instance Attribute Details
#delivered ⇒ Object
Returns the value of attribute delivered.
7
8
9
|
# File 'lib/rpush/daemon/batch.rb', line 7
def delivered
@delivered
end
|
#failed ⇒ Object
Returns the value of attribute failed.
7
8
9
|
# File 'lib/rpush/daemon/batch.rb', line 7
def failed
@failed
end
|
#notifications ⇒ Object
Returns the value of attribute notifications.
7
8
9
|
# File 'lib/rpush/daemon/batch.rb', line 7
def notifications
@notifications
end
|
#num_processed ⇒ Object
Returns the value of attribute num_processed.
7
8
9
|
# File 'lib/rpush/daemon/batch.rb', line 7
def num_processed
@num_processed
end
|
#retryable ⇒ Object
Returns the value of attribute retryable.
7
8
9
|
# File 'lib/rpush/daemon/batch.rb', line 7
def retryable
@retryable
end
|
Instance Method Details
#all_processed ⇒ Object
95
96
97
98
99
100
|
# File 'lib/rpush/daemon/batch.rb', line 95
def all_processed
@mutex.synchronize do
@num_processed = @notifications.size
complete
end
end
|
#complete? ⇒ Boolean
18
19
20
|
# File 'lib/rpush/daemon/batch.rb', line 18
def complete?
@complete == true
end
|
#each_delivered(&blk) ⇒ Object
26
27
28
|
# File 'lib/rpush/daemon/batch.rb', line 26
def each_delivered(&blk)
@delivered.each(&blk)
end
|
#each_notification(&blk) ⇒ Object
22
23
24
|
# File 'lib/rpush/daemon/batch.rb', line 22
def each_notification(&blk)
@notifications.each(&blk)
end
|
#mark_all_delivered ⇒ Object
59
60
61
62
63
64
65
66
67
|
# File 'lib/rpush/daemon/batch.rb', line 59
def mark_all_delivered
@mutex.synchronize do
@delivered = @notifications
end
each_notification do |notification|
Rpush::Daemon.store.mark_delivered(notification, Time.now, persist: false)
end
end
|
#mark_all_failed(code, message) ⇒ Object
78
79
80
81
82
83
84
85
86
|
# File 'lib/rpush/daemon/batch.rb', line 78
def mark_all_failed(code, message)
key = [code, message]
@mutex.synchronize do
@failed[key] = @notifications
end
each_notification do |notification|
Rpush::Daemon.store.mark_failed(notification, code, message, Time.now, persist: false)
end
end
|
#mark_all_retryable(deliver_after, error) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/rpush/daemon/batch.rb', line 39
def mark_all_retryable(deliver_after, error)
retryable_count = 0
each_notification do |notification|
next if notification.delivered || notification.failed
retryable_count += 1
mark_retryable(notification, deliver_after)
end
log_warn("Will retry #{retryable_count} of #{@notifications.size} notifications after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
end
|
#mark_delivered(notification) ⇒ Object
52
53
54
55
56
57
|
# File 'lib/rpush/daemon/batch.rb', line 52
def mark_delivered(notification)
@mutex.synchronize do
@delivered << notification
end
Rpush::Daemon.store.mark_delivered(notification, Time.now, persist: false)
end
|
#mark_failed(notification, code, description) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/rpush/daemon/batch.rb', line 69
def mark_failed(notification, code, description)
key = [code, description]
@mutex.synchronize do
@failed[key] ||= []
@failed[key] << notification
end
Rpush::Daemon.store.mark_failed(notification, code, description, Time.now, persist: false)
end
|
#mark_retryable(notification, deliver_after) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/rpush/daemon/batch.rb', line 30
def mark_retryable(notification, deliver_after)
@mutex.synchronize do
@retryable[deliver_after] ||= []
@retryable[deliver_after] << notification
end
Rpush::Daemon.store.mark_retryable(notification, deliver_after, persist: false)
end
|
#notification_processed ⇒ Object
88
89
90
91
92
93
|
# File 'lib/rpush/daemon/batch.rb', line 88
def notification_processed
@mutex.synchronize do
@num_processed += 1
complete if @num_processed >= @notifications.size
end
end
|