I want to have a deamon running on a server and I would like to be able to change some parameters without restarting it.
My guess was that the best way to do that was by using a socket. I played a bit with genie and I ended up with a structure that works. Here’s a toy example:
using Genie, Genie.Router, Genie.Renderer.Json, Genie.Requests
using Dates
settings = Dict("a" => 1, "b" => 2, "c" => 3)
route("/config") do
settings |> json
end
route("/config", method = POST) do
payload = jsonpayload()
settings["a"] = payload["a"]
settings["b"] = payload["b"]
settings["c"] = payload["c"]
settings |> json
end
Genie.startup()
while true
print("$(Dates.now()): $(settings)\n")
sleep(10)
end
I can run this and it prints the dictionary. Then if I run the following
using HTTP
HTTP.request("POST", "http://localhost:8000/config", [("Content-Type", "application/json")], """{"a":0, "b":0,"c":0}""")
The dictionary changes. That’s basically the only thing I need. I don’t need access from outside the same machine.
So far so good, but is Genie an overkill? Should I do this in HTTP? Or maybe by using a linux socket? How easy is to implement this in HTTP or with a socket?