2019-01-25 17:50:08 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rufus-scheduler'
|
|
|
|
|
2024-04-04 18:23:21 +08:00
|
|
|
def schedule_task(scheduler, interval, &block)
|
|
|
|
scheduler.every interval do
|
|
|
|
ActiveRecord::Base.connection_pool.with_connection(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-12-12 17:56:26 +08:00
|
|
|
if ENV['WORKER'].present?
|
|
|
|
scheduler = Rufus::Scheduler.singleton
|
2019-01-25 17:50:08 +08:00
|
|
|
|
2023-12-12 17:56:26 +08:00
|
|
|
if ENV['ENABLE_TEMPLATES_SYNC'] == 'true'
|
2024-04-04 18:23:21 +08:00
|
|
|
schedule_task(scheduler, '12h') do
|
2023-12-12 17:56:26 +08:00
|
|
|
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
|
2019-01-25 17:50:08 +08:00
|
|
|
end
|
2019-02-12 23:07:20 +08:00
|
|
|
|
2023-12-12 17:56:26 +08:00
|
|
|
if ENV['ENABLE_FLUICS_SYNC'] == 'true'
|
2024-04-04 18:23:21 +08:00
|
|
|
schedule_task(scheduler, '24h') do
|
2023-12-12 17:56:26 +08:00
|
|
|
LabelPrinters::Fluics::SyncService.new.sync_templates! if LabelPrinter.fluics.any?
|
|
|
|
end
|
2022-08-29 15:52:54 +08:00
|
|
|
end
|
2023-11-02 11:07:35 +08:00
|
|
|
|
2023-12-12 17:56:26 +08:00
|
|
|
reminder_job_interval = ENV['REMINDER_JOB_INTERVAL'] || '1h'
|
2024-04-04 18:23:21 +08:00
|
|
|
schedule_task(scheduler, reminder_job_interval) do
|
2023-12-12 17:56:26 +08:00
|
|
|
MyModules::DueDateReminderJob.perform_now
|
|
|
|
RepositoryItemDateReminderJob.perform_now
|
|
|
|
end
|
2023-11-28 00:44:12 +08:00
|
|
|
|
2024-04-04 18:23:21 +08:00
|
|
|
schedule_task(scheduler, '1d') do
|
2023-12-12 17:56:26 +08:00
|
|
|
NotificationCleanupJob.perform_now
|
|
|
|
end
|
2023-11-28 00:44:12 +08:00
|
|
|
end
|