diff --git a/python/hostclient-basic-py/main.py b/python/hostclient-basic-py/main.py new file mode 100644 index 00000000..f378d907 --- /dev/null +++ b/python/hostclient-basic-py/main.py @@ -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 ) + print(e, file=sys.stderr) + finally: + stream.end() + return stream \ No newline at end of file diff --git a/python/hostclient-basic-py/package.json b/python/hostclient-basic-py/package.json new file mode 100644 index 00000000..30e6204c --- /dev/null +++ b/python/hostclient-basic-py/package.json @@ -0,0 +1,22 @@ +{ + "name": "@scramjet/hostclient-basic-py", + "version": "0.1.0", + "main": "main.py", + "author": "Scramjet ", + "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" + } + } \ No newline at end of file diff --git a/python/hostclient-basic-py/requirements.txt b/python/hostclient-basic-py/requirements.txt new file mode 100644 index 00000000..f16f13cd --- /dev/null +++ b/python/hostclient-basic-py/requirements.txt @@ -0,0 +1 @@ +scramjet-framework-py \ No newline at end of file