improvement: add worker/scheduler priorities

This commit is contained in:
Zach Daniel 2023-08-23 18:24:53 -04:00
parent 76ede390d6
commit 9308cf0fff
2 changed files with 13 additions and 2 deletions

View file

@ -80,6 +80,16 @@ defmodule AshOban do
doc:
"If set, any given run of the scheduler will only ever schedule this many items maximum"
],
worker_priority: [
type: :pos_integer,
doc: "A number from 0 to 3, where 0 is the highest priority and 3 is the lowest.",
default: 2
],
scheduler_priority: [
type: :pos_integer,
doc: "A number from 0 to 3, where 0 is the highest priority and 3 is the lowest.",
default: 3
],
max_scheduler_attempts: [
type: :pos_integer,
default: 1,

View file

@ -45,6 +45,7 @@ defmodule AshOban.Transformers.DefineSchedulers do
defp define_scheduler(resource, scheduler_module_name, worker_module_name, trigger, dsl) do
api = AshOban.Info.oban_api!(dsl)
primary_key = Ash.Resource.Info.primary_key(dsl)
pro? = AshOban.Info.pro?()
filter =
@ -134,7 +135,7 @@ defmodule AshOban.Transformers.DefineSchedulers do
quoted =
quote location: :keep do
use unquote(worker),
priority: 1,
priority: unquote(trigger.worker_priority),
queue: unquote(trigger.scheduler_queue),
unique: [
period: :infinity,
@ -289,7 +290,7 @@ defmodule AshOban.Transformers.DefineSchedulers do
worker_module_name,
quote location: :keep do
use unquote(worker),
priority: 0,
priority: unquote(trigger.scheduler_priority),
max_attempts: unquote(trigger.max_attempts),
queue: unquote(trigger.queue),
unique: [