Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/cancel-transaction.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 RelationalAI, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

# Fetch details for the given database.

using RAI: Context, HTTPError, load_config, cancel_transaction

include("parseargs.jl")

function run(id; profile)
cfg = load_config(; profile = profile)
ctx = Context(cfg)
rsp = cancel_transaction(ctx, id)
println(rsp)
end

function main()
args = parseargs(
"id", Dict(:help => "transaction id", :required => true),
"--profile", Dict(:help => "config profile (default: default)"))
try
run(args.id; profile = args.profile)
catch e
e isa HTTPError ? show(e) : rethrow()
end
end

main()
5 changes: 5 additions & 0 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ function get_transaction_results(ctx::Context, id::AbstractString; kw...)
return _parse_multipart_results_response(rsp)
end

function cancel_transaction(ctx::Context, id::AbstractString; kw...)
path = PATH_ASYNC_TRANSACTIONS * "/$id/cancel"
return _post(ctx, path)
end
Comment on lines +651 to +654
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a unit test for this? Probably it doesn't need to be an integration test; just a unit test that confirms that the correct path is hit with a POST request?

Thank you!


function _parse_multipart_fastpath_sync_response(msg)
# TODO: in-place conversion to Arrow without copying the bytes.
# ... HTTP.parse_multipart_form() copies the bytes into IOBuffers.
Expand Down