Class: Rpush::Daemon::Delivery

Inherits:
Object
  • Object
show all
Includes:
Loggable, Reflectable
Defined in:
lib/rpush/daemon/delivery.rb

Instance Method Summary collapse

Methods included from Loggable

#log_debug, #log_error, #log_info, #log_warn

Methods included from Reflectable

#reflect

Instance Method Details

#mark_batch_deliveredObject



31
32
33
# File 'lib/rpush/daemon/delivery.rb', line 31

def mark_batch_delivered
  @batch.mark_all_delivered
end

#mark_batch_failed(error) ⇒ Object



40
41
42
43
# File 'lib/rpush/daemon/delivery.rb', line 40

def mark_batch_failed(error)
  code = error.respond_to?(:code) ? error.code : nil
  @batch.mark_all_failed(code, error.to_s)
end

#mark_batch_retryable(deliver_after, error) ⇒ Object



22
23
24
25
# File 'lib/rpush/daemon/delivery.rb', line 22

def mark_batch_retryable(deliver_after, error)
  log_warn("Will retry #{@batch.notifications.size} notifications after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
  @batch.mark_all_retryable(deliver_after)
end

#mark_deliveredObject



27
28
29
# File 'lib/rpush/daemon/delivery.rb', line 27

def mark_delivered
  @batch.mark_delivered(@notification)
end

#mark_failed(error) ⇒ Object



35
36
37
38
# File 'lib/rpush/daemon/delivery.rb', line 35

def mark_failed(error)
  code = error.respond_to?(:code) ? error.code : nil
  @batch.mark_failed(@notification, code, error.to_s)
end

#mark_retryable(notification, deliver_after, error = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/rpush/daemon/delivery.rb', line 7

def mark_retryable(notification, deliver_after, error = nil)
  if notification.fail_after && notification.fail_after < Time.now
    @batch.mark_failed(notification, nil, "Notification failed to be delivered before #{notification.fail_after.strftime('%Y-%m-%d %H:%M:%S')}.")
  else
    if error
      log_warn("Will retry notification #{notification.id} after #{deliver_after.strftime('%Y-%m-%d %H:%M:%S')} due to error (#{error.class.name}, #{error.message})")
    end
    @batch.mark_retryable(notification, deliver_after)
  end
end

#mark_retryable_exponential(notification) ⇒ Object



18
19
20
# File 'lib/rpush/daemon/delivery.rb', line 18

def mark_retryable_exponential(notification)
  mark_retryable(notification, Time.now + 2**(notification.retries + 1))
end