From c915561519b077e616a22dea7f0999401a528a37 Mon Sep 17 00:00:00 2001 From: Rosa Gutierrez Date: Fri, 27 Dec 2024 17:40:10 +0100 Subject: [PATCH] Don't fail when recurring tasks are defined for another environment For example, `production` only, and the configuration is being loaded for `development`. In this case, we can't take the env key as the task definition, failing to load Solid Queue at all. Fixes https://github.com/rails/solid_queue/issues/468 --- lib/solid_queue/configuration.rb | 4 ++-- test/dummy/config/recurring_with_production_only.yml | 6 ++++++ test/unit/configuration_test.rb | 4 ++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/dummy/config/recurring_with_production_only.yml diff --git a/lib/solid_queue/configuration.rb b/lib/solid_queue/configuration.rb index bd238dcc..c9e44901 100644 --- a/lib/solid_queue/configuration.rb +++ b/lib/solid_queue/configuration.rb @@ -141,8 +141,8 @@ def dispatchers_options def recurring_tasks @recurring_tasks ||= recurring_tasks_config.map do |id, options| - RecurringTask.from_configuration(id, **options) - end + RecurringTask.from_configuration(id, **options) if options.has_key?(:schedule) + end.compact end def processes_config diff --git a/test/dummy/config/recurring_with_production_only.yml b/test/dummy/config/recurring_with_production_only.yml new file mode 100644 index 00000000..6d71dc1e --- /dev/null +++ b/test/dummy/config/recurring_with_production_only.yml @@ -0,0 +1,6 @@ +production: + periodic_store_result: + class: StoreResultJob + queue: default + args: [ 42, { status: "custom_status" } ] + schedule: every second diff --git a/test/unit/configuration_test.rb b/test/unit/configuration_test.rb index 87b8726e..11653c25 100644 --- a/test/unit/configuration_test.rb +++ b/test/unit/configuration_test.rb @@ -99,6 +99,10 @@ class ConfigurationTest < ActiveSupport::TestCase assert SolidQueue::Configuration.new(recurring_schedule_file: config_file_path(:empty_recurring)).valid? assert SolidQueue::Configuration.new(skip_recurring: true).valid? + configuration = SolidQueue::Configuration.new(recurring_schedule_file: config_file_path(:recurring_with_production_only)) + assert configuration.valid? + assert_processes configuration, :scheduler, 0 + # No processes configuration = SolidQueue::Configuration.new(skip_recurring: true, dispatchers: [], workers: []) assert_not configuration.valid?