Skip to content

Commit

Permalink
Solution: Support options configuration for unnamed job (#611)
Browse files Browse the repository at this point in the history
* Solution: Support options configuration for unnamed job

* remove keyword check
  • Loading branch information
fly49 committed Mar 27, 2024
1 parent 6cb0c7b commit efe1b77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/quantum/normalizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ defmodule Quantum.Normalizer do
normalize_options(base, %{schedule: schedule, task: task})
end

def normalize(%Job{} = base, {schedule, task, opts}) when is_list(opts) do
opts =
Enum.into(opts, %{})
|> Map.merge(%{schedule: schedule, task: task})

normalize_options(base, opts)
end

def normalize(%Job{} = _base, %Job{} = job) do
job
end
Expand Down
7 changes: 5 additions & 2 deletions test/quantum/normalizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,13 @@ defmodule Quantum.NormalizerTest do
test "unnamed job as tuple with arguments" do
schedule = ~e[* * * * *]
task = {MyModule, :my_method, [1, 2, 3]}
opts = [state: :inactive]

job = {"* * * * *", task}
job = {"* * * * *", task, opts}

assert %{schedule: ^schedule, task: ^task, name: name, state: :inactive} =
normalize(Scheduler.new_job(), job)

assert %{schedule: ^schedule, task: ^task, name: name} = normalize(Scheduler.new_job(), job)
assert is_reference(name)
end

Expand Down

0 comments on commit efe1b77

Please sign in to comment.