Skip to content

Commit

Permalink
fix: only supply metadata if read_metadata is set
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Oct 7, 2023
1 parent 981e659 commit 72123d1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/transformers/define_schedulers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ defmodule AshOban.Transformers.DefineSchedulers do
end
end
else
quote location: :keep do
quote location: :keep, generated: true do
@impl unquote(worker)
def unquote(function_name)(%Oban.Job{args: %{"primary_key" => primary_key} = args} = job) do
AshOban.debug(
Expand All @@ -510,13 +510,18 @@ defmodule AshOban.Transformers.DefineSchedulers do
{:discard, :trigger_no_longer_applies}

{:ok, record} ->
args =
if unquote(is_nil(trigger.read_metadata)) do
%{}
else
%{metadata: args["metadata"]}
end

record
|> Ash.Changeset.new()
|> prepare(primary_key)
|> Ash.Changeset.set_context(%{private: %{ash_oban?: true}})
|> Ash.Changeset.for_action(unquote(trigger.action), %{
metadata: args["metadata"] || %{}
})
|> Ash.Changeset.for_action(unquote(trigger.action), args)
|> AshOban.update_or_destroy(unquote(api))
|> case do
:ok ->
Expand Down

0 comments on commit 72123d1

Please sign in to comment.