JuliaWebAPI.jl icon indicating copy to clipboard operation
JuliaWebAPI.jl copied to clipboard

Ability to add endpoints and redefine functions without restarting

Open tk3369 opened this issue 7 years ago • 1 comments

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.)

tk3369 avatar Mar 30 '18 06:03 tk3369

One way to get this working is to:

  • define and register or redefine a function
  • send the control command :terminate to request the task started by process to exit
  • wait for the task to exit
  • recreate the APIResponder and call process on it again

These steps can be packaged into a restart method to make it convenient.

tanmaykm avatar Apr 03 '18 16:04 tanmaykm