refactor: simplify sitemap scheduling process

- Removed conditional check for production environment in
  the initializer to ensure the sitemap refresh worker
  always runs at startup.
- Renamed Sidekiq configuration file from sidekiq.yml to
  sidekiq_scheduler.yml to better reflect its purpose.

These changes streamline the initialization process
for scheduled tasks and enhance the clarity of the
configuration files used in the project.
This commit is contained in:
songtianlun 2025-01-25 11:24:44 +08:00
parent 1ca468f9af
commit ead795266e
4 changed files with 9 additions and 11 deletions

View File

@ -31,7 +31,7 @@ class RefreshSitemapWorker
end
end
SitemapGenerator::Sitemap.ping_search_engines if Rails.env.production?
# SitemapGenerator::Sitemap.ping_search_engines if Rails.env.production?
Rails.logger.info "Sitemap has been generated successfully"
rescue => e
Rails.logger.error "Error refreshing sitemap: #{e.message}"

View File

@ -1,11 +1,9 @@
# config/initializers/schedule_tasks.rb
Rails.application.config.after_initialize do
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
end

View File

@ -5,7 +5,7 @@ Sidekiq.configure_server do |config|
config.redis = { url: ENV.fetch("REDIS_URL", "redis://localhost:6379/1") }
config.logger.level = Logger::INFO
config.on(:startup) do
schedule_file = "config/sidekiq.yml"
schedule_file = "config/sidekiq_scheduler.yml"
if File.exist?(schedule_file)
Sidekiq::Scheduler.enabled = true
Sidekiq::Scheduler.dynamic = true