today_ai_weather/config/initializers/schedule_tasks.rb
songtianlun c37a93bcdf
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
Docker / docker (push) Waiting to run
feat: remove trailing newline at end of file
Remove trailing newline at end of file in `schedule_tasks.rb`.

- Modify file to remove unnecessary newline at end of file.
2025-01-25 01:55:00 +08:00

22 lines
647 B
Ruby

# config/initializers/schedule_tasks.rb
Rails.application.config.after_initialize do
if Rails.env.production? && !ENV["RAILS_BUILD"]
begin
redis_key = "startup_task_running"
unless Sidekiq.redis { |conn| conn.get(redis_key) }
Sidekiq.redis do |conn|
conn.setex(redis_key, 1.hour.to_i, "1")
end
RefreshSitemapWorker.perform_async
Rails.logger.info "Startup task (RefreshSitemapWorker) scheduled successfully"
end
rescue => e
Rails.logger.error "Error scheduling startup task: #{e.message}"
ensure
Sidekiq.redis { |conn| conn.del(redis_key) }
end
end
end