From d4d52095359ef0fb2512e357454bbb42fa2cd86d Mon Sep 17 00:00:00 2001 From: Ivan Kljun Date: Tue, 12 Dec 2023 10:56:26 +0100 Subject: [PATCH] Make scheduler run only on worker [SCI-9865] --- config/initializers/scheduler.rb | 56 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/config/initializers/scheduler.rb b/config/initializers/scheduler.rb index 85a2f2c41..d06ed3acb 100644 --- a/config/initializers/scheduler.rb +++ b/config/initializers/scheduler.rb @@ -2,33 +2,35 @@ require 'rufus-scheduler' -scheduler = Rufus::Scheduler.singleton +if ENV['WORKER'].present? + scheduler = Rufus::Scheduler.singleton -if ENV['ENABLE_TEMPLATES_SYNC'] == 'true' - # Templates sync periodic task - scheduler.every '12h' do - Rails.logger.info('Templates, syncing all template projects') - updated, total = TemplatesService.new.update_all_templates - Rails.logger.info( - "Templates, total number of updated projects: #{updated} out of #{total}}" - ) - Rails.logger.flush + if ENV['ENABLE_TEMPLATES_SYNC'] == 'true' + # Templates sync periodic task + scheduler.every '12h' do + Rails.logger.info('Templates, syncing all template projects') + updated, total = TemplatesService.new.update_all_templates + Rails.logger.info( + "Templates, total number of updated projects: #{updated} out of #{total}}" + ) + Rails.logger.flush + end + end + + if ENV['ENABLE_FLUICS_SYNC'] == 'true' + scheduler.every '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 + MyModules::DueDateReminderJob.perform_now + RepositoryItemDateReminderJob.perform_now + end + + scheduler.every '1d' do + NotificationCleanupJob.perform_now end end - -if ENV['ENABLE_FLUICS_SYNC'] == 'true' - scheduler.every '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 - MyModules::DueDateReminderJob.perform_now - RepositoryItemDateReminderJob.perform_now -end - -scheduler.every '1d' do - NotificationCleanupJob.perform_now -end