Skip to main content

Write your durable execution

Define your durable execution name, contract, and business logic.

Tourbillon durable executions require:

  • A definition, written in protobuf
  • An implementation, written in Starlark
  • A contracts file, compiled with buf

Example

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
def Echo(ctx, req)!:
pkg = proto.package("echo", contracts = ctx.contracts)
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)
req = pkg.EchoRequest(message = "durable")
res = Echo(ctx, req)
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

We now create our repository and push to remote.

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