littlehorse-enterprises / littlehorse

This repository contains the code for the LittleHorse Server, Dashboard, CLI, and Java/Go/Python SDK's. Brought to you by LittleHorse Enterprises LLC
https://littlehorse.dev/
Other
119 stars 11 forks source link

Allow Passing `NodeOutput` into Task #1119

Closed coltmcnealy-lh closed 1 week ago

coltmcnealy-lh commented 2 weeks ago

Right now, the following is illegal:

NodeOutput itemPrice = wf.execute("fetch-price", ....);

wf.execute("charge-customer", itemPrice);

You have to:

WfRunVariable itemPriceVar = wf.addVariable("item-price", INT);
wf.mutate(itemPriceVar, ASSIGN, wf.execute("fetch-price", ...);

wf.execute("charge-customer", itemPriceVar);

We should be able to do the following:

wf.execute("charge-customer", wf.execute("fetch-price", ...));

Implementation

This can be implemented on the client side. It should:

  1. Create an internal variable transparently.
  2. Assign the node output to that variable.
  3. Transparently use that variable.

This does not require changing the protobuf.

Rejected Alternative

A rejected alternative is to change the protobuf to allow referring to a NodeRun. The problem with this is:

coltmcnealy-lh commented 2 weeks ago

I started the implementation on this commit here: https://github.com/littlehorse-enterprises/littlehorse/commit/7517105b7c39d34d4cb254c8a385528a37fa226d

However, there are problems:

Solution: Require Client in Workflow

We now have output type information on a TaskDef and UserTaskDef. We can add it for an ExternalEventDef, which would mean that (with LH API access) we would be able to infer the output type of all nodes.

If the WfSpec builder SDK had access to a GRPC client, then we could simply fetch the required metadata from the server in order to compile it.

Advantages

We plan to enable better stacktraces and error handling by validating in-line during the compilation rather than just letting the LH Server return an error message with only node names. The only way to do that is to make the SDK call the LH API during node definition time (eg. WorkflowThread#execute()) and validate each step there. This would allow users to have a stacktrace from the specific line that caused a problem.

This means that we will have use-case for making the Workflow object require a client as well.

Disadvantages

Solution: Optionally Take Client

In this solution: