Class: ActionPushWeb::NotificationJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/action_push_web/notification_job.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exponential_backoff_delay(executions) ⇒ Object

Exponential backoff starting from a minimum of 1 minute, capped at 60m as suggested by FCM: firebase.google.com/docs/cloud-messaging/scale-fcm#errors

| Executions | Delay (rounded minutes) | |————|————————-| | 1 | 1 | | 2 | 2 | | 3 | 4 | | 4 | 8 | | 5 | 16 | | 6 | 32 | | 7 | 60 (cap) |



26
27
28
29
30
31
32
33
# File 'app/jobs/action_push_web/notification_job.rb', line 26

def exponential_backoff_delay(executions)
  base_wait = 1.minute
  delay = base_wait * (2**(executions - 1))
  jitter = 0.15
  jitter_delay = rand * delay * jitter

  [ delay + jitter_delay, 60.minutes ].min
end

.retry_optionsObject



10
11
12
# File 'app/jobs/action_push_web/notification_job.rb', line 10

def retry_options
  Rails.version >= "8.1" ? { report: report_job_retries } : {}
end

Instance Method Details

#perform(notification_class, notification_attributes, subscription) ⇒ Object



44
45
46
# File 'app/jobs/action_push_web/notification_job.rb', line 44

def perform(notification_class, notification_attributes, subscription)
  notification_class.constantize.new(**notification_attributes).deliver_to(subscription)
end