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.
This commit is contained in:
songtianlun 2025-01-25 11:05:53 +08:00
parent 1f35664590
commit 1ca468f9af

View File

@ -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