Skip to content

Commit

Permalink
retry webhooks on non 200 status
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Feb 10, 2024
1 parent d1d26b5 commit f8b24eb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
22 changes: 14 additions & 8 deletions app/jobs/send_form_completed_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class SendFormCompletedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'

NotSuccessStatus = Class.new(StandardError)

def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)

Expand All @@ -12,13 +14,17 @@ def perform(submitter)

ActiveStorage::Current.url_options = Docuseal.default_url_options

Faraday.post(config.value,
{
event_type: 'form.completed',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
resp = Faraday.post(config.value,
{
event_type: 'form.completed',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)

if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end
22 changes: 14 additions & 8 deletions app/jobs/send_form_started_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
class SendFormStartedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'

NotSuccessStatus = Class.new(StandardError)

def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)

return if config.blank? || config.value.blank?

ActiveStorage::Current.url_options = Docuseal.default_url_options

Faraday.post(config.value,
{
event_type: 'form.started',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
resp = Faraday.post(config.value,
{
event_type: 'form.started',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)

if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end
22 changes: 14 additions & 8 deletions app/jobs/send_form_viewed_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
class SendFormViewedWebhookRequestJob < ApplicationJob
USER_AGENT = 'DocuSeal.co Webhook'

NotSuccessStatus = Class.new(StandardError)

def perform(submitter)
config = Accounts.load_webhook_configs(submitter.submission.account)

return if config.blank? || config.value.blank?

ActiveStorage::Current.url_options = Docuseal.default_url_options

Faraday.post(config.value,
{
event_type: 'form.viewed',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)
resp = Faraday.post(config.value,
{
event_type: 'form.viewed',
timestamp: Time.current,
data: Submitters::SerializeForWebhook.call(submitter)
}.to_json,
'Content-Type' => 'application/json',
'User-Agent' => USER_AGENT)

if resp.status.to_i >= 400 && (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
raise NotSuccessStatus, resp.status.to_s
end
end
end

0 comments on commit f8b24eb

Please sign in to comment.