-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (42 loc) · 1.68 KB
/
main.py
File metadata and controls
53 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import sys
from scramjet.streams import Stream
async def run(context, input, *args):
"""
A Sequence that uses some basic HostClient's methods.
Parameters:
input (any): dummy input, it takes no params
Returns:
stream: output stream with data
"""
stream = Stream()
try:
# get version
version = await context.hub.get_version()
print(version)
context.logger.info(f"Host version called from Sequence: {version}")
# get load check
load_check = await context.hub.get_load_check()
print(load_check)
context.logger.info(f"Load check called from Sequence: {load_check}")
# get config
hub_config = await context.hub.get_config()
print(hub_config)
context.logger.info(f"Host config called from Sequence: {hub_config}")
# get status
status = await context.hub.get_status()
print(status)
context.logger.info(f"Host status called from Sequence: {status}")
# List sequences and write its length to output
seq_list = await context.hub.list_sequences()
stream.write(str(len(seq_list)))
context.logger.info(f"Sequence list called from Sequence: {seq_list}")
# List instances and write its length to output
inst_list = await context.hub.list_instances()
stream.write(str(len(inst_list)))
context.logger.info(f"Instance list called from Sequence: {inst_list}")
except Exception as e:
# if error occurs it will be logged under /instance/:id/stderr endpoint (CLI: si inst stderr <instID>)
print(e, file=sys.stderr)
finally:
stream.end()
return stream