Skip to content

Commit

Permalink
use sidekiq
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Jun 24, 2024
1 parent 9539c47 commit 3034c00
Show file tree
Hide file tree
Showing 41 changed files with 332 additions and 132 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-debug.log*
/attachments
/docuseal
/ee
dump.rdb
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@ Rails/SkipsModelValidations:
Rails/ApplicationController:
Enabled: false

Rails/Output:
Enabled: false

Capybara/ClickLinkOrButtonStyle:
Enabled: false
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ENV OPENSSL_CONF=/app/openssl_legacy.cnf

WORKDIR /app

RUN apk add --no-cache sqlite-dev libpq-dev mariadb-dev vips-dev vips-poppler poppler-utils vips-heif gcompat ttf-freefont && mkdir /fonts && rm /usr/share/fonts/freefont/FreeSans.otf
RUN apk add --no-cache sqlite-dev libpq-dev mariadb-dev vips-dev vips-poppler poppler-utils redis vips-heif gcompat ttf-freefont && mkdir /fonts && rm /usr/share/fonts/freefont/FreeSans.otf

RUN echo $'.include = /etc/ssl/openssl.cnf\n\
\n\
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gem 'pagy'
gem 'pg', require: false
gem 'premailer-rails'
gem 'pretender'
gem 'puma'
gem 'puma', require: false
gem 'rack'
gem 'rails'
gem 'rails_autolink'
Expand All @@ -37,7 +37,7 @@ gem 'rqrcode'
gem 'ruby-vips'
gem 'rubyXL'
gem 'shakapacker'
gem 'sidekiq', require: ENV.key?('REDIS_URL')
gem 'sidekiq'
gem 'sqlite3', require: false, force_ruby_platform: true
gem 'strip_attributes'
gem 'turbo-rails'
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def create
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

Expand All @@ -94,7 +94,7 @@ def destroy
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])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/submitter_form_views_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create

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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/submitters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def update
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
Expand Down
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 @@ -20,7 +20,7 @@ def create

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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def update

@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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/start_form_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def update

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)
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create
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)
Expand All @@ -56,7 +56,7 @@ def create
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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/submitters_send_email_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create
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!
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 @@ -61,7 +61,7 @@ def create
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
Expand All @@ -72,7 +72,7 @@ def create
def update
@template.update!(template_params)

SendTemplateUpdatedWebhookRequestJob.perform_later('template_id' => @template.id)
SendTemplateUpdatedWebhookRequestJob.perform_async('template_id' => @template.id)

head :ok
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 @@ -18,7 +18,7 @@ def create

@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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/webhook_settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create
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
Expand Down
6 changes: 4 additions & 2 deletions app/jobs/process_submitter_completion_job.rb
Original file line number Diff line number Diff line change
@@ -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'])

Expand All @@ -20,7 +22,7 @@ def perform(params = {})

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)
Expand Down
17 changes: 9 additions & 8 deletions app/jobs/send_form_completed_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -38,12 +40,11 @@ def perform(params = {})

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
17 changes: 9 additions & 8 deletions app/jobs/send_form_started_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -36,12 +38,11 @@ def perform(params = {})

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
17 changes: 9 additions & 8 deletions app/jobs/send_form_viewed_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -36,12 +38,11 @@ def perform(params = {})

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
17 changes: 9 additions & 8 deletions app/jobs/send_submission_archived_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -34,12 +36,11 @@ def perform(params = {})

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
17 changes: 9 additions & 8 deletions app/jobs/send_submission_created_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -34,12 +36,11 @@ def perform(params = {})

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
4 changes: 3 additions & 1 deletion app/jobs/send_submitter_invitation_email_job.rb
Original file line number Diff line number Diff line change
@@ -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'])

Expand Down
17 changes: 9 additions & 8 deletions app/jobs/send_template_created_webhook_request_job.rb
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -34,12 +36,11 @@ def perform(params = {})

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
Loading

0 comments on commit 3034c00

Please sign in to comment.