simplify job params
This commit is contained in:
@@ -64,14 +64,14 @@ module Api
|
||||
submissions = create_submissions(@template, params)
|
||||
|
||||
submissions.each do |submission|
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later(submission)
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
|
||||
end
|
||||
|
||||
Submissions.send_signature_requests(submissions)
|
||||
|
||||
submissions.each do |submission|
|
||||
if submission.submitters.all?(&:completed_at?) && submission.submitters.last
|
||||
ProcessSubmitterCompletionJob.perform_later(submission.submitters.last)
|
||||
ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => submission.submitters.last.id })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -94,7 +94,7 @@ module Api
|
||||
else
|
||||
@submission.update!(archived_at: Time.current)
|
||||
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_later(@submission)
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_later('submission_id' => @submission.id)
|
||||
end
|
||||
|
||||
render json: @submission.as_json(only: %i[id archived_at])
|
||||
|
||||
@@ -13,7 +13,7 @@ module Api
|
||||
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'view_form', request)
|
||||
|
||||
SendFormViewedWebhookRequestJob.perform_later(submitter)
|
||||
SendFormViewedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
|
||||
|
||||
render json: {}
|
||||
end
|
||||
|
||||
@@ -66,7 +66,7 @@ module Api
|
||||
end
|
||||
|
||||
if @submitter.completed_at?
|
||||
ProcessSubmitterCompletionJob.perform_later(@submitter)
|
||||
ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => @submitter.id })
|
||||
elsif normalized_params[:send_email] || normalized_params[:send_sms]
|
||||
Submitters.send_signature_requests([@submitter])
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ module Api
|
||||
|
||||
Templates::CloneAttachments.call(template: cloned_template, original_template: @template)
|
||||
|
||||
SendTemplateCreatedWebhookRequestJob.perform_later(cloned_template)
|
||||
SendTemplateCreatedWebhookRequestJob.perform_later('template_id' => cloned_template.id)
|
||||
|
||||
render json: Templates::SerializeForApi.call(cloned_template)
|
||||
end
|
||||
|
||||
@@ -65,7 +65,7 @@ module Api
|
||||
|
||||
@template.update!(template_params)
|
||||
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later(@template)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later('template_id' => @template.id)
|
||||
|
||||
render json: @template.as_json(only: %i[id updated_at])
|
||||
end
|
||||
|
||||
@@ -36,7 +36,9 @@ class StartFormController < ApplicationController
|
||||
is_new_record = @submitter.new_record?
|
||||
|
||||
if @submitter.save
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later(@submitter.submission) if is_new_record
|
||||
if is_new_record
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => @submitter.submission.id })
|
||||
end
|
||||
|
||||
redirect_to submit_form_path(@submitter.slug)
|
||||
else
|
||||
|
||||
@@ -45,7 +45,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
|
||||
submissions.each do |submission|
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later(submission)
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
|
||||
end
|
||||
|
||||
Submissions.send_signature_requests(submissions)
|
||||
@@ -56,7 +56,7 @@ class SubmissionsController < ApplicationController
|
||||
def destroy
|
||||
@submission.update!(archived_at: Time.current)
|
||||
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_later(@submission)
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_later('submission_id' => @submission.id)
|
||||
|
||||
redirect_back(fallback_location: template_path(@submission.template), notice: 'Submission has been archived')
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ class TemplatesController < ApplicationController
|
||||
if @template.save
|
||||
Templates::CloneAttachments.call(template: @template, original_template: @base_template) if @base_template
|
||||
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later(@template)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later('template_id' => @template.id)
|
||||
|
||||
maybe_redirect_to_template(@template)
|
||||
else
|
||||
@@ -72,7 +72,7 @@ class TemplatesController < ApplicationController
|
||||
def update
|
||||
@template.update!(template_params)
|
||||
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later(@template)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_later('template_id' => @template.id)
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class TemplatesUploadsController < ApplicationController
|
||||
|
||||
@template.update!(schema:)
|
||||
|
||||
SendTemplateCreatedWebhookRequestJob.perform_later(@template)
|
||||
SendTemplateCreatedWebhookRequestJob.perform_later('template_id' => @template.id)
|
||||
|
||||
redirect_to edit_template_path(@template)
|
||||
rescue Templates::CreateAttachments::PdfEncrypted
|
||||
|
||||
@@ -17,7 +17,7 @@ class WebhookSettingsController < ApplicationController
|
||||
def update
|
||||
submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last
|
||||
|
||||
SendFormCompletedWebhookRequestJob.perform_later(submitter)
|
||||
SendFormCompletedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
|
||||
|
||||
redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook request has been sent.')
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
def perform(submitter)
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
is_all_completed = !submitter.submission.submitters.exists?(completed_at: nil)
|
||||
|
||||
if !is_all_completed && submitter.submission.submitters_order_preserved?
|
||||
@@ -18,7 +20,7 @@ class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
|
||||
return if Accounts.load_webhook_url(submitter.account).blank?
|
||||
|
||||
SendFormCompletedWebhookRequestJob.perform_later(submitter)
|
||||
SendFormCompletedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
|
||||
end
|
||||
|
||||
def enqueue_completed_emails(submitter)
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(submitter, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(submitter.submission.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -37,9 +39,10 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
|
||||
SendFormCompletedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(submitter, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(submitter, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(submitter.submission.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -35,9 +37,10 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
|
||||
SendFormStartedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(submitter, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(submitter, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(submitter.submission.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -35,9 +37,10 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
|
||||
SendFormViewedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(submitter, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendSubmissionArchivedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(submission, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
submission = Submission.find(params['submission_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(submission.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -33,9 +35,10 @@ class SendSubmissionArchivedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
|
||||
SendSubmissionArchivedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(submission, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'submission_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendSubmissionCreatedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(submission, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
submission = Submission.find(params['submission_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(submission.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -33,9 +35,10 @@ class SendSubmissionCreatedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
|
||||
SendSubmissionCreatedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(submission, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'submission_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendTemplateCreatedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(template, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
template = Template.find(params['template_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(template.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -33,9 +35,10 @@ class SendTemplateCreatedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
|
||||
SendTemplateCreatedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(template, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'template_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,10 @@ class SendTemplateUpdatedWebhookRequestJob < ApplicationJob
|
||||
|
||||
MAX_ATTEMPTS = 10
|
||||
|
||||
def perform(template, params = {})
|
||||
attempt = params[:attempt].to_i
|
||||
def perform(params = {})
|
||||
template = Template.find(params['template_id'])
|
||||
|
||||
attempt = params['attempt'].to_i
|
||||
url = Accounts.load_webhook_url(template.account)
|
||||
|
||||
return if url.blank?
|
||||
@@ -33,9 +35,10 @@ class SendTemplateUpdatedWebhookRequestJob < ApplicationJob
|
||||
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
|
||||
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
|
||||
SendTemplateUpdatedWebhookRequestJob.set(wait: (2**attempt).minutes)
|
||||
.perform_later(template, {
|
||||
attempt: attempt + 1,
|
||||
last_status: resp&.status.to_i
|
||||
.perform_later({
|
||||
'template_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,14 +14,14 @@ module Submitters
|
||||
unless submitter.submission_events.exists?(event_type: 'start_form')
|
||||
SubmissionEvents.create_with_tracking_data(submitter, 'start_form', request)
|
||||
|
||||
SendFormStartedWebhookRequestJob.perform_later(submitter)
|
||||
SendFormStartedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
|
||||
end
|
||||
|
||||
update_submitter!(submitter, params, request)
|
||||
|
||||
submitter.submission.save!
|
||||
|
||||
ProcessSubmitterCompletionJob.perform_later(submitter) if submitter.completed_at?
|
||||
ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => submitter.id }) if submitter.completed_at?
|
||||
|
||||
submitter
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user