edgurgel / verk

A job processing system that just verks! 🧛‍
https://hex.pm/packages/verk
MIT License
721 stars 65 forks source link

Bump confex version to support documented config #172

Closed coop closed 5 years ago

coop commented 5 years ago

The documentation suggests that you do the following:

config :verk,
  queues: {:system, {MyApp.Env, :verk_queues, []}, "VERK_DISABLED"}

defmodule MyApp.Env do
  def verk_queues("true"), do: []
  def verk_queues(_), do: [default: 25, priority: 10]
end

Unfortunately this MFA style configuration was only introduced in confex 3.3. I have bumped the version of confex to ~> 3.3.0 so the documentation is correct. Is that any reason we can't bump to ~> 3.3?

coveralls commented 5 years ago

Coverage Status

Coverage remained the same at 87.891% when pulling 28841bce13b97cf7b6ae091146aa78729035a1ba on coop:fix-confex-version into cae9bea1426d5b340b3041b29453f17c709d70a8 on edgurgel:master.

coop commented 5 years ago

I also realised that confex's :system adapter expects "VERK_DISABLED" to be set otherwise an error is raised (this error isn't reported when starting up an app). I ended up implementing a custom adapter that handles the env var not being present:

config :verk,
  queues: {{:via, MyApp.Verk.Env}, {:queues, "VERK_DISABLED"}},
  max_retry_count: 10,
  poll_interval: 5000,
  start_job_log_level: :info,
  done_job_log_level: :info,
  fail_job_log_level: :info,
  node_id: "1",
  redis_url: "redis://127.0.0.1:6379"

defmodule MyApp.Verk.Env do
  def queues("true"), do: {:ok, []}

  def queues(_) do
    {:ok, [default: 25, other_queue: 1]}
  end

  def fetch_value({fun, key}) do
    value = System.get_env(key)

    apply(__MODULE__, fun, [value])
  end
end

This way my web processes (include dev) don't have to set an env var to get the "default" behaviour.

edgurgel commented 5 years ago

@coop, thank you for the PR! I will release a new minor version soon 👍

Would you mind updating the README with the custom adapter you showed here? Thanks again!