How to save and recover the status of a workflow?
Suppose you have a Workflow
object defined with the following code:
julia> using SimpleWorkflows.Thunks: Thunk
ERROR: UndefVarError: `Thunks` not defined
julia> using SimpleWorkflows: Job, Workflow, run!, →
ERROR: UndefVarError: `Job` not defined
julia> function f₁() println("Start job `i`!") sleep(5) end
f₁ (generic function with 1 method)
julia> function f₂(n) println("Start job `j`!") sleep(n) exp(2) end
f₂ (generic function with 1 method)
julia> function f₃(n) println("Start job `k`!") sleep(n) end
f₃ (generic function with 1 method)
julia> function f₄() println("Start job `l`!") run(`sleep 3`) end
f₄ (generic function with 1 method)
julia> function f₅(n, x) println("Start job `m`!") sleep(n) sin(x) end
f₅ (generic function with 1 method)
julia> function f₆(n; x = 1) println("Start job `n`!") sleep(n) cos(x) run(`pwd` & `ls`) end
f₆ (generic function with 1 method)
julia> i = Job(Thunk(f₁, ()); user = "me", desc = "i")
ERROR: UndefVarError: `Thunk` not defined
julia> j = Job(Thunk(f₂, 3); user = "he", desc = "j")
ERROR: UndefVarError: `Thunk` not defined
julia> k = Job(Thunk(f₃, 6); desc = "k")
ERROR: UndefVarError: `Thunk` not defined
julia> l = Job(Thunk(f₄, ()); desc = "l", user = "me")
ERROR: UndefVarError: `Thunk` not defined
julia> m = Job(Thunk(f₅, 3, 1); desc = "m")
ERROR: UndefVarError: `Thunk` not defined
julia> n = Job(Thunk(f₆, 1; x = 3); user = "she", desc = "n")
ERROR: UndefVarError: `Thunk` not defined
julia> i → l
ERROR: UndefVarError: `→` not defined
julia> j → k → m → n
ERROR: UndefVarError: `j` not defined
julia> j → l
ERROR: UndefVarError: `→` not defined
julia> k → n
ERROR: UndefVarError: `→` not defined
julia> wf = Workflow(k)
ERROR: UndefVarError: `Workflow` not defined
To save the Workflow
instance to disk while running in case it failed or is interrupted, use the serialize
function.
julia> using Serialization: serialize
julia> wf = serialize("wf.jls", wf)
ERROR: UndefVarError: `wf` not defined
julia> run!(wf)
ERROR: UndefVarError: `run!` not defined
After the above steps are finished, a saved.jls
file is saved to your local file system. Then you can close the current Julia session and restart it (which resembles an interrupted remote session, for example). To reload the workflow, run:
julia> using SimpleWorkflows
julia> using Serialization: deserialize
julia> deserialize("wf.jls")
And voilà!