akira / exq

Job processing library for Elixir - compatible with Resque / Sidekiq

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: using multiple namespaces

zastrixarundell opened this issue · comments

Perhaps allow the application to start multiple children which use multiple namespaces. Add a parameter in start_link when starting Exq with supervisors.

This should already work. Set start_on_application to false and call start_link directly in your supervisor tree.

Exq.start_link(name: .., namespace: ..)

Ah, looks like I've had 2 issues. First one is that I've enclosed my args in [ ] rather than [[ ]]. And the second that I did not know of the namespace argument. I only thought name existed:

exq/lib/exq.ex

Line 28 in ccd487a

name: top_supervisor(opts[:name]),

How exactly should this then be used? I have this current code in my application:

prefix = "namespace"
suffixes = ["one", "two", "three"]

exq_children =
  for suffix <- suffixes do
    name = "#{prefix}:#{suffix}" |> String.to_atom()
    %{id: name, start: {Exq, :start_link, [[name: name, namespace: name]]}}
  end

opts = [strategy: :one_for_one, name: Dealmailer.Supervisor]
Supervisor.start_link(children ++ exq_children, opts)

Exq.Api.jobs(:"namespace:one", "exq")

When I run that I get the following error:

** (EXIT) exited in: GenServer.call(:"namespace:one", {:jobs, "exq"}, 5000)
        ** (EXIT) an exception was raised:
            ** (FunctionClauseError) no function clause matching in Exq.Manager.Server.handle_call/3
                (exq 0.13.5) lib/exq/manager/server.ex:177: Exq.Manager.Server.handle_call({:jobs, "exq"}, {#PID<0.604.0>, #Reference<0.2827354029.2243428353.24178>}, %Exq.Manager.Server.State{enqueuer: :"namespace:one.Enqueuer", metadata: :"namespace:one.Worker.Metadata", middleware: :"namespace:one.Middleware.Server", namespace: :"namespace:one", node_id: "thinkpad", pid: #PID<0.779.0>, poll_timeout: 100, queues: ["exq"], redis: :"namespace:one.Redis.Client", scheduler_poll_timeout: 200, stats: :"namespace:one.Stats", work_table: #Reference<0.2827354029.2243559425.24129>, workers_sup: :"namespace:one.Worker.Sup"})
                (stdlib 3.11.2) gen_server.erl:661: :gen_server.try_handle_call/4
                (stdlib 3.11.2) gen_server.erl:690: :gen_server.handle_msg/6
                (stdlib 3.11.2) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Now it does register that something works because when I call:

Exq.Api.jobs(:"namespace:zero", "exq") # zero wasn't declared

I get the error:

    ** (EXIT) exited in: GenServer.call(:"namespace:zero", {:jobs, "exq"}, 5000)
        ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started

Edit:
I am using namespace:* for both the namespace and process name just so it's easier for me. It didn't work when I named the namespace and GenServer name differently.

Exq starts multiple gen servers. The name passed to Exq.Api.jobs() in incorrect. You could call Exq.Api.Server.server_name(name) to get the api server's name.

Closing this, as it is already possible to start multiple exq