JuliaWebAPI.jl
JuliaWebAPI.jl copied to clipboard
Ability to add endpoints and redefine functions without restarting
First, I ran the process async. Then, I want to either a new function but it came back with the world age issue.
julia> apiresponder = APIResponder("tcp://0.0.0.0:8890")
JuliaWebAPI.APIResponder with endpoints:
julia> function testfn1(arg1, arg2; narg1="1", narg2="2")
return (parse(Int, arg1) * parse(Int, narg1)) + (parse(Int, arg2) * parse(Int, narg2))
end
testfn1 (generic function with 1 method)
julia> register(apiresponder, testfn1)
JuliaWebAPI.APIResponder with endpoints:
"testfn1"
julia> process(apiresponder; async=true)
JuliaWebAPI.APIResponder with endpoints:
"testfn1"
Now, add and register a new function:
julia> testfn4(arg1, arg2) = test1(args1, args2)
testfn4 (generic function with 1 method)
julia> register(apiresponder, testfn4)
JuliaWebAPI.APIResponder with endpoints:
"testfn1", "testfn4"
Hit the testfn4 url and got this exception:
julia> 29-Mar 23:40:30:ERROR:root:api_exception: MethodError: no method matching testfn4(::String, ::String)
The applicable method may be too new: running in world age 21847, while current world is 21848.
Closest candidates are:
testfn4(::Any, ::Any) at REPL[7]:1 (method too new to be called from this world context.)
One way to get this working is to:
- define and register or redefine a function
- send the control command
:terminateto request the task started byprocessto exit - wait for the task to exit
- recreate the
APIResponderand callprocesson it again
These steps can be packaged into a restart method to make it convenient.