Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/api/templates_clone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def finalize_and_render_response(cloned_template)
end

def enqueue_webhooks(template)
WebhookUrls.for_account_id(template.account_id, 'template.created').each do |webhook_url|
WebhookUrls.for_template(template, 'template.created').each do |webhook_url|
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => template.id,
'webhook_url_id' => webhook_url.id)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ def enqueue_template_updated_webhooks
end

def enqueue_template_webhooks(template, event_type, job_class)
return if template.account_id.blank?
return if template.partnership.blank? && template.account.blank?

WebhookUrls.for_account_id(template.account_id, event_type).each do |webhook_url|
WebhookUrls.for_template(template, event_type).each do |webhook_url|
job_class.perform_async('template_id' => template.id, 'webhook_url_id' => webhook_url.id)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ def maybe_redirect_to_template(template)
end

def enqueue_template_created_webhooks(template)
WebhookUrls.for_account_id(template.account_id, 'template.created').each do |webhook_url|
WebhookUrls.for_template(template, 'template.created').each do |webhook_url|
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => template.id,
'webhook_url_id' => webhook_url.id)
end
end

def enqueue_template_updated_webhooks(template)
WebhookUrls.for_account_id(template.account_id, 'template.updated').each do |webhook_url|
WebhookUrls.for_template(template, 'template.updated').each do |webhook_url|
SendTemplateUpdatedWebhookRequestJob.perform_async('template_id' => template.id,
'webhook_url_id' => webhook_url.id)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/templates_uploads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create_file_params_from_url
end

def enqueue_template_created_webhooks(template)
WebhookUrls.for_account_id(template.account_id, 'template.created').each do |webhook_url|
WebhookUrls.for_template(template, 'template.created').each do |webhook_url|
SendTemplateCreatedWebhookRequestJob.perform_async('template_id' => template.id,
'webhook_url_id' => webhook_url.id)
end
Expand Down
19 changes: 8 additions & 11 deletions app/jobs/send_form_changes_requested_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendFormChangesRequestedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -20,14 +18,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'form.changes_requested',
data: Submitters::SerializeForWebhook.call(submitter))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormChangesRequestedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submitter)

SendFormChangesRequestedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
17 changes: 7 additions & 10 deletions app/jobs/send_form_completed_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendFormCompletedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 12

def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -28,14 +26,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'form.completed',
data: webhook_data)

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormCompletedWebhookRequestJob.perform_in((2**attempt).minutes, {
**params,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submitter)

SendFormCompletedWebhookRequestJob.perform_in((2**attempt).minutes, {
**params,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end

private
Expand Down
19 changes: 8 additions & 11 deletions app/jobs/send_form_declined_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendFormDeclinedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -20,14 +18,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'form.declined',
data: Submitters::SerializeForWebhook.call(submitter))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormDeclinedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submitter)

SendFormDeclinedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
19 changes: 8 additions & 11 deletions app/jobs/send_form_started_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendFormStartedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -20,14 +18,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'form.started',
data: Submitters::SerializeForWebhook.call(submitter))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormStartedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submitter)

SendFormStartedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
19 changes: 8 additions & 11 deletions app/jobs/send_form_viewed_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendFormViewedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submitter = Submitter.find(params['submitter_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -20,14 +18,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'form.viewed',
data: Submitters::SerializeForWebhook.call(submitter))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormViewedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submitter)

SendFormViewedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submitter_id' => submitter.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
19 changes: 8 additions & 11 deletions app/jobs/send_submission_archived_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendSubmissionArchivedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -18,14 +16,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'submission.archived',
data: submission.as_json(only: %i[id archived_at]))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionArchivedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submission)

SendSubmissionArchivedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
17 changes: 7 additions & 10 deletions app/jobs/send_submission_completed_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendSubmissionCompletedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -18,13 +16,12 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'submission.completed',
data: Submissions::SerializeForApi.call(submission))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionCompletedWebhookRequestJob.perform_in((2**attempt).minutes, {
**params,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submission)

SendSubmissionCompletedWebhookRequestJob.perform_in((2**attempt).minutes, {
**params,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
19 changes: 8 additions & 11 deletions app/jobs/send_submission_created_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendSubmissionCreatedWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -18,14 +16,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'submission.created',
data: Submissions::SerializeForApi.call(submission))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submission)

SendSubmissionCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
19 changes: 8 additions & 11 deletions app/jobs/send_submission_expired_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ class SendSubmissionExpiredWebhookRequestJob

sidekiq_options queue: :webhooks

MAX_ATTEMPTS = 10

def perform(params = {})
submission = Submission.find(params['submission_id'])
webhook_url = WebhookUrl.find(params['webhook_url_id'])
Expand All @@ -18,14 +16,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'submission.expired',
data: Submissions::SerializeForApi.call(submission))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionExpiredWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: submission)

SendSubmissionExpiredWebhookRequestJob.perform_in((2**attempt).minutes, {
'submission_id' => submission.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
17 changes: 8 additions & 9 deletions app/jobs/send_template_created_webhook_request_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ def perform(params = {})
resp = SendWebhookRequest.call(webhook_url, event_type: 'template.created',
data: Templates::SerializeForApi.call(template))

if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
SendTemplateCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
'template_id' => template.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
return unless WebhookRetryLogic.should_retry?(response: resp, attempt: attempt, record: template)

SendTemplateCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
'template_id' => template.id,
'webhook_url_id' => webhook_url.id,
'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
})
end
end
Loading
Loading