Idempotency
When making calls from within a
workflow
method (which requires
explicit idempotency), or outside of your Reboot application using an
ExternalContext
, you can use the .idempotently()
builder method:
- Python
- TypeScript
bank = Bank.ref(SINGLETON_BANK_ID)
await bank.idempotently().SignUp(
context,
customer_name="Initial User",
)
await Bank.ref(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.idempotently('open').Open(
context,
request.account_id,
Options(bearer_token=context.caller_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=...)
.