Skip to content

Commit

Permalink
Don't try to start a supervisor on an empty configuration
Browse files Browse the repository at this point in the history
It leads to weird errors, especially when forking, such as
`Errno::ECHILD` when trying to check on the children status without
having forked any children.

I want to improve this with a generic configuration validation step,
that would check this and other things, and abort/raise if there are any
problems, but this will do for now.
  • Loading branch information
rosa committed Aug 24, 2024
1 parent b9b41db commit 418f885
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/solid_queue/supervisor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ def start(mode: :fork, load_configuration_from: nil)
SolidQueue.supervisor = true
configuration = Configuration.new(mode: mode, load_from: load_configuration_from)

klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
klass.new(configuration).tap(&:start)
if configuration.configured_processes.any?
klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
klass.new(configuration).tap(&:start)
else
abort "No workers or processed configured. Exiting..."
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions test/unit/fork_supervisor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ class ForkSupervisorTest < ActiveSupport::TestCase
assert_no_registered_processes
end

test "start with empty configuration" do
config_as_hash = { workers: [], dispatchers: [] }

pid = run_supervisor_as_fork(load_configuration_from: config_as_hash)
sleep(0.5)
assert_no_registered_processes

assert_not process_exists?(pid)
end

test "create and delete pidfile" do
assert_not File.exist?(@pidfile)

Expand Down

0 comments on commit 418f885

Please sign in to comment.