-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: add test helper for running triggers
- Loading branch information
1 parent
b5ef503
commit 6f9e6ff
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
defmodule AshOban.Test do | ||
@moduledoc "Helpers for testing ash_oban triggers" | ||
|
||
def schedule_and_run_triggers(resource) do | ||
triggers = | ||
AshOban.Info.oban_triggers(resource) | ||
|
||
Enum.each(triggers, fn trigger -> | ||
AshOban.schedule(resource, trigger) | ||
end) | ||
|
||
triggers | ||
|> Enum.map(& &1.queue) | ||
|> Enum.uniq() | ||
|> Enum.reduce(%{}, fn queue, acc -> | ||
queue | ||
|> Oban.drain_queue() | ||
|> Map.merge(acc, fn _key, left, right -> | ||
left + right | ||
end) | ||
end) | ||
end | ||
end |