Merge pull request #7429 from ivanscinote/SCI-10581-ik

Fix rufus jobs to release db connections after use [SCI-10581]
This commit is contained in:
Martin Artnik 2024-04-08 14:51:00 +02:00 committed by GitHub
commit c35c03e5b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View file

@ -299,6 +299,9 @@ Naming/VariableName:
Naming/VariableNumber:
EnforcedStyle: normalcase
Naming/BlockForwarding:
EnforcedStyle: explicit
Style/WordArray:
EnforcedStyle: percent
MinSize: 0

View file

@ -2,12 +2,17 @@
require 'rufus-scheduler'
def schedule_task(scheduler, interval, &block)
scheduler.every interval do
ActiveRecord::Base.connection_pool.with_connection(&block)
end
end
if ENV['WORKER'].present?
scheduler = Rufus::Scheduler.singleton
if ENV['ENABLE_TEMPLATES_SYNC'] == 'true'
# Templates sync periodic task
scheduler.every '12h' do
schedule_task(scheduler, '12h') do
Rails.logger.info('Templates, syncing all template projects')
updated, total = TemplatesService.new.update_all_templates
Rails.logger.info(
@ -18,19 +23,18 @@ if ENV['WORKER'].present?
end
if ENV['ENABLE_FLUICS_SYNC'] == 'true'
scheduler.every '24h' do
schedule_task(scheduler, '24h') do
LabelPrinters::Fluics::SyncService.new.sync_templates! if LabelPrinter.fluics.any?
end
end
reminder_job_interval = ENV['REMINDER_JOB_INTERVAL'] || '1h'
scheduler.every reminder_job_interval do
schedule_task(scheduler, reminder_job_interval) do
MyModules::DueDateReminderJob.perform_now
RepositoryItemDateReminderJob.perform_now
end
scheduler.every '1d' do
schedule_task(scheduler, '1d') do
NotificationCleanupJob.perform_now
end
end