2025-01-25 01:23:04 +08:00
|
|
|
# config/initializers/schedule_tasks.rb
|
|
|
|
|
|
|
|
Rails.application.config.after_initialize do
|
2025-01-25 01:38:12 +08:00
|
|
|
if Rails.env.production? && !ENV["RAILS_BUILD"]
|
2025-01-25 01:23:04 +08:00
|
|
|
begin
|
|
|
|
unless Rails.cache.read("startup_task_running")
|
|
|
|
Rails.cache.write("startup_task_running", true, expires_in: 1.hour)
|
|
|
|
|
|
|
|
RefreshSitemapWorker.perform_async
|
|
|
|
|
|
|
|
Rails.logger.info "Startup task (RefreshSitemapWorker) scheduled successfully"
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
Rails.logger.error "Error scheduling startup task: #{e.message}"
|
|
|
|
ensure
|
|
|
|
Rails.cache.delete("startup_task_running")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|