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: ThunkERROR: UndefVarError: `Thunks` not definedjulia> using SimpleWorkflows: Job, Workflow, run!, →ERROR: UndefVarError: `Job` not definedjulia> function f₁() println("Start job `i`!") sleep(5) endf₁ (generic function with 1 method)julia> function f₂(n) println("Start job `j`!") sleep(n) exp(2) endf₂ (generic function with 1 method)julia> function f₃(n) println("Start job `k`!") sleep(n) endf₃ (generic function with 1 method)julia> function f₄() println("Start job `l`!") run(`sleep 3`) endf₄ (generic function with 1 method)julia> function f₅(n, x) println("Start job `m`!") sleep(n) sin(x) endf₅ (generic function with 1 method)julia> function f₆(n; x = 1) println("Start job `n`!") sleep(n) cos(x) run(`pwd` & `ls`) endf₆ (generic function with 1 method)julia> i = Job(Thunk(f₁, ()); user = "me", desc = "i")ERROR: UndefVarError: `Thunk` not definedjulia> j = Job(Thunk(f₂, 3); user = "he", desc = "j")ERROR: UndefVarError: `Thunk` not definedjulia> k = Job(Thunk(f₃, 6); desc = "k")ERROR: UndefVarError: `Thunk` not definedjulia> l = Job(Thunk(f₄, ()); desc = "l", user = "me")ERROR: UndefVarError: `Thunk` not definedjulia> m = Job(Thunk(f₅, 3, 1); desc = "m")ERROR: UndefVarError: `Thunk` not definedjulia> n = Job(Thunk(f₆, 1; x = 3); user = "she", desc = "n")ERROR: UndefVarError: `Thunk` not definedjulia> i → lERROR: UndefVarError: `→` not definedjulia> j → k → m → nERROR: UndefVarError: `j` not definedjulia> j → lERROR: UndefVarError: `→` not definedjulia> k → nERROR: UndefVarError: `→` not definedjulia> 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: serializejulia> wf = serialize("wf.jls", wf)ERROR: UndefVarError: `wf` not definedjulia> 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à!