ash_oban/test/ash_oban_test.exs

66 lines
1.2 KiB
Elixir
Raw Normal View History

2023-04-22 16:58:26 +12:00
defmodule AshObanTest do
use ExUnit.Case
doctest AshOban
2023-04-28 14:07:05 +12:00
defmodule Api do
use Ash.Api
resources do
allow_unregistered? true
end
end
2023-04-22 16:58:26 +12:00
defmodule Triggered do
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
extensions: [AshOban]
oban do
triggers do
2023-04-28 14:07:05 +12:00
api Api
2023-04-22 17:35:21 +12:00
trigger :process do
2023-04-28 14:07:05 +12:00
action :process
2023-04-22 17:35:21 +12:00
where expr(processed != true)
worker_read_action(:read)
2023-04-22 17:35:21 +12:00
end
trigger :process_2 do
action :process
where expr(processed != true)
worker_read_action(:read)
scheduler_cron false
end
2023-04-22 16:58:26 +12:00
end
end
actions do
2023-04-28 14:07:05 +12:00
defaults [:create]
read :read do
primary? true
pagination keyset?: true
end
2023-04-22 16:58:26 +12:00
update :process do
change set_attribute(:processed, true)
end
end
ets do
private? true
end
attributes do
uuid_primary_key :id
end
end
test "foo" do
assert [
%AshOban.Trigger{action: :process},
%AshOban.Trigger{action: :process, scheduler: nil}
] = AshOban.Info.oban_triggers(Triggered)
2023-04-22 16:58:26 +12:00
end
end