17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/tolliver/services/policies/instantly.rb', line 17
def deliver(notification_delivery)
return nil if notification_delivery.nil? || notification_delivery.policy != :instantly
return 0 if notification_delivery.sent_count == notification_delivery.receivers_count
notification_receivers = notification_delivery.notification_receivers
sent_counter = 0
notification_receivers.each do |notification_receiver|
sent_counter += 1 if notification_delivery.method_service.deliver(notification_receiver)
end
notification_delivery.is_postponed = false
notification_delivery.sent_count += sent_counter
notification_delivery.sent_at = Time.current if notification_delivery.sent_count == notification_delivery.receivers_count
notification_delivery.save
(notification_delivery.receivers_count - notification_delivery.sent_count)
end
|