1

我使用 Elixir exq构建了一个异步作业处理应用程序。文档说我可以使用终端(带有iex -S mix)或作为独立应用程序(带有mix exq.run)运行应用程序。当我在终端上运行时,一切正常,但是当我运行独立应用程序时,我在获取作业时收到此消息:

16:52:55.028 [info]  Elixir.MyWorker[128f902c-dd22-4706-95a2-89dc974b95d6] start

16:52:55.045 [error] Process #PID<0.196.0> raised an exception
** (UndefinedFunctionError) function MyWorker.perform/1 is undefined (module MyWorker is not available)
    MyWorker.perform("arg1")
    (exq 0.14.0) lib/exq/worker/server.ex:186: anonymous fn/4 in Exq.Worker.Server.dispatch_work/3

16:52:55.052 [info]  Queueing job 128f902c-dd22-4706-95a2-89dc974b95d6 to retry in 24.0 seconds

我究竟做错了什么?

这是我的lib/my_worker.ex文件:

defmodule MyWorker do
  def perform(arg) do
    IO.puts("teste: " <> arg)
  end
end

和我的mix.exs

defmodule WorkersSandbox.MixProject do
  use Mix.Project

  def project do
    [
      app: :workers_sandbox,
      version: "0.1.0",
      elixir: "~> 1.10",
      start_permanent: Mix.env() == :prod,
      deps: deps()
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      applications: [:exq_ui, :exq],
      extra_applications: [:logger]
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:exq, "~> 0.14.0"},
      {:jason, "~> 1.0"},
      {:exq_ui, "~> 0.11.0"},
      {:plug_cowboy, "~> 2.0"}
    ]
  end
end

我的config/config.exs

import Config

config :exq,
  start_on_application: true,
  name: Exq,
  host: "127.0.0.1",
  port: 6379,
  # password: "",
  namespace: "exq",
  queues: [{"default", 10_000}, {"fila2", 10_000}],
  poll_timeout: 50,
  scheduler_poll_timeout: 200,
  scheduler_enable: true,
  max_retries: 25,
  mode: :default,
  shutdown_timeout: 5000
4

1 回答 1

1

本期所述,

您应该使用以下命令启动工作人员:

mix do app.start, exq.run

要不就

mix run --no-halt

应该在这些情况下工作。exq.run 混合任务只是启动 exq 应用程序,而不是主应用程序。更新了文档以明确这一点。

于 2020-11-09T15:17:34.923 回答