Class: Webhooks::Attempt

Inherits:
ApplicationRecord show all
Defined in:
app/models/webhooks/attempt.rb

Instance Method Summary collapse

Instance Method Details

#deliverObject



27
28
29
# File 'app/models/webhooks/attempt.rb', line 27

def deliver
  request || create_request!
end

#max_attempts?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/models/webhooks/attempt.rb', line 31

def max_attempts?
  error? && attempt >= Rails.application.config.webhooks.attempts.limit
end

#reattempt(manual_reattempt: false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/models/webhooks/attempt.rb', line 35

def reattempt(manual_reattempt: false)
  return if !manual_reattempt && max_attempts?

  # If it's a manual reattempt we need to set the counter to 1 otherwise
  # we risk hitting the configured limit.
  next_attempt = if manual_reattempt
    1
  else
    attempt + 1
  end

  Webhooks::Attempt.create!(
    endpoint: endpoint,
    event: event,
    attempt: next_attempt,
    manual: manual_reattempt,
  )
end