Hello Everyone
I’m glad to announce a first draft version of Visor: a tasks supervisor for Julia.
The starting motivation sparkled some years ago around the “apparently simple” goal of controlling the shutdown of multi-tasks applications.
Visor
is influenced by Erlang Supervisor design principles with the aims to be as simple as possible.
Just to be an idea this is an extract from the README:
demo.jl
:
using Visor
# The only requirement for a task driven by Visor is that the first argument is
# a descriptor representing the supervised task, in this case `pd` is the
# descriptor of the `printer` process.
function printer(pd, device)
println("(re)starting printer driver")
receive(pd) do msg
device.jobcount += 1
print("processing $msg ... ")
if device.jobcount === 3
# unexpected printer failure
error("printer service panic error: $msg not printed")
end
println("done")
end
end
function controller(pd)
# The from(name) function returns a Visor task object from process name.
# The default name is the name of process task.
printer_process = from("printer")
for i in 1:8
# send a one-way message to the printer process.
cast(printer_process, "job-$i")
end
end
# needed for simulating a printer failure:
# when jobcount is equal to 3
mutable struct PrinterStatus
jobcount::Int
end
supervise([process(printer; args=(PrinterStatus(0),)), process(controller)])
myhost:~/$ julia demo.jl
(re)starting printer driver
processing job-1 ... done
processing job-2 ... done
processing job-3 ... ┌ Error: [printer] exception: ErrorException("printer service panick error: job-3 not printed")
└ @ Visor .../Visor.jl:1107
(re)starting printer driver
processing job-3 ... done
processing job-4 ... done
processing job-5 ... done
processing job-6 ... done
processing job-7 ... done
processing job-8 ... done
^C
myhost.~/$
Feedback welcome!
Attilio