Your First Workflow
To implement a Tourbillon workflow you will need to:
- Define a service that will receive a request to execute and a return a workflow response (result)
- Implement the logic for your service using Starlark
We will use a simple calculator scenario to provide a practical example of how to implement a Tourbillon workflow.
Prerequisites
- TODO: Tourbillon CLI
- buf.build CLI
- gRPCurl
Defining your workflow interface
calculator/service.proto
syntax = "proto3";
package demo;
import "tourbillon/annotations/v1/durable_service.proto";
message CalculatorServiceRequest {
number x = 1;
number y = 2;
string operation = 3;
}
message CalculatorServiceResponse {
number n = 1;
}
service CalculatorService {
option (tourbillon.annotations.v1.durable_service) = true;
rpc Execute(CalculatorServiceRequest) returns (CalculatorServiceResponse);
}
Implementing your workflow logic
Each workflow definition requires an Execute function that accepts two arguments:
ctx: a context objectreq: the request received for the workflow execution
In this example the req is the Protobuf message demo.CalculatorServiceRequest as defined in the Proto.
demo/CalculatorService.star
def Execute(ctx, req):
# your code here...
This is where the coordination logic for your workflow will be implemented, using Starlark.
For example; we implement basic arithmetic to our workflow:
demo/CalculatorService.star
def Execute(ctx, req):
demo = proto.package("demo", contracts=ctx.contracts)
n = null
if req.operation == "+":
n = req.x + req.y
elif req.operation == "-":
n = req.x - req.y
elif req.operation == "*":
n = req.x * req.y
elif req.operation == "/":
n = req.x / req.y
return demo.CalculatorServiceResponse(n = n)
The return value for the function must be the Protobuf message, as defined in our Proto definition.
Deploying your workflow
TODO
Executing your workflow
curl -d '{"x":10,"y":10}' http://localhost:8000/demo.CalculatorService/Execute