Skip to content

Commit

Permalink
Streamline misconfiguration detection and error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
jherdman authored and rosa committed Dec 10, 2024
1 parent ab3d9ab commit e3f422c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
20 changes: 17 additions & 3 deletions lib/solid_queue/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,21 @@ def configured_processes
end

def valid?
skip_recurring_tasks? || recurring_tasks.none? || recurring_tasks.all?(&:valid?)
configured_processes.any? && (skip_recurring_tasks? || invalid_tasks.none?)
end

def invalid_tasks
recurring_tasks.select(&:invalid?)
def error_messages
if configured_processes.none?
"No workers or processed configured. Exiting..."
else
error_messages = invalid_tasks.map do |task|
all_messages = task.errors.full_messages.map { |msg| "\t#{msg}" }.join("\n")
"#{task.key}:\n#{all_messages}"
end
.join("\n")

"Invalid processes configured:\n#{error_messages}"
end
end

def max_number_of_threads
Expand All @@ -62,6 +72,10 @@ def default_options
}
end

def invalid_tasks
recurring_tasks.select(&:invalid?)
end

def only_work?
options[:only_work]
end
Expand Down
22 changes: 3 additions & 19 deletions lib/solid_queue/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,12 @@ def start(**options)
SolidQueue.supervisor = true
configuration = Configuration.new(**options)

if configuration.configured_processes.any?
if configuration.valid?
new(configuration).tap(&:start)
else
abort_due_to_invalid_tasks(configuration)
end
if configuration.valid?
new(configuration).tap(&:start)
else
abort "No workers or processed configured. Exiting..."
abort configuration.error_messages
end
end

private
def abort_due_to_invalid_tasks(configuration)
error_messages = configuration.invalid_tasks
.map do |task|
all_messages = task.errors.full_messages.map { |msg| "\t#{msg}" }.join("\n")
"#{task.key}:\n#{all_messages}"
end
.join("\n")

abort "Invalid processes configured:\n#{error_messages}"
end
end

def initialize(configuration)
Expand Down
2 changes: 0 additions & 2 deletions test/unit/configuration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ class ConfigurationTest < ActiveSupport::TestCase
configuration = SolidQueue::Configuration.new(recurring_schedule_file: config_file_path(:recurring_with_invalid))

assert_not configuration.valid?

assert_equal configuration.invalid_tasks.size, 1
end

test "is valid when there are no recurring tasks" do
Expand Down

0 comments on commit e3f422c

Please sign in to comment.