From 1ca468f9afbe169ed96d5c25b6bbf513d26a1216 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Sat, 25 Jan 2025 11:05:53 +0800 Subject: [PATCH] fix: improve error handling for sitemap task - Add error handling when scheduling the RefreshSitemapWorker in production. - Log successful scheduling and errors for improved diagnostics. This change ensures that any issues with scheduling the worker are logged and can be addressed promptly, enhancing the reliability of the application in production. --- config/initializers/schedule_tasks.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/config/initializers/schedule_tasks.rb b/config/initializers/schedule_tasks.rb index 5954c8f..9da1beb 100644 --- a/config/initializers/schedule_tasks.rb +++ b/config/initializers/schedule_tasks.rb @@ -1,4 +1,11 @@ # config/initializers/schedule_tasks.rb Rails.application.config.after_initialize do - RefreshSitemapWorker.perform_async unless Rails.env.production? && !ENV["RAILS_BUILD"] -end + if Rails.env.production? && !ENV["RAILS_BUILD"] + begin + RefreshSitemapWorker.perform_async + Rails.logger.info "Startup task (RefreshSitemapWorker) scheduled successfully" + rescue => e + Rails.logger.error "Error scheduling startup task: #{e.message}" + end + end + end