simplify job params

pull/349/head
Pete Matsyburka 1 year ago
parent 61da477733
commit acf06084bf

@ -64,14 +64,14 @@ module Api
submissions = create_submissions(@template, params) submissions = create_submissions(@template, params)
submissions.each do |submission| submissions.each do |submission|
SendSubmissionCreatedWebhookRequestJob.perform_later(submission) SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
end end
Submissions.send_signature_requests(submissions) Submissions.send_signature_requests(submissions)
submissions.each do |submission| submissions.each do |submission|
if submission.submitters.all?(&:completed_at?) && submission.submitters.last 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
end end
@ -94,7 +94,7 @@ module Api
else else
@submission.update!(archived_at: Time.current) @submission.update!(archived_at: Time.current)
SendSubmissionArchivedWebhookRequestJob.perform_later(@submission) SendSubmissionArchivedWebhookRequestJob.perform_later('submission_id' => @submission.id)
end end
render json: @submission.as_json(only: %i[id archived_at]) 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) SubmissionEvents.create_with_tracking_data(submitter, 'view_form', request)
SendFormViewedWebhookRequestJob.perform_later(submitter) SendFormViewedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
render json: {} render json: {}
end end

@ -66,7 +66,7 @@ module Api
end end
if @submitter.completed_at? if @submitter.completed_at?
ProcessSubmitterCompletionJob.perform_later(@submitter) ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => @submitter.id })
elsif normalized_params[:send_email] || normalized_params[:send_sms] elsif normalized_params[:send_email] || normalized_params[:send_sms]
Submitters.send_signature_requests([@submitter]) Submitters.send_signature_requests([@submitter])
end end

@ -20,7 +20,7 @@ module Api
Templates::CloneAttachments.call(template: cloned_template, original_template: @template) 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) render json: Templates::SerializeForApi.call(cloned_template)
end end

@ -65,7 +65,7 @@ module Api
@template.update!(template_params) @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]) render json: @template.as_json(only: %i[id updated_at])
end end

@ -36,7 +36,9 @@ class StartFormController < ApplicationController
is_new_record = @submitter.new_record? is_new_record = @submitter.new_record?
if @submitter.save 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) redirect_to submit_form_path(@submitter.slug)
else else

@ -45,7 +45,7 @@ class SubmissionsController < ApplicationController
end end
submissions.each do |submission| submissions.each do |submission|
SendSubmissionCreatedWebhookRequestJob.perform_later(submission) SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
end end
Submissions.send_signature_requests(submissions) Submissions.send_signature_requests(submissions)
@ -56,7 +56,7 @@ class SubmissionsController < ApplicationController
def destroy def destroy
@submission.update!(archived_at: Time.current) @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') redirect_back(fallback_location: template_path(@submission.template), notice: 'Submission has been archived')
end end

@ -61,7 +61,7 @@ class TemplatesController < ApplicationController
if @template.save if @template.save
Templates::CloneAttachments.call(template: @template, original_template: @base_template) if @base_template 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) maybe_redirect_to_template(@template)
else else
@ -72,7 +72,7 @@ class TemplatesController < ApplicationController
def update def update
@template.update!(template_params) @template.update!(template_params)
SendTemplateUpdatedWebhookRequestJob.perform_later(@template) SendTemplateUpdatedWebhookRequestJob.perform_later('template_id' => @template.id)
head :ok head :ok
end end

@ -18,7 +18,7 @@ class TemplatesUploadsController < ApplicationController
@template.update!(schema:) @template.update!(schema:)
SendTemplateCreatedWebhookRequestJob.perform_later(@template) SendTemplateCreatedWebhookRequestJob.perform_later('template_id' => @template.id)
redirect_to edit_template_path(@template) redirect_to edit_template_path(@template)
rescue Templates::CreateAttachments::PdfEncrypted rescue Templates::CreateAttachments::PdfEncrypted

@ -17,7 +17,7 @@ class WebhookSettingsController < ApplicationController
def update def update
submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last 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.') redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook request has been sent.')
end end

@ -1,7 +1,9 @@
# frozen_string_literal: true # frozen_string_literal: true
class ProcessSubmitterCompletionJob < ApplicationJob 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) is_all_completed = !submitter.submission.submitters.exists?(completed_at: nil)
if !is_all_completed && submitter.submission.submitters_order_preserved? 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? return if Accounts.load_webhook_url(submitter.account).blank?
SendFormCompletedWebhookRequestJob.perform_later(submitter) SendFormCompletedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
end end
def enqueue_completed_emails(submitter) def enqueue_completed_emails(submitter)

@ -7,8 +7,10 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(submitter, params = {}) def perform(params = {})
attempt = params[:attempt].to_i submitter = Submitter.find(params['submitter_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(submitter.submission.account) url = Accounts.load_webhook_url(submitter.submission.account)
return if url.blank? return if url.blank?
@ -37,9 +39,10 @@ class SendFormCompletedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormCompletedWebhookRequestJob.set(wait: (2**attempt).minutes) SendFormCompletedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(submitter, { .perform_later({
attempt: attempt + 1, 'submitter_id' => submitter.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(submitter, params = {}) def perform(params = {})
attempt = params[:attempt].to_i submitter = Submitter.find(params['submitter_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(submitter.submission.account) url = Accounts.load_webhook_url(submitter.submission.account)
return if url.blank? return if url.blank?
@ -35,9 +37,10 @@ class SendFormStartedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormStartedWebhookRequestJob.set(wait: (2**attempt).minutes) SendFormStartedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(submitter, { .perform_later({
attempt: attempt + 1, 'submitter_id' => submitter.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(submitter, params = {}) def perform(params = {})
attempt = params[:attempt].to_i submitter = Submitter.find(params['submitter_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(submitter.submission.account) url = Accounts.load_webhook_url(submitter.submission.account)
return if url.blank? return if url.blank?
@ -35,9 +37,10 @@ class SendFormViewedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || submitter.account.account_configs.exists?(key: :plan))
SendFormViewedWebhookRequestJob.set(wait: (2**attempt).minutes) SendFormViewedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(submitter, { .perform_later({
attempt: attempt + 1, 'submitter_id' => submitter.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendSubmissionArchivedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(submission, params = {}) def perform(params = {})
attempt = params[:attempt].to_i submission = Submission.find(params['submission_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(submission.account) url = Accounts.load_webhook_url(submission.account)
return if url.blank? return if url.blank?
@ -33,9 +35,10 @@ class SendSubmissionArchivedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionArchivedWebhookRequestJob.set(wait: (2**attempt).minutes) SendSubmissionArchivedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(submission, { .perform_later({
attempt: attempt + 1, 'submission_id' => submission.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendSubmissionCreatedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(submission, params = {}) def perform(params = {})
attempt = params[:attempt].to_i submission = Submission.find(params['submission_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(submission.account) url = Accounts.load_webhook_url(submission.account)
return if url.blank? return if url.blank?
@ -33,9 +35,10 @@ class SendSubmissionCreatedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || submission.account.account_configs.exists?(key: :plan))
SendSubmissionCreatedWebhookRequestJob.set(wait: (2**attempt).minutes) SendSubmissionCreatedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(submission, { .perform_later({
attempt: attempt + 1, 'submission_id' => submission.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendTemplateCreatedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(template, params = {}) def perform(params = {})
attempt = params[:attempt].to_i template = Template.find(params['template_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(template.account) url = Accounts.load_webhook_url(template.account)
return if url.blank? return if url.blank?
@ -33,9 +35,10 @@ class SendTemplateCreatedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
SendTemplateCreatedWebhookRequestJob.set(wait: (2**attempt).minutes) SendTemplateCreatedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(template, { .perform_later({
attempt: attempt + 1, 'template_id' => template.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -7,8 +7,10 @@ class SendTemplateUpdatedWebhookRequestJob < ApplicationJob
MAX_ATTEMPTS = 10 MAX_ATTEMPTS = 10
def perform(template, params = {}) def perform(params = {})
attempt = params[:attempt].to_i template = Template.find(params['template_id'])
attempt = params['attempt'].to_i
url = Accounts.load_webhook_url(template.account) url = Accounts.load_webhook_url(template.account)
return if url.blank? return if url.blank?
@ -33,9 +35,10 @@ class SendTemplateUpdatedWebhookRequestJob < ApplicationJob
if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS && if (resp.nil? || resp.status.to_i >= 400) && attempt <= MAX_ATTEMPTS &&
(!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan)) (!Docuseal.multitenant? || template.account.account_configs.exists?(key: :plan))
SendTemplateUpdatedWebhookRequestJob.set(wait: (2**attempt).minutes) SendTemplateUpdatedWebhookRequestJob.set(wait: (2**attempt).minutes)
.perform_later(template, { .perform_later({
attempt: attempt + 1, 'template_id' => template.id,
last_status: resp&.status.to_i 'attempt' => attempt + 1,
'last_status' => resp&.status.to_i
}) })
end end
end end

@ -14,14 +14,14 @@ module Submitters
unless submitter.submission_events.exists?(event_type: 'start_form') unless submitter.submission_events.exists?(event_type: 'start_form')
SubmissionEvents.create_with_tracking_data(submitter, 'start_form', request) SubmissionEvents.create_with_tracking_data(submitter, 'start_form', request)
SendFormStartedWebhookRequestJob.perform_later(submitter) SendFormStartedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
end end
update_submitter!(submitter, params, request) update_submitter!(submitter, params, request)
submitter.submission.save! submitter.submission.save!
ProcessSubmitterCompletionJob.perform_later(submitter) if submitter.completed_at? ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => submitter.id }) if submitter.completed_at?
submitter submitter
end end

Loading…
Cancel
Save