Skip to content

Commit e00fa95

Browse files
Merge pull request #86 from RelationalAI/ss-txn-cancel
Support transaction cancellation
2 parents 9dadef1 + 199374b commit e00fa95

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

examples/cancel_transaction.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2021-2022 RelationalAI, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License
14+
15+
16+
import json
17+
from argparse import ArgumentParser
18+
from urllib.request import HTTPError
19+
20+
from railib import api, config, show
21+
22+
23+
def run(id: str, profile: str):
24+
cfg = config.read(profile=profile)
25+
ctx = api.Context(**cfg)
26+
rsp = api.cancel_transaction(ctx, id)
27+
print(json.dumps(rsp, indent=2))
28+
29+
30+
if __name__ == "__main__":
31+
p = ArgumentParser()
32+
p.add_argument("id", type=str, help="transaction id")
33+
p.add_argument("-p", "--profile", type=str,
34+
help="profile name", default="default")
35+
args = p.parse_args()
36+
try:
37+
run(args.id, args.profile)
38+
except HTTPError as e:
39+
show.http_error(e)

railib/api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class Permission(str, Enum):
118118
"get_transaction",
119119
"get_transaction_metadata",
120120
"get_transaction_results",
121+
"cancel_transaction",
121122
"get_user",
122123
"list_databases",
123124
"list_edbs",
@@ -303,6 +304,11 @@ def get_transaction_results(ctx: Context, id: str) -> list:
303304
return _parse_multipart(content_type, rsp.read())
304305

305306

307+
def cancel_transaction(ctx: Context, id: str) -> dict:
308+
rsp = rest.post(ctx, _mkurl(ctx, f"{PATH_TRANSACTIONS}/{id}/cancel"), {})
309+
return json.loads(rsp.read())
310+
311+
306312
def get_user(ctx: Context, userid: str) -> dict:
307313
return _get_resource(ctx, f"{PATH_USER}/{userid}", name=userid)
308314

0 commit comments

Comments
 (0)