mirror of
https://github.com/ash-project/ash_oban.git
synced 2024-09-20 05:13:15 +12:00
improvement: support providing an otp app to schedule and run triggers
This commit is contained in:
parent
99a97b379d
commit
06c340569f
1 changed files with 42 additions and 45 deletions
43
lib/test.ex
43
lib/test.ex
|
@ -1,26 +1,10 @@
|
||||||
defmodule AshOban.Test do
|
defmodule AshOban.Test do
|
||||||
@moduledoc "Helpers for testing ash_oban triggers"
|
@moduledoc "Helpers for testing ash_oban triggers"
|
||||||
|
|
||||||
@mix_app Mix.Project.config()[:app]
|
def schedule_and_run_triggers(resource_or_api_or_otp_app) do
|
||||||
|
cond do
|
||||||
def schedule_and_run_triggers() do
|
Spark.Dsl.is?(resource_or_api_or_otp_app, Ash.Api) ->
|
||||||
@mix_app
|
resource_or_api_or_otp_app
|
||||||
|> IO.inspect()
|
|
||||||
|> Application.get_env(:ash_apis, [])
|
|
||||||
|> IO.inspect()
|
|
||||||
|> List.wrap()
|
|
||||||
|> Enum.reduce(%{}, fn api, acc ->
|
|
||||||
api
|
|
||||||
|> schedule_and_run_triggers()
|
|
||||||
|> Map.merge(acc, fn _key, left, right ->
|
|
||||||
left + right
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def schedule_and_run_triggers(resource_or_api) do
|
|
||||||
if Spark.Dsl.is?(resource_or_api, Ash.Api) do
|
|
||||||
resource_or_api
|
|
||||||
|> Ash.Api.Info.resources()
|
|> Ash.Api.Info.resources()
|
||||||
|> Enum.reduce(%{}, fn resource, acc ->
|
|> Enum.reduce(%{}, fn resource, acc ->
|
||||||
resource
|
resource
|
||||||
|
@ -29,12 +13,13 @@ defmodule AshOban.Test do
|
||||||
left + right
|
left + right
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
else
|
|
||||||
|
Spark.Dsl.is?(resource_or_api_or_otp_app, Ash.Resource) ->
|
||||||
triggers =
|
triggers =
|
||||||
AshOban.Info.oban_triggers(resource_or_api)
|
AshOban.Info.oban_triggers(resource_or_api_or_otp_app)
|
||||||
|
|
||||||
Enum.each(triggers, fn trigger ->
|
Enum.each(triggers, fn trigger ->
|
||||||
AshOban.schedule(resource_or_api, trigger)
|
AshOban.schedule(resource_or_api_or_otp_app, trigger)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
queues =
|
queues =
|
||||||
|
@ -50,6 +35,18 @@ defmodule AshOban.Test do
|
||||||
left + right
|
left + right
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
true ->
|
||||||
|
resource_or_api_or_otp_app
|
||||||
|
|> Application.get_env(:ash_apis, [])
|
||||||
|
|> List.wrap()
|
||||||
|
|> Enum.reduce(%{}, fn api, acc ->
|
||||||
|
api
|
||||||
|
|> schedule_and_run_triggers()
|
||||||
|
|> Map.merge(acc, fn _key, left, right ->
|
||||||
|
left + right
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue