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)
|
2023-07-20 06:18:15 +12:00
|
|
|
worker_read_action(:read)
|
2023-04-22 17:35:21 +12:00
|
|
|
end
|
2023-08-25 08:15:04 +12:00
|
|
|
|
|
|
|
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
|
2023-08-25 08:15:04 +12:00
|
|
|
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
|