Skip to content

Commit

Permalink
Don't fail when recurring tasks are defined for another environment
Browse files Browse the repository at this point in the history
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 #468
  • Loading branch information
rosa committed Dec 27, 2024
1 parent e0921d2 commit 9497257
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/solid_queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/dummy/config/recurring_with_production_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
production:
periodic_store_result:
class: StoreResultJob
queue: default
args: [ 42, { status: "custom_status" } ]
schedule: every second
4 changes: 4 additions & 0 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 9497257

Please sign in to comment.