Write your durable execution
Define your durable execution name, contract, and business logic.
Tourbillon durable executions require:
- A definition - the name of your durable execution and the input/output schema
- An implementation - the business logic of your durable execution
- A contracts file - required by Tourbillon to enable durable executions to be triggered
Definition
Definitions are written in protobuf.
echo/echo.proto
syntax = "proto3";
package echo;
import "tourbillon/annotations/v1/durable_service.proto";
option (tourbillon.annotations.v1.durable_services) = true;
service EchoService {
rpc Echo(EchoRequest) returns (EchoResponse);
}
message EchoRequest {
string message = 1;
}
message EchoResponse {
string message = 1;
}
Implementation
Implementations are written in Starlark.
echo/EchoService.star
load("time", "time")
def Echo(ctx, req)!:
pkg = proto.package("echo", contracts = ctx.contracts)
time.sleep(time.SECOND * 5)
return pkg.EchoResponse(message = req.message)
Test
echo/EchoService_test.star
load("//echo/EchoService.star", "Echo")
load("assert", "assert")
def test_echo(ctx)!:
"""Simple echo test"""
pkg = proto.package("echo", contracts = ctx.contracts)
res = Echo(ctx, pkg.EchoRequest(message = "durable"))
assert.eq(res.message, req.message)
Contracts
A contracts.binpb file is required by Tourbillon to read each available durable execution definition.
buf.yaml
version: "v2"
deps:
- buf.build/bckground/tourbillon-starlark
buf build -o contracts.binpb
Repository
The repository that Tourbillon will fetch periodically and implement in your Tourbillon runtime. These are connected to Tourbillon namespaces (see next step).
git init .
git checkout -b main
git add .
git commit -m "echo service"
git remote add origin git@github.com/my-org/durable-executions
git push -u origin main