Skip to content

Commit

Permalink
v0.11.2: dependency checks and converts.
Browse files Browse the repository at this point in the history
  • Loading branch information
cihga39871 committed Jan 16, 2025
1 parent 5beeb33 commit da69919
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JobSchedulers"
uuid = "eeff360b-c02d-44d3-ab26-4013c616a17e"
authors = ["Jiacheng Chuan <[email protected]>"]
version = "0.11.1"
version = "0.11.2"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
6 changes: 6 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

v0.11.2

- Feat: add check for dependencies' job states when creating `Job`. Throw error immediately when invalid job state is found.
- Change: `Base.show(io::IO, job::Job)` prints better job's description.
- Fix: 32-bit system: `convert_dependency` and `convert_dependency_element` did not include all possible types.

v0.11.1

- Compat: 32-bit system.
Expand Down
2 changes: 1 addition & 1 deletion src/compat_pipelines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Job(p::Program;
cron::Cron = Cron(:none),
until::Union{DateTime,Period} = DateTime(9999),
priority::Int = 20,
dependency = Vector{Pair{Symbol,Union{Int,Job}}}(),
dependency = Vector{Pair{Symbol,Union{Int64,Job}}}(),
stdout = nothing,
stderr = nothing,
dir::AbstractString = "",
Expand Down
47 changes: 25 additions & 22 deletions src/jobs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ mutable struct Job
function Job(id::Integer, name::String, user::String, ncpu::Real, mem::Integer, schedule_time::ST, submit_time::DateTime, start_time::DateTime, stop_time::DateTime, wall_time::Period, cron::Cron, until::ST2, state::Symbol, priority::Int, dependency, task::Union{Task,Nothing}, stdout::Union{IO,AbstractString,Nothing}, stderr::Union{IO,AbstractString,Nothing}, _thread_id::Int, _func::Union{Function,Nothing}, _need_redirect::Bool = check_need_redirect(stdout, stderr), _group::AbstractString = "") where {ST<:Union{DateTime,Period}, ST2<:Union{DateTime,Period}}
check_ncpu_mem(ncpu, mem)
check_priority(priority)
new(Int64(id), name, user, Float64(ncpu), Int64(mem), period2datetime(schedule_time), submit_time, start_time, stop_time, wall_time, cron, period2datetime(until), state, priority, convert_dependency(dependency), task, stdout, stderr, _thread_id, _func, _need_redirect, _group, :nothing)
dep = convert_dependency(dependency)
check_dep(dep)
new(Int64(id), name, user, Float64(ncpu), Int64(mem), period2datetime(schedule_time), submit_time, start_time, stop_time, wall_time, cron, period2datetime(until), state, priority, dep, task, stdout, stderr, _thread_id, _func, _need_redirect, _group, :nothing)
end
end

Expand All @@ -99,7 +101,7 @@ function Job(task::Task;
cron::Cron = cron_none,
until::Union{DateTime,Period} = DateTime(9999),
priority::Int = 20,
dependency = Vector{Pair{Symbol,Int}}(),
dependency = Vector{Pair{Symbol,Union{Int64, Job}}}(),
stdout=nothing, stderr=nothing, append::Bool=false
)
if ncpu > 1.001
Expand Down Expand Up @@ -152,7 +154,7 @@ function Job(f::Function;
cron::Cron = cron_none,
until::Union{DateTime,Period} = DateTime(9999),
priority::Int = 20,
dependency = Vector{Pair{Symbol,Int}}(),
dependency = Vector{Pair{Symbol,Union{Int64, Job}}}(),
stdout=nothing, stderr=nothing, append::Bool=false
)
if ncpu > 1.001
Expand Down Expand Up @@ -204,7 +206,7 @@ function Job(command::Base.AbstractCmd;
cron::Cron = cron_none,
until::Union{DateTime,Period} = DateTime(9999),
priority::Int = 20,
dependency = Vector{Pair{Symbol,Int}}(),
dependency = Vector{Pair{Symbol,Union{Int64, Job}}}(),
stdout=nothing, stderr=nothing, append::Bool=false
)
f() = run(command)
Expand Down Expand Up @@ -276,6 +278,15 @@ function check_priority(priority::Int)
end
end

function check_dep(dependency::Vector{Pair{Symbol,Union{Int64, Job}}})
length(dependency) == 0 && (return)
for p in dependency
if !(p.first in [QUEUING, RUNNING, DONE, FAILED, CANCELLED, PAST])
error("invalid job state (:$(p.first)) found in Job's dependency ($(p.first) => $(p.second)). Possible Job states are QUEUING, RUNNING, DONE, FAILED, CANCELLED, PAST")
end
end
end

check_need_redirect(stdout::Nothing, stderr::Nothing) = false
check_need_redirect(stdout, stderr) = check_need_redirect(stdout) && check_need_redirect(stderr)

Expand All @@ -284,24 +295,16 @@ check_need_redirect(io::IO) = true
check_need_redirect(x::Nothing) = false
check_need_redirect(x::Any) = error("$x is not valid for redirecting IO: not IO, file_path::AbstractString, or nothing.")

function convert_dependency(dependency::Vector{Pair{Symbol,Union{Int64, Job}}})
dependency
end
function convert_dependency(dependency::Vector)
Pair{Symbol,Union{Int64, Job}}[convert_dependency_element(d) for d in dependency]
end
function convert_dependency(dependency)
Pair{Symbol,Union{Int64, Job}}[convert_dependency_element(dependency)]
end
function convert_dependency_element(p::Pair{Symbol,T}) where T # do not specify T's type!!!
p
end
function convert_dependency_element(job::Job)
DONE => job
end
function convert_dependency_element(job::Integer)
DONE => Int64(job)
end
convert_dependency(dependency::Vector{Pair{Symbol,Union{Int64, Job}}}) = dependency
convert_dependency(dependency::Vector) = Pair{Symbol,Union{Int64, Job}}[convert_dependency_element(d) for d in dependency]
convert_dependency(dependency) = Pair{Symbol,Union{Int64, Job}}[convert_dependency_element(dependency)]

convert_dependency_element(p::Pair{Symbol,Job}) = p
convert_dependency_element(p::Pair{Symbol,Int64}) = p
convert_dependency_element(p::Pair{Symbol,<:Integer}) = p.first => Int64(p.second)
convert_dependency_element(p::Pair) = Symbol(p.first) => (p.second isa Job ? p.second : Int64(p.second))
convert_dependency_element(job::Job) = DONE => job
convert_dependency_element(job::Integer) = DONE => Int64(job)

"""
isqueuing(j::Job) :: Bool
Expand Down
6 changes: 5 additions & 1 deletion src/pretty_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ end
end

function Base.show(io::IO, job::Job)
print(io, "Job $(job.id) ($(job.state)): $(job.name)")
if isempty(job.name)
print(io, "Job($(job.id): $(job.state))")
else
print(io, "Job($(job.id) \"$(job.name)\": $(job.state))")
end
end

function Base.show(io::IO, ::MIME"text/plain", job_queue::Vector{Job};
Expand Down

0 comments on commit da69919

Please sign in to comment.