Skip to content

Commit

Permalink
RAI-8289 add suspend/resume functionality to julia sdk (#94)
Browse files Browse the repository at this point in the history
* Add suspend/resume functionality.

* add integration test to suspend/resume functionality
  • Loading branch information
janrous-rai authored Feb 16, 2023
1 parent d7ae333 commit 0adc238
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/RAI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export
create_engine,
delete_engine,
get_engine,
list_engines
list_engines,
suspend_engine,
resume_engine

export
delete_models,
Expand Down
16 changes: 15 additions & 1 deletion src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ function _request(ctx::Context, method, path; query = nothing, body = UInt8[], k
# _print_request(method, path, query, body);
try
rsp = @mock request(ctx, method, _mkurl(ctx, path); query = query, body = body, kw...)
return JSON3.read(rsp.body)
if length(rsp.body) == 0
return Dict()
else
return JSON3.read(rsp.body)
end
catch e
if e isa HTTP.ExceptionRequest.StatusError
throw(HTTPError(e.status, String(e.response.body)))
Expand Down Expand Up @@ -238,6 +242,16 @@ function create_engine(ctx::Context, engine::AbstractString; size = nothing, kw.
return _put(ctx, PATH_ENGINE; body = JSON3.write(data), kw...)
end

function suspend_engine(ctx::Context, engine::AbstractString; kw...)
payload=Dict("suspend" => true)
return _patch(ctx, "$PATH_ENGINE/$engine"; body=JSON3.write(payload), kw...)
end

function resume_engine(ctx::Context, engine::AbstractString; kw...)
payload=Dict("suspend" => false)
return _patch(ctx, "$PATH_ENGINE/$engine"; body=JSON3.write(payload), kw...)
end

function create_oauth_client(ctx::Context, name::AbstractString, permissions; kv...)
isnothing(permissions) && (permissions = [])
data = Dict("name" => name, "permissions" => permissions)
Expand Down
19 changes: 19 additions & 0 deletions test/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ const CTX = test_context()
# engine
@testset "engine" begin end

# -----------------------------------
# suspend and resume
with_engine(CTX) do engine_name
@testset "suspend" begin
suspend_engine(CTX, engine_name)
start_time = time()
_poll_with_specified_overhead(; POLLING_KWARGS..., start_time) do
eng = get_engine(CTX, engine_name)
return eng[:state] == "SUSPENDED" && eng[:suspend] == true
end
resume_engine(CTX, engine_name)
start_time = time()
_poll_with_specified_overhead(; POLLING_KWARGS..., start_time) do
eng = get_engine(CTX, engine_name)
return eng[:state] == "PROVISIONED" && eng[:suspend] == false
end
end
end

with_engine(CTX) do engine_name
# -----------------------------------
# database
Expand Down

0 comments on commit 0adc238

Please sign in to comment.