Skip to content

Commit 0adc238

Browse files
authored
RAI-8289 add suspend/resume functionality to julia sdk (#94)
* Add suspend/resume functionality. * add integration test to suspend/resume functionality
1 parent d7ae333 commit 0adc238

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/RAI.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export
4343
create_engine,
4444
delete_engine,
4545
get_engine,
46-
list_engines
46+
list_engines,
47+
suspend_engine,
48+
resume_engine
4749

4850
export
4951
delete_models,

src/api.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ function _request(ctx::Context, method, path; query = nothing, body = UInt8[], k
207207
# _print_request(method, path, query, body);
208208
try
209209
rsp = @mock request(ctx, method, _mkurl(ctx, path); query = query, body = body, kw...)
210-
return JSON3.read(rsp.body)
210+
if length(rsp.body) == 0
211+
return Dict()
212+
else
213+
return JSON3.read(rsp.body)
214+
end
211215
catch e
212216
if e isa HTTP.ExceptionRequest.StatusError
213217
throw(HTTPError(e.status, String(e.response.body)))
@@ -238,6 +242,16 @@ function create_engine(ctx::Context, engine::AbstractString; size = nothing, kw.
238242
return _put(ctx, PATH_ENGINE; body = JSON3.write(data), kw...)
239243
end
240244

245+
function suspend_engine(ctx::Context, engine::AbstractString; kw...)
246+
payload=Dict("suspend" => true)
247+
return _patch(ctx, "$PATH_ENGINE/$engine"; body=JSON3.write(payload), kw...)
248+
end
249+
250+
function resume_engine(ctx::Context, engine::AbstractString; kw...)
251+
payload=Dict("suspend" => false)
252+
return _patch(ctx, "$PATH_ENGINE/$engine"; body=JSON3.write(payload), kw...)
253+
end
254+
241255
function create_oauth_client(ctx::Context, name::AbstractString, permissions; kv...)
242256
isnothing(permissions) && (permissions = [])
243257
data = Dict("name" => name, "permissions" => permissions)

test/integration.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ const CTX = test_context()
114114
# engine
115115
@testset "engine" begin end
116116

117+
# -----------------------------------
118+
# suspend and resume
119+
with_engine(CTX) do engine_name
120+
@testset "suspend" begin
121+
suspend_engine(CTX, engine_name)
122+
start_time = time()
123+
_poll_with_specified_overhead(; POLLING_KWARGS..., start_time) do
124+
eng = get_engine(CTX, engine_name)
125+
return eng[:state] == "SUSPENDED" && eng[:suspend] == true
126+
end
127+
resume_engine(CTX, engine_name)
128+
start_time = time()
129+
_poll_with_specified_overhead(; POLLING_KWARGS..., start_time) do
130+
eng = get_engine(CTX, engine_name)
131+
return eng[:state] == "PROVISIONED" && eng[:suspend] == false
132+
end
133+
end
134+
end
135+
117136
with_engine(CTX) do engine_name
118137
# -----------------------------------
119138
# database

0 commit comments

Comments
 (0)