Skip to content

Instantly share code, notes, and snippets.

@matchish
Last active January 29, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matchish/070ae36f2af77e94715c90b4f4ce0914 to your computer and use it in GitHub Desktop.
Save matchish/070ae36f2af77e94715c90b4f4ce0914 to your computer and use it in GitHub Desktop.
//We store all operations in a file
// then if transaction is failed we revert every operation
//transaction is failed if file lock was released
PreCreateUserHook.run(uid, pass)
tx = new Tx('create-user' + uid);
tx.add(new CreateUser(uid, pass))
PostCreateUserHook.run(uid, pass)
tx = Tx.find('create-user' + uid)
tx.commit()
BackgroundJob
Tx.all().each((tx) => tx.fail || tx.rollback())
class Tx {
commit = () => {
connector.send('create-user', uid, pass)
Filesystem.remove(this)
})
}
rollback = () => {
while (this.operations.length) {
tx.operations.pop().rollback()
}
}
add = (operation) => {
Filesystem.save(operation)
}
}
class CreateUser {
rollback: () => {
DeleteUser(uid)
//What if nextclloud crash ater user was deleted but before next line?
//In this case we'll try to delete user again after server up(operation should be idempotent).
Filesystem.remove(this)
}
}
@timLoewel
Copy link

commit = () => { connector.send('create-user', uid, pass) Filesystem.remove(this) })
does this belong to CreateUser class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment