Idempotency
If you'd like a guarantee that a call to a Reboot method happens exactly
once, you can call that method using the .idempotently()
builder method:
- Python
- TypeScript
bank = Bank.lookup(SINGLETON_BANK_ID)
await bank.idempotently().SignUp(
context,
customer_name="Initial User",
)
await Bank.construct({ id: SINGLETON_BANK_ID })
.idempotently()
.signUp(context, { customerName: "Initial User" });
If you need to call the same method on a state more than once using the same ExternalContext
or Context
, including when
you're doing manual retries, then you can specify an idempotency "alias" to
distinguish each call, for example:
- Python
- TypeScript
# Since we may manually retry the following call, we must
# provide idempotency, which we do via passing the string
# alias 'open'.
await Account.construct(
id=request.account_id,
).idempotently('open').Open(
context,
Options(bearer_token=context.bearer_token),
initial_deposit=(
request.initial_deposit
if request.HasField('initial_deposit') else None
),
)
await this.state.write("unlock", context, async (state) => {
state.userIdActive = "";
});
Reboot will deterministically generate an idempotency key given an
alias. You can also manually pass an idempotency key by calling
.idempotently(key=...)
.