diff --git a/EasyJobsBase/src/jobs.jl b/EasyJobsBase/src/jobs.jl index ac02ffb..90f315f 100644 --- a/EasyJobsBase/src/jobs.jl +++ b/EasyJobsBase/src/jobs.jl @@ -88,7 +88,10 @@ mutable struct ConditionalJob <: DependentJob parents::Set{AbstractJob} "These jobs runs after the current job." children::Set{AbstractJob} - function ConditionalJob(core::Think; name="", description="", username="") + skip_incomplete::Bool + function ConditionalJob( + core::Think, skip_incomplete=true; name="", description="", username="" + ) return new( uuid1(), core, @@ -102,6 +105,7 @@ mutable struct ConditionalJob <: DependentJob 0, Set(), Set(), + skip_incomplete, ) end end @@ -122,9 +126,9 @@ mutable struct ArgDependentJob <: DependentJob parents::Set{AbstractJob} "These jobs runs after the current job." children::Set{AbstractJob} - succeededonly::Bool + skip_incomplete::Bool function ArgDependentJob( - core::Think, succeededonly=true; name="", description="", username="" + core::Think, skip_incomplete=true; name="", description="", username="" ) return new( uuid1(), @@ -139,7 +143,7 @@ mutable struct ArgDependentJob <: DependentJob 0, Set(), Set(), - succeededonly, + skip_incomplete, ) end end diff --git a/EasyJobsBase/src/run.jl b/EasyJobsBase/src/run.jl index 4eae2cd..d83e454 100644 --- a/EasyJobsBase/src/run.jl +++ b/EasyJobsBase/src/run.jl @@ -1,6 +1,6 @@ using Thinkers: TimeoutException, ErrorInfo, reify!, setargs!, haserred, _kill -export run!, execute!, kill! +export shouldrun, run!, execute!, kill! # See https://github.com/MineralsCloud/SimpleWorkflows.jl/issues/137 """ @@ -123,16 +123,14 @@ prepare!(::AbstractJob) = nothing # No op function prepare!(job::ArgDependentJob) # Use previous results as arguments args = if countparents(job) == 1 - result = getresult(only(eachparent(job))) - if isnothing(result) # Parent job is pending or still running - # This means `job.succeededonly` must be `true` based on the logic - # Keep the arguments unchanged - @warn "the parent job is pending or still running! No arguments will be set!" - else # Parent job has succeeded or failed - something(result) + parent = only(eachparent(job)) + if issucceeded(parent) + something(getresult(parent)) + else + error("the parent job has failed!") end else # > 1 - parents = if job.succeededonly + parents = if job.skip_incomplete Iterators.filter(issucceeded, eachparent(job)) else eachparent(job) @@ -143,15 +141,15 @@ function prepare!(job::ArgDependentJob) return nothing end -shouldrun(::AbstractJob) = true -shouldrun(job::ConditionalJob) = - countparents(job) >= 1 && all(issucceeded(parent) for parent in eachparent(job)) -function shouldrun(job::ArgDependentJob) - if job.succeededonly - return countparents(job) >= 1 +shouldrun(::IndependentJob) = true +function shouldrun(job::Union{ConditionalJob,ArgDependentJob}) + if countparents(job) < 1 + return false + end + if job.skip_incomplete + return all(issucceeded(parent) for parent in eachparent(job)) else - return countparents(job) >= 1 && - all(issucceeded(parent) for parent in eachparent(job)) + return all(isexited(parent) for parent in eachparent(job)) end end diff --git a/EasyJobsBase/test/run.jl b/EasyJobsBase/test/run.jl index 2d9f6d4..3438206 100644 --- a/EasyJobsBase/test/run.jl +++ b/EasyJobsBase/test/run.jl @@ -111,14 +111,17 @@ end j = ArgDependentJob(Thunk(f₂, 3), false; username="he", name="j") k = ArgDependentJob(Thunk(f₃, 6), false; username="she", name="k") i → j → k - @test_throws AssertionError run!(j) + @test !shouldrun(j) + @test !shouldrun(k) exec = run!(i) wait(exec) @test getresult(i) == Some(25) - @test_throws AssertionError run!(k) + @test shouldrun(j) + @test !shouldrun(k) exec = run!(j) wait(exec) @test getresult(j) == Some(26) + @test shouldrun(k) exec = run!(k) wait(exec) @test getresult(k) == Some(13.0) @@ -134,15 +137,14 @@ end k = Job(Thunk(f₃, 6); username="she", name="k") l = ArgDependentJob(Thunk(f₄, ()); username="she", name="me") (i, j, k) .→ l - exec = run!(l) - wait(exec) - @test isfailed(l) + @test !shouldrun(l) execs = map((i, j, k)) do job run!(job) end for exec in execs wait(exec) end + @test shouldrun(l) l.core = Thunk(l.core) exec = run!(l) wait(exec) @@ -150,12 +152,13 @@ end @test getresult(j) == Some(4) @test getresult(k) == Some(3.0) @test getresult(l) == Some(32.0) - @testset "Change `succeededonly` to `false`" begin + @testset "Change `skip_incomplete` to `false`" begin i = Job(Thunk(f₁, 5); username="me", name="i") j = Job(Thunk(f₂, 3); username="he", name="j") k = Job(Thunk(f₃, 6); username="she", name="k") l = ArgDependentJob(Thunk(f₄, ()), false; username="she", name="me") (i, j, k) .→ l + @test !shouldrun(l) + @test_throws AssertionError run!(l) end - @test_throws AssertionError run!(l) end