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



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

def mark_batch_delivered
  @batch.mark_all_delivered
end

#mark_batch_failed(error) ⇒ Object



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

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
# File 'lib/rpush/daemon/delivery.rb', line 22

def mark_batch_retryable(deliver_after, error)
  @batch.mark_all_retryable(deliver_after, error)
end

#mark_deliveredObject



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

def mark_delivered
  @batch.mark_delivered(@notification)
end

#mark_failed(error) ⇒ Object



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

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