Skip to content
Open
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
53 changes: 53 additions & 0 deletions python/hostclient-basic-py/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
22 changes: 22 additions & 0 deletions python/hostclient-basic-py/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "@scramjet/hostclient-basic-py",
"version": "0.1.0",
"main": "main.py",
"author": "Scramjet <open-source@scramjet.org>",
"license": "GPL-3.0",
"repository": {
"type": "git",
"url": "https://github.com/scramjetorg/transform-hub.git"
},
"engines": {
"python3": "3.9.0"
},
"scripts": {
"build:refapps": "yarn build:refapps:only",
"build:refapps:only": "mkdir -p dist/__pypackages__/ && cp *.py dist/ && pip3 install -t dist/__pypackages__/ -r requirements.txt",
"postbuild:refapps": "yarn prepack && yarn packseq",
"packseq": "PACKAGES_DIR=python node ../../scripts/packsequence.js",
"prepack": "PACKAGES_DIR=python node ../../scripts/publish.js",
"clean": "rm -rf ./dist"
}
}
1 change: 1 addition & 0 deletions python/hostclient-basic-py/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scramjet-framework-py