Skip to content

Commit 6fb7f7e

Browse files
S4Adama-tylenda
authored andcommitted
Add HostClient-start-seq-py Sequence
1 parent bd02542 commit 6fb7f7e

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sys
2+
from scramjet.streams import Stream
3+
4+
5+
async def run(context, input, *args):
6+
"""
7+
Sequence that starts any other Sequence, by giving its id as an argument.
8+
9+
Parameters:
10+
input (any): dummy input, it takes no params
11+
*args (tuple): Sequences ids that will be started
12+
13+
Returns:
14+
stream: output stream with ids of started Instances
15+
"""
16+
stream = Stream()
17+
context.logger.info("Working...")
18+
try:
19+
# for each element in args tuple
20+
for seq_id in args:
21+
# get Sequence object
22+
seq = await context.hub.get_sequence(seq_id)
23+
context.logger.info(f"Sequence client called: {seq.id}")
24+
25+
inst = await seq.start()
26+
context.logger.info(f"Sequence {seq_id} started: {inst.id}")
27+
stream.write(inst.id)
28+
29+
except Exception as e:
30+
# if error occurs it will be logged under /instance/:id/stderr endpoint (CLI: si inst stderr <instID>)
31+
print(e, file=sys.stderr)
32+
finally:
33+
stream.end()
34+
return stream
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "@scramjet/hostclient-start-seq-py",
3+
"version": "0.1.0",
4+
"main": "main.py",
5+
"author": "Scramjet <open-source@scramjet.org>",
6+
"description": "Sequence that starts any other Sequence, by providing its id as an argument.",
7+
"license": "GPL-3.0",
8+
"repository": {
9+
"type": "git",
10+
"url": "https://github.com/scramjetorg/transform-hub.git"
11+
},
12+
"engines": {
13+
"python3": "3.9.0"
14+
},
15+
"scripts": {
16+
"build:refapps": "yarn build:refapps:only",
17+
"build:refapps:only": "mkdir -p dist/__pypackages__/ && cp *.py dist/ && pip3 install -t dist/__pypackages__/ -r requirements.txt",
18+
"postbuild:refapps": "yarn prepack && yarn packseq",
19+
"packseq": "PACKAGES_DIR=python node ../../scripts/packsequence.js",
20+
"prepack": "PACKAGES_DIR=python node ../../scripts/publish.js",
21+
"clean": "rm -rf ./dist"
22+
}
23+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scramjet-framework-py

0 commit comments

Comments
 (0)