Last active
January 29, 2020 14:06
-
-
Save matchish/070ae36f2af77e94715c90b4f4ce0914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
commit = () => { connector.send('create-user', uid, pass) Filesystem.remove(this) })
does this belong to CreateUser class?