yarrichar
yarrichar5mo ago

When does a mutation commit?

I assume this is a silly question, but I'm just wanting to check that if I call a mutation from an action that the mutation will have succeeded or failed when the mutation call returns? I'm basically wanting to do:
actionA:
runMutation(lockRecord);
try {
// do stuff while I'm holding the lock
} finally {
runMutation(releaseRecord);
}
actionA:
runMutation(lockRecord);
try {
// do stuff while I'm holding the lock
} finally {
runMutation(releaseRecord);
}
Just asking because queries and mutations are deterministic, and the talk in the docs about it being safe to retry them.
2 Replies
lee
lee5mo ago
The mutation has committed by the time await ctx.runMutation in an action returns. So you can use mutations to take locks. Note that actions can fail at any point, so it's not guaranteed that the finallyMutation will run. If you want to make sure that the lock gets released, you will need a backup method to release locks that have been held for too long.
yarrichar
yarricharOP5mo ago
Great, thanks. Yeah, I'm storing the lock as <requestId>:<timestamp> to handle that case. It also lets me make sure that I don't release a lock someone else has acquired (if the lock times out before the action).

Did you find this page helpful?