0

我正在尝试在苦艾酒中间件/3FunWithFlags.enabled?回调中使用(ref fwf ),但出现以下错误:

(ArgumentError) argument error
    (stdlib) :ets.lookup(:fun_with_flags_cache, :some_flag)

Stacktrace:
  │ lib/fun_with_flags/store/cache.ex:35: FunWithFlags.Store.Cache.get/1
  │ lib/fun_with_flags/store.ex:12: FunWithFlags.Store.lookup/1
  │ lib/fun_with_flags.ex:77: FunWithFlags.enabled?/2

我没有尝试太多。我只是缩小了问题发生的范围。我猜中间件在创建:some_flag record(或者可能是:fun_with_flags_cache表)之前编译,然后因为没有记录/表而失败。

这个链接说:

它将标志信息存储在 Redis 或关系数据库(PostgreSQL 或 MySQL,带有 Ecto)中,用于跨不同节点的持久性和同步,但它还在 ETS 表中维护本地缓存以进行快速查找。当在一个节点上添加或切换标志时,其他节点会通过 PubSub 通知并重新加载其本地 ETS 缓存。

我已经尝试使用以下配置禁用 ETS:

config :fun_with_flags, :cache,
  enabled: false,

但我没有工作。:(

这是我如何使用它的示例:

defmodule MyApp.Schema do
use Absinthe.Schema
...
  def middleware(middleware, field, object) do
  FunWithFlags.enabled?(:some_flag) # <-- (ArgumentError) argument error (stdlib) :ets.lookup...
  ...
  end
end

谢谢!

4

1 回答 1

0

由于文档明确提到了可能的竞争条件,我建议您按照文档的应用程序启动行为部分所述手动启动 FwF 应用程序。

mix.exs

- {:fun_with_flags, "~> 1.6"},
+ {:fun_with_flags, "~> 1.6", runtime: false},

在你的Application.start/1回调中:

  def start(_type, _args) do
    children = [
      ...,
+     FunWithFlags.Supervisor,
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
于 2021-09-23T13:04:02.360 回答