Skip to content

Commit

Permalink
improvement: support overriding job opts in run_trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
janajri committed Sep 1, 2023
1 parent 776eec9 commit 1c3f5f6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/ash_oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ defmodule AshOban do
|> Oban.insert!()
end

def run_trigger(%resource{} = record, trigger) do
def run_trigger(%resource{} = record, trigger, oban_job_opts) do
trigger =
case trigger do
%AshOban.Trigger{} ->
Expand All @@ -257,7 +257,7 @@ defmodule AshOban do
end

%{primary_key: Map.take(record, primary_key), metadata: metadata}
|> trigger.worker.new()
|> trigger.worker.new(oban_job_opts)
|> Oban.insert!()
end

Expand Down
4 changes: 2 additions & 2 deletions lib/changes/builtin_changes.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule AshOban.Changes.BuiltinChanges do
@moduledoc "Builtin changes for `AshOban`"

def run_oban_trigger(trigger_name) do
{AshOban.Changes.RunObanTrigger, trigger: trigger_name}
def run_oban_trigger(trigger_name, oban_job_opts \\ []) do
{AshOban.Changes.RunObanTrigger, trigger: trigger_name, oban_job_opts: oban_job_opts}
end
end
2 changes: 1 addition & 1 deletion lib/changes/run_oban_trigger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule AshOban.Changes.RunObanTrigger do
end

Ash.Changeset.after_action(changeset, fn _changeset, result ->
AshOban.run_trigger(result, trigger)
AshOban.run_trigger(result, trigger, opts[:oban_job_opts] || [])
{:ok, result}
end)
end
Expand Down

0 comments on commit 1c3f5f6

Please sign in to comment.