feat: improve Sidekiq scheduling configuration

- Enable dynamic scheduling only if the schedule file exists
- Update the sidekiq.yml to include a new job for batch generation
- Define a cron schedule for the new job to run every 2 hours

This update allows Sidekiq to conditionally enable its scheduler and
introduces a new job that processes weather art batches every two
hours. The change enhances the job management and scheduling
dynamics in the application.
This commit is contained in:
songtianlun 2025-01-23 01:07:39 +08:00
parent c20ff296eb
commit e9095ece6e
2 changed files with 16 additions and 7 deletions

View File

@ -5,8 +5,13 @@ 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
Sidekiq.schedule = YAML.load_file(File.expand_path("../../sidekiq.yml", __FILE__))
Sidekiq::Scheduler.reload_schedule!
schedule_file = "config/sidekiq.yml"
if File.exist?(schedule_file)
Sidekiq::Scheduler.enabled = true
Sidekiq::Scheduler.dynamic = true
Sidekiq.schedule = YAML.load_file(schedule_file)
Sidekiq::Scheduler.reload_schedule!
end
end
end

View File

@ -1,10 +1,14 @@
:schedule:
sample_job:
cron: '0 * * * *' # 每小时执行
class: BatchGenerateWeatherArtsWorker
:concurrency: 5
:queues:
- prod
- default
- mailers
- low
:scheduler:
:schedule:
batch_generate_weather:
cron: '0 */2 * * *' # every 每2 hours
queue: prod
class: BatchGenerateWeatherArtsWorker