|
| 1 | +import json |
| 2 | +from typing import Any, Optional |
| 3 | + |
| 4 | +from . import __identifier__, __version__ |
| 5 | + |
| 6 | + |
| 7 | +async def do_thing(message: dict[str, Any], context: dict[str, Any]) -> dict[str, Any]: |
| 8 | + """Process some incoming data.""" |
| 9 | + # All debugging information MUST be output in stderr. you can just use the logging |
| 10 | + # module or if you are a die hard print debugger use this instead: |
| 11 | + # print("My debug!", file=sys.stderr) |
| 12 | + |
| 13 | + return message |
| 14 | + |
| 15 | + |
| 16 | +if __name__ == "__main__": |
| 17 | + import asyncio |
| 18 | + import sys |
| 19 | + |
| 20 | + # message is the input to your function. This is the output from the previous |
| 21 | + # function plus any transformations the user defined in their workflow. Parameters |
| 22 | + # should be documented in the parameters.json file so they can be used in the UI. |
| 23 | + try: |
| 24 | + message = json.loads(sys.argv[1]) |
| 25 | + except IndexError: |
| 26 | + raise ValueError("missing required `message` argument") from None |
| 27 | + |
| 28 | + # this contains some contextual information about the workflow and the current |
| 29 | + # state. required secrets should be defined in the README so users can write their |
| 30 | + # lookup class with this node's unique requirements in mind. |
| 31 | + try: |
| 32 | + context = json.loads(sys.argv[2]) |
| 33 | + except IndexError: |
| 34 | + raise ValueError("missing `context` argument") from None |
| 35 | + |
| 36 | + output = asyncio.run(do_thing(message, context)) |
| 37 | + |
| 38 | + # Non-zero exit codes indicate to the executor there was an unrecoverable error and |
| 39 | + # workflow execution should terminate. |
| 40 | + if output is None: |
| 41 | + sys.exit(1) |
| 42 | + |
| 43 | + # The output of your function is input for a potential next state. It must be in |
| 44 | + # JSON format and be the only thing output on stdout. This value is picked up by the |
| 45 | + # executor and processed. |
| 46 | + print(json.dumps(output)) |
0 commit comments