Files
docuseal/app/jobs/send_form_started_webhook_request_job.rb
T

29 lines
974 B
Ruby
Raw Normal View History

2023-08-05 15:25:16 +03:00
# frozen_string_literal: true
2023-09-14 20:31:07 +03:00
class SendFormStartedWebhookRequestJob < ApplicationJob
2023-08-05 15:25:16 +03:00
USER_AGENT = 'DocuSeal.co Webhook'
2024-02-09 23:04:42 +02:00
NotSuccessStatus = Class.new(StandardError)
2023-08-05 15:25:16 +03:00
def perform(submitter)
2023-10-08 12:04:32 +03:00
config = Accounts.load_webhook_configs(submitter.submission.account)
2023-08-05 15:25:16 +03:00
return if config.blank? || config.value.blank?
ActiveStorage::Current.url_options = Docuseal.default_url_options
2024-02-09 23:04:42 +02:00
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
2023-08-05 15:25:16 +03:00
end
end