Hello everyone,
I’m trying to run an application with a bunch of workers which are using the module, but can’t figure out what I’m doing wrong here. The code is pretty straightforward
defmodule Matchmaking.Application do
@moduledoc false
use Application
import Supervisor.Spec, warn: false
@config Confex.fetch_env!(:matchmaking, __MODULE__)
defp spawn_workers(module, opts, concurrency) when is_integer(concurrency) and concurrency >= 1 do
for id <- 1..concurrency do
worker(module, opts, id: String.to_atom("#{module}_#{id}"), restart: :transient)
end
end
def start(_type, _args) do
children = List.flatten([
supervisor(Matchmaking.AMQP.Connection, []),
spawn_workers(Matchmaking.Middleware.Worker, [], 2),
])
opts = [strategy: :one_for_one, name: Matchmaking.Supervisor]
Supervisor.start_link(children, opts)
end
end
Which is leading to the next error:
** (Mix) Could not start application matchmaking: Matchmaking.Application.start(:normal, []) returned an error: shutdown: failed to start child: Matchmaking.Middleware.Worker_2
** (EXIT) already started: #PID<0.239.0>
Can anybody help me how to figure out with the following issue? The amount of workers will be always fixed at the each start and won’t be changed later.