You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docuseal/app/jobs/process_auto_archive_job.rb

29 lines
704 B

# frozen_string_literal: true
class ProcessAutoArchiveJob
include Sidekiq::Job
sidekiq_options retry: 0
INTERVAL = 24.hours
def perform
AccountConfig.where(key: AccountConfig::AUTO_ARCHIVE_DAYS_KEY).find_each do |config|
days = config.value.to_i
next if days <= 0
cutoff = days.days.ago
Submission.where(account_id: config.account_id)
.where(archived_at: nil)
.where(created_at: ...cutoff)
.find_each do |submission|
submission.update!(archived_at: Time.current)
WebhookUrls.enqueue_events(submission, 'submission.archived')
end
end
ensure
self.class.perform_in(INTERVAL)
end
end