Files
docuseal/app/jobs/send_submission_archived_webhook_request_job.rb
T

34 lines
1.4 KiB
Ruby
Raw Normal View History

2024-04-09 18:11:58 +03:00
# frozen_string_literal: true
2024-06-18 16:51:42 +03:00
class SendSubmissionArchivedWebhookRequestJob
include Sidekiq::Job
sidekiq_options queue: :webhooks
2024-05-27 14:35:19 +03:00
2024-04-09 18:11:58 +03:00
MAX_ATTEMPTS = 10
2024-06-22 10:36:32 +03:00
def perform(params = {})
submission = Submission.find(params['submission_id'])
2024-11-01 15:35:02 +02:00
webhook_url = WebhookUrl.find(params['webhook_url_id'])
2024-06-22 10:36:32 +03:00
attempt = params['attempt'].to_i
2024-08-05 13:30:04 +03:00
return if webhook_url.url.blank? || webhook_url.events.exclude?('submission.archived')
2024-04-09 18:11:58 +03:00
resp = SendWebhookRequest.call(webhook_url, event_type: 'submission.archived',
2025-07-04 21:11:08 +03:00
event_uuid: params['event_uuid'],
record: submission,
attempt:,
data: submission.as_json(only: %i[id archived_at]))
2024-04-09 18:11:58 +03:00
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
2024-05-08 09:53:37 +03:00
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
2024-06-18 16:51:42 +03:00
SendSubmissionArchivedWebhookRequestJob.perform_in((2**attempt).minutes, {
2025-07-04 21:11:08 +03:00
**params,
2024-06-18 16:51:42 +03:00
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
2024-04-09 18:11:58 +03:00
end
end
end