Skip to content

Commit

Permalink
make initialization of inactive job possible
Browse files Browse the repository at this point in the history
This commit adds to ability to define a job in a config
as being inactive when initializing. This can be useful when
you want to define certain jobs that you want to set active
in the app at runtime without the need to configure the whole
job at runtime.
  • Loading branch information
drumusician committed Jun 2, 2019
1 parent f8bafb6 commit 723a436
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/quantum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Quantum do
timeout: 5_000,
schedule: nil,
overlap: true,
state: :active,
timezone: :utc,
run_strategy: {Random, :cluster},
debug_logging: true
Expand Down
4 changes: 3 additions & 1 deletion lib/quantum/job.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ defmodule Quantum.Job do
overlap when is_boolean(overlap) <- Keyword.fetch!(config, :overlap),
timezone when timezone == :utc or is_binary(timezone) <-
Keyword.fetch!(config, :timezone),
state when is_atom(state) <- Keyword.fetch!(config, :state),
schedule <- Keyword.get(config, :schedule) do
%__MODULE__{
name: name,
overlap: Keyword.fetch!(config, :overlap),
timezone: Keyword.fetch!(config, :timezone),
run_strategy: run_strategy,
schedule: schedule
schedule: schedule,
state: state
}
end
end
Expand Down
7 changes: 7 additions & 0 deletions test/quantum/job_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ defmodule Quantum.JobTest do

assert %Job{schedule: ^schedule, overlap: false} = Job.new(configs)
end

test "is is possible to initialize a job as inactive" do
configs = Scheduler.config(schedule: "*/7", overlap: false, state: :inactive)
schedule = ~e[*/7]

assert %Job{schedule: ^schedule, overlap: false, state: :inactive} = Job.new(configs)
end
end

0 comments on commit 723a436

Please sign in to comment.