OxL Справочник OxL
РусскийEnglish

fn serve

Registers the recovery loop of a saga kind; called once at node start by the code the compiler generates. roles: the cluster roles that run sagas (comma separated, empty = every node).

Example:

oxl✓ проверяется в CI
@error data Boom { m: str }

service Bank {
  @public @idempotent rpc hold(n: u64) -> u64
  @public @idempotent rpc unhold(n: u64) -> () | Boom
  @public @idempotent rpc refuse(n: u64) -> u64 | Boom
}

impl Bank {
  rpc hold(n) => n
  rpc unhold(n) { fail Boom{ m: "bank is down" } }
  rpc refuse(n) { fail Boom{ m: "no" } }
}

// the second step fails and its compensation never succeeds: the saga becomes stuck
saga pay(n: u64) -> u64 {
  Bank.hold(n)   undo h => Bank.unhold(h)
  -> Bank.refuse(n)
}

fn main() io, net, time, db {
  // `pay` is registered with serve("main.pay", ...) by the generated code; calling it only starts a saga
  match pay(3) {
    u64 v => print("done {v}")
    Boom b => print("boom")
    CompensationFailed c => print("stuck at step {c.step}")
    NetError e => print("net error")
  }
}
Вывод
stuck at step 1
pub(api) fn serve<T: Serializable, effect F>(name: str, roles: str, run: fn(bytes) -> T F) net, db, time, F

Потокобезопасность. the loop runs in a task of the node; every claimed saga runs in a task of its own.

С версии. 1.0.0-beta

Параметры

ИмяТипОписание
namestr
rolesstr

the cluster roles that run sagas (comma separated, empty = every node).

runfn(bytes) -> T F

Эффекты

не объявлены (чистая, пока тело не говорит иное)

Определено в: std/saga/saga.oxl:852

См. также