Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
server: add a notify service status This will be useful for monitors to inform what is the status of the services they are overseeing
cmd/beterrabad/executor.ha | 21 +++++++++++++++++++++ cmd/beterrabad/socket.ha | 3 +++
diff --git a/cmd/beterrabad/executor.ha b/cmd/beterrabad/executor.ha index 881328df472366d0156b20e1f20838909c424085..9600bb0b5837b3799d3e5f786114fd579d789f6d 100644 --- a/cmd/beterrabad/executor.ha +++ b/cmd/beterrabad/executor.ha @@ -53,6 +53,27 @@ }; }; }; +fn notify_service(status: str, svcname: str, serv: *server) str = { + log::printfln("Notified on {}", svcname); + let service: nullable *beterraba::service = null; + + for (let i = 0z; i < len(serv.services); i += 1) { + if (serv.services[i].name == svcname) { + service = &serv.services[i]; + break; + }; + }; + + match (service) { + case null => + return "Didn't find a service with that name"; + case let svc: *beterraba::service => + svc.status = beterraba::statusfromstr(status); + log::println("Set svc status to {}", beterraba::strstatus(svc.status)); + return "ack"; + }; +}; + fn list_services(cmdargs: str, serv: *server) str = { let names: []str = []; defer free(names); diff --git a/cmd/beterrabad/socket.ha b/cmd/beterrabad/socket.ha index d5e2c6b9833dc5233e53c18477f0e73ee5d8babf..064197719e037cea7922110dbe5c097893e0ede0 100644 --- a/cmd/beterrabad/socket.ha +++ b/cmd/beterrabad/socket.ha @@ -196,6 +196,9 @@ fmt::fprintf(&buf, status)?; case "status" => let status = status_service(args, server); fmt::fprintf(&buf, status)?; + case "started" => + let status = notify_service("started", args, server); + fmt::fprintf(&buf, status)?; case "list" => let status = list_services(args, server); fmt::fprintf(&buf, status)?;