This commit is contained in:
Zach Daniel 2023-04-21 23:35:21 -06:00
parent 223124bd77
commit 316a77a7f2
3 changed files with 27 additions and 6 deletions

View file

@ -6,23 +6,23 @@ defmodule AshOban do
defmodule Trigger do
@type t :: %__MODULE__{
action: atom,
condition: Ash.Expr.t()
where: Ash.Expr.t()
}
defstruct [:action, :condition]
defstruct [:action, :where]
end
@trigger %Spark.Dsl.Entity{
name: :trigger,
target: Trigger,
args: [:action, :condition],
args: [:action],
imports: [Ash.Filter.TemplateHelpers],
schema: [
action: [
type: :atom,
doc: "The action to be triggered"
],
condition: [
where: [
type: :any,
doc: "The filter expression to determine if something should be triggered"
]
@ -39,5 +39,10 @@ defmodule AshOban do
sections: [@triggers]
}
use Spark.Dsl.Extension, sections: [@oban]
use Spark.Dsl.Extension,
sections: [@oban],
verifiers: [
# This is a bit dumb, a verifier probably shouldn't have side effects
AshOban.Verifiers.DefineSchedulers
]
end

View file

@ -0,0 +1,14 @@
defmodule AshOban.Verifiers.DefineSchedulers do
use Spark.Dsl.Verifier
def verify(dsl_state) do
# TODO
# dsl_state
# |> AshOban.Info.oban_triggers()
# |> Enum.each(fn trigger ->
# IO.inspect(trigger)
# end)
:ok
end
end

View file

@ -9,7 +9,9 @@ defmodule AshObanTest do
oban do
triggers do
trigger :process, expr(processed != true)
trigger :process do
where expr(processed != true)
end
end
end