2023-04-22 16:46:04 +12:00
|
|
|
defmodule AshOban do
|
|
|
|
@moduledoc """
|
|
|
|
Documentation for `AshOban`.
|
|
|
|
"""
|
2023-04-22 16:58:26 +12:00
|
|
|
|
|
|
|
defmodule Trigger do
|
|
|
|
@type t :: %__MODULE__{
|
|
|
|
action: atom,
|
2023-04-22 17:35:21 +12:00
|
|
|
where: Ash.Expr.t()
|
2023-04-22 16:58:26 +12:00
|
|
|
}
|
|
|
|
|
2023-04-22 17:35:21 +12:00
|
|
|
defstruct [:action, :where]
|
2023-04-22 16:58:26 +12:00
|
|
|
end
|
|
|
|
|
|
|
|
@trigger %Spark.Dsl.Entity{
|
|
|
|
name: :trigger,
|
|
|
|
target: Trigger,
|
2023-04-22 17:35:21 +12:00
|
|
|
args: [:action],
|
2023-04-22 16:58:26 +12:00
|
|
|
imports: [Ash.Filter.TemplateHelpers],
|
|
|
|
schema: [
|
|
|
|
action: [
|
|
|
|
type: :atom,
|
|
|
|
doc: "The action to be triggered"
|
|
|
|
],
|
2023-04-22 17:35:21 +12:00
|
|
|
where: [
|
2023-04-22 16:58:26 +12:00
|
|
|
type: :any,
|
|
|
|
doc: "The filter expression to determine if something should be triggered"
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
@triggers %Spark.Dsl.Section{
|
|
|
|
name: :triggers,
|
|
|
|
entities: [@trigger]
|
|
|
|
}
|
|
|
|
|
|
|
|
@oban %Spark.Dsl.Section{
|
|
|
|
name: :oban,
|
|
|
|
sections: [@triggers]
|
|
|
|
}
|
|
|
|
|
2023-04-22 17:35:21 +12:00
|
|
|
use Spark.Dsl.Extension,
|
|
|
|
sections: [@oban],
|
|
|
|
verifiers: [
|
|
|
|
# This is a bit dumb, a verifier probably shouldn't have side effects
|
|
|
|
AshOban.Verifiers.DefineSchedulers
|
|
|
|
]
|
2023-04-22 16:46:04 +12:00
|
|
|
end
|