Skip to content

Commit

Permalink
feat: add manual? trigger flag to stop scheduler creation
Browse files Browse the repository at this point in the history
  • Loading branch information
rellen committed Aug 10, 2023
1 parent 1286db7 commit 3a3df2b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
16 changes: 14 additions & 2 deletions lib/ash_oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule AshOban do
state: :active | :paused | :deleted,
worker: module,
__identifier__: atom,
on_error: atom
on_error: atom,
manual?: boolean
}

defstruct [
Expand All @@ -38,6 +39,7 @@ defmodule AshOban do
:scheduler,
:worker,
:on_error,
:manual?,
:__identifier__
]

Expand Down Expand Up @@ -140,6 +142,12 @@ defmodule AshOban do
type: :atom,
doc:
"An update action to call after the last attempt has failed. See the getting started guide for more."
],
manual?: [
type: :boolean,
default: :false,
doc:
"Whether to only run the trigger manually (with `run_trigger`) instead of on a cron schedule."
]
]
}
Expand Down Expand Up @@ -252,7 +260,11 @@ defmodule AshOban do
end)
|> Enum.reduce(base, fn {resource, trigger}, config ->
require_queues!(config, resource, trigger)
add_job(config, cron_plugin, resource, trigger)
if trigger.manual? == false do
add_job(config, cron_plugin, resource, trigger)
else
config
end
end)
end

Expand Down
10 changes: 8 additions & 2 deletions lib/transformers/define_schedulers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ defmodule AshOban.Transformers.DefineSchedulers do
|> Transformer.async_compile(fn ->
define_worker(module, worker_module_name, trigger, dsl)
end)
|> Transformer.async_compile(fn ->
define_scheduler(module, scheduler_module_name, worker_module_name, trigger, dsl)
|> then(fn dsl ->
if trigger.manual? == false do
Transformer.async_compile(dsl, fn ->
define_scheduler(module, scheduler_module_name, worker_module_name, trigger, dsl)
end)
else
dsl
end
end)
end)
|> then(&{:ok, &1})
Expand Down
3 changes: 2 additions & 1 deletion lib/transformers/set_defaults.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ defmodule AshOban.Transformers.SetDefaults do
| read_action: read_action.name,
queue: queue,
scheduler_queue: trigger.scheduler_queue || queue,
action: trigger.action || trigger.name
action: trigger.action || trigger.name,
manual?: trigger.manual? || false
})
end)}
end
Expand Down

0 comments on commit 3a3df2b

Please sign in to comment.