use sidekiq

This commit is contained in:
Pete Matsyburka
2024-06-18 16:51:42 +03:00
parent 9539c476c0
commit 3034c00bb3
41 changed files with 332 additions and 132 deletions
+4 -2
View File
@@ -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