2023-09-01 03:25:05 +12:00
|
|
|
defmodule AshOban.Test.Triggered do
|
2023-12-13 03:44:35 +13:00
|
|
|
@moduledoc false
|
2023-09-01 03:25:05 +12:00
|
|
|
use Ash.Resource,
|
2024-03-30 12:52:22 +13:00
|
|
|
domain: AshOban.Test.Domain,
|
2023-09-01 03:25:05 +12:00
|
|
|
data_layer: Ash.DataLayer.Ets,
|
2024-02-21 07:02:43 +13:00
|
|
|
authorizers: [Ash.Policy.Authorizer],
|
2023-09-01 03:25:05 +12:00
|
|
|
extensions: [AshOban]
|
|
|
|
|
|
|
|
oban do
|
|
|
|
triggers do
|
|
|
|
trigger :process do
|
|
|
|
action :process
|
|
|
|
where expr(processed != true)
|
2024-02-21 07:02:43 +13:00
|
|
|
max_attempts 2
|
2023-09-01 03:25:05 +12:00
|
|
|
worker_read_action(:read)
|
|
|
|
end
|
|
|
|
|
|
|
|
trigger :process_2 do
|
|
|
|
action :process
|
|
|
|
where expr(processed != true)
|
2024-02-21 07:02:43 +13:00
|
|
|
max_attempts 2
|
2023-09-01 03:25:05 +12:00
|
|
|
worker_read_action(:read)
|
|
|
|
scheduler_cron false
|
|
|
|
end
|
|
|
|
end
|
2024-02-15 05:28:52 +13:00
|
|
|
|
|
|
|
scheduled_actions do
|
|
|
|
schedule :say_hello, "0 0 1 1 *"
|
|
|
|
end
|
2023-09-01 03:25:05 +12:00
|
|
|
end
|
|
|
|
|
2024-02-21 07:02:43 +13:00
|
|
|
policies do
|
|
|
|
policy action(:process) do
|
|
|
|
authorize_if actor_present()
|
|
|
|
end
|
|
|
|
|
|
|
|
policy always() do
|
|
|
|
authorize_if always()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-09-01 03:25:05 +12:00
|
|
|
actions do
|
|
|
|
defaults [:create]
|
|
|
|
|
|
|
|
read :read do
|
|
|
|
primary? true
|
|
|
|
pagination keyset?: true
|
|
|
|
end
|
|
|
|
|
|
|
|
update :process do
|
2024-05-03 16:01:40 +12:00
|
|
|
require_atomic? false
|
2023-09-01 03:25:05 +12:00
|
|
|
change set_attribute(:processed, true)
|
2024-02-21 07:02:43 +13:00
|
|
|
|
|
|
|
change fn changeset, context ->
|
|
|
|
send(self(), {:actor, context.actor})
|
|
|
|
changeset
|
|
|
|
end
|
2023-09-01 03:25:05 +12:00
|
|
|
end
|
2024-02-15 05:28:52 +13:00
|
|
|
|
|
|
|
action :say_hello, :string do
|
|
|
|
run fn input, _ ->
|
|
|
|
{:ok, "Hello"}
|
|
|
|
end
|
|
|
|
end
|
2023-09-01 03:25:05 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
ets do
|
|
|
|
private? true
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes do
|
|
|
|
uuid_primary_key :id
|
2024-02-21 07:02:43 +13:00
|
|
|
attribute :processed, :boolean, default: false, allow_nil?: false
|
2023-09-01 03:25:05 +12:00
|
|
|
end
|
|
|
|
end
|