ueberauth / guardian_db

Guardian DB integration for tracking tokens and ensuring logout cannot be replayed.
MIT License
368 stars 87 forks source link

`Guardian.DB.Sweeper` incompatible with old worker API #144

Open RichDom2185 opened 1 year ago

RichDom2185 commented 1 year ago

Steps to Reproduce

Configure using the old (deprecated) worker(...) notation (as defined in the examples in lib/guardian/db.ex):

children = [
  worker(Guardian.DB.Sweeper, [interval: 60])
]

Expected Result

Configures the worker correctly, just like as if it were called using the new notation (as defined in the README):

children = [
  {Guardian.DB.Sweeper, [interval: 60]}
]

Actual Result

shutdown: failed to start child: Guardian.DB.Sweeper
    ** (EXIT) an exception was raised:
        ** (FunctionClauseError) no function clause matching in Keyword.get/3
            (elixir 1.13.4) lib/keyword.ex:352: Keyword.get({:interval, 180000}, :interval, 3600000)
            (guardian_db 3.0.0) lib/guardian/db/sweeper.ex:19: Guardian.DB.Sweeper.start_link/1
            (stdlib 4.3.1) supervisor.erl:414: :supervisor.do_start_child_i/3
            (stdlib 4.3.1) supervisor.erl:400: :supervisor.do_start_child/2
            (stdlib 4.3.1) supervisor.erl:384: anonymous fn/3 in :supervisor.start_children/2
            (stdlib 4.3.1) supervisor.erl:1250: :supervisor.children_map/4
            (stdlib 4.3.1) supervisor.erl:350: :supervisor.init_children/2
            (stdlib 4.3.1) gen_server.erl:851: :gen_server.init_it/2
            (stdlib 4.3.1) gen_server.erl:814: :gen_server.init_it/6
            (stdlib 4.3.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
yordis commented 1 year ago

Weird, I do not see the child_spec but it works doing the following:

test "testing supervisor" do
    children = [
      {Guardian.DB.Sweeper, [interval: 60 * 60 * 1000]}
    ]

    assert {:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one)
    assert %{active: 1, specs: 1, supervisors: 0, workers: 1} = Supervisor.count_children(pid)
  end

What elixir and erlang version are you using?