-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add suspend/resume engine to the api (#150)
* Add suspend/resume engine to the api * Fix docs * Feedback changes
- Loading branch information
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2021 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 | ||
|
||
"""Resume an engine.""" | ||
|
||
from argparse import ArgumentParser | ||
import json | ||
import time | ||
from urllib.request import HTTPError | ||
from railib import api, config, show | ||
|
||
|
||
def run(engine: str, profile: str): | ||
cfg = config.read(profile=profile) | ||
ctx = api.Context(**cfg) | ||
api.resume_engine_wait(ctx, engine) | ||
print(json.dumps(api.get_engine(ctx, engine), indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
p = ArgumentParser() | ||
p.add_argument("engine", type=str, help="engine name") | ||
p.add_argument("-p", "--profile", type=str, help="profile name", default="default") | ||
args = p.parse_args() | ||
try: | ||
run(args.engine, args.profile) | ||
except HTTPError as e: | ||
show.http_error(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2021 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 | ||
|
||
"""Suspend an engine.""" | ||
|
||
from argparse import ArgumentParser | ||
import json | ||
import time | ||
from urllib.request import HTTPError | ||
from railib import api, config, show | ||
|
||
|
||
# Answers if the given state is a terminal state. | ||
def is_term_state(state: str) -> bool: | ||
return state == "SUSPENDED" or ("FAILED" in state) | ||
|
||
|
||
def run(engine: str, profile: str): | ||
cfg = config.read(profile=profile) | ||
ctx = api.Context(**cfg) | ||
rsp = api.suspend_engine(ctx, engine) | ||
while True: # wait for request to reach terminal state | ||
time.sleep(3) | ||
rsp = api.get_engine(ctx, engine) | ||
if not rsp or is_term_state(rsp["state"]): | ||
break | ||
print(json.dumps(rsp, indent=2)) | ||
|
||
|
||
if __name__ == "__main__": | ||
p = ArgumentParser() | ||
p.add_argument("engine", type=str, help="engine name") | ||
p.add_argument("-p", "--profile", type=str, help="profile name", default="default") | ||
args = p.parse_args() | ||
try: | ||
run(args.engine, args.profile) | ||
except HTTPError as e: | ||
show.http_error(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters