use sidekiq
This commit is contained in:
@@ -64,14 +64,14 @@ module Api
|
||||
submissions = create_submissions(@template, params)
|
||||
|
||||
submissions.each do |submission|
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_async({ '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({ 'submitter_id' => submission.submitters.last.id })
|
||||
ProcessSubmitterCompletionJob.perform_async({ '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_id' => @submission.id)
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_async('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_id' => submitter.id })
|
||||
SendFormViewedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id })
|
||||
|
||||
render json: {}
|
||||
end
|
||||
|
||||
@@ -66,7 +66,7 @@ module Api
|
||||
end
|
||||
|
||||
if @submitter.completed_at?
|
||||
ProcessSubmitterCompletionJob.perform_later({ 'submitter_id' => @submitter.id })
|
||||
ProcessSubmitterCompletionJob.perform_async({ '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('template_id' => cloned_template.id)
|
||||
SendTemplateCreatedWebhookRequestJob.perform_async('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_id' => @template.id)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_async('template_id' => @template.id)
|
||||
|
||||
render json: @template.as_json(only: %i[id updated_at])
|
||||
end
|
||||
|
||||
@@ -37,7 +37,7 @@ class StartFormController < ApplicationController
|
||||
|
||||
if @submitter.save
|
||||
if is_new_record
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => @submitter.submission.id })
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_async({ 'submission_id' => @submitter.submission.id })
|
||||
end
|
||||
|
||||
redirect_to submit_form_path(@submitter.slug)
|
||||
|
||||
@@ -45,7 +45,7 @@ class SubmissionsController < ApplicationController
|
||||
end
|
||||
|
||||
submissions.each do |submission|
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_later({ 'submission_id' => submission.id })
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_async({ '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_id' => @submission.id)
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_async('submission_id' => @submission.id)
|
||||
|
||||
redirect_back(fallback_location: template_path(@submission.template), notice: 'Submission has been archived')
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ class SubmittersSendEmailController < ApplicationController
|
||||
alert: 'Email has been sent already.')
|
||||
end
|
||||
|
||||
SendSubmitterInvitationEmailJob.perform_later('submitter_id' => @submitter.id)
|
||||
SendSubmitterInvitationEmailJob.perform_async('submitter_id' => @submitter.id)
|
||||
|
||||
@submitter.sent_at ||= Time.current
|
||||
@submitter.save!
|
||||
|
||||
@@ -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_id' => @template.id)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_async('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_id' => @template.id)
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_async('template_id' => @template.id)
|
||||
|
||||
head :ok
|
||||
end
|
||||
|
||||
@@ -18,7 +18,7 @@ class TemplatesUploadsController < ApplicationController
|
||||
|
||||
@template.update!(schema:)
|
||||
|
||||
SendTemplateCreatedWebhookRequestJob.perform_later('template_id' => @template.id)
|
||||
SendTemplateCreatedWebhookRequestJob.perform_async('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_id' => submitter.id })
|
||||
SendFormCompletedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id })
|
||||
|
||||
redirect_back(fallback_location: settings_webhooks_path, notice: 'Webhook request has been sent.')
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
class ProcessSubmitterCompletionJob
|
||||
include Sidekiq::Job
|
||||
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
@@ -20,7 +22,7 @@ class ProcessSubmitterCompletionJob < ApplicationJob
|
||||
|
||||
return if Accounts.load_webhook_url(submitter.account).blank?
|
||||
|
||||
SendFormCompletedWebhookRequestJob.perform_later({ 'submitter_id' => submitter.id })
|
||||
SendFormCompletedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id })
|
||||
end
|
||||
|
||||
def enqueue_completed_emails(submitter)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendFormCompletedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendFormCompletedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -38,12 +40,11 @@ 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_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendFormCompletedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendFormStartedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendFormStartedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -36,12 +38,11 @@ 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_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendFormStartedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendFormViewedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendFormViewedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -36,12 +38,11 @@ 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_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendFormViewedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'submitter_id' => submitter.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendSubmissionArchivedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendSubmissionArchivedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -34,12 +36,11 @@ 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_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendSubmissionArchivedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'submission_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendSubmissionCreatedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendSubmissionCreatedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -34,12 +36,11 @@ 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_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendSubmissionCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'submission_id' => submission.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendSubmitterInvitationEmailJob < ApplicationJob
|
||||
class SendSubmitterInvitationEmailJob
|
||||
include Sidekiq::Job
|
||||
|
||||
def perform(params = {})
|
||||
submitter = Submitter.find(params['submitter_id'])
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendTemplateCreatedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendTemplateCreatedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -34,12 +36,11 @@ 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_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendTemplateCreatedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'template_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SendTemplateUpdatedWebhookRequestJob < ApplicationJob
|
||||
queue_as :webhooks
|
||||
class SendTemplateUpdatedWebhookRequestJob
|
||||
include Sidekiq::Job
|
||||
|
||||
sidekiq_options queue: :webhooks
|
||||
|
||||
USER_AGENT = 'DocuSeal.co Webhook'
|
||||
|
||||
@@ -34,12 +36,11 @@ 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_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
SendTemplateUpdatedWebhookRequestJob.perform_in((2**attempt).minutes, {
|
||||
'template_id' => template.id,
|
||||
'attempt' => attempt + 1,
|
||||
'last_status' => resp&.status.to_i
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,6 +81,12 @@ class User < ApplicationRecord
|
||||
true
|
||||
end
|
||||
|
||||
def sidekiq?
|
||||
return true if Rails.env.development?
|
||||
|
||||
role == 'admin'
|
||||
end
|
||||
|
||||
def self.sign_in_after_reset_password
|
||||
if PasswordsController::Current.user.present?
|
||||
!PasswordsController::Current.user.otp_required_for_login
|
||||
|
||||
Reference in New Issue
Block a user