Extendable transaction system, to build workflows with commit/rollback semantics.
Project description
Rstransaction is a python2/python3 toolbox to create transactional systems, for any kind of operations: in-memory, on filesystems, on remote storages…
It supports commits/rollbacks and savepoints.
It was never used in production, but is well tested, and easily extendable to support different kinds of behaviour : immediate or lazy actions, recording of operations to disk files or DBs in case of crash, auto-rollback on error or not…
INSTALL
Using pip is recommended, although installing from a checkout of the repository (via setup.py) also works:
$ pip install rstransaction
USAGE
Your best bet is to read the sources (especially tests).
The idea is to create “atomic” operations using TransactionalActionAdapter. Each of these operations knows how to operate, how to rollback itself, and also how to preprocess its arguments so that they are unambiguous (ex. turn relative file names into absolute ones).
These actions are then registered near a TransactionalActionRegistry.
An action recorder has to be chosen (the default one, ActionRecorderBase, simply records actions in-memory, without persistence).
A transaction processor (inheriting TransactionBase) is then instantiated, and given the action registry as well as the action recorder. The default transaction processor, InteractiveTransaction, executes any operation (issued with tx_process_action()), immediately, so potential errors must be handled accordingly. But one could implement a transaction processor which delays all operations until commit time.
Transaction steps can be set manually (with tx_commit(), tx_rollback(), savepoint methods..), but the best is to use the transaction processor as a context manager (with keyword), so that full commit/rollback occur automatically on exit. The “tx_savepoint” attribute of transaction processor can also be used as a context manager, only acting on a savepoint this time.
A transaction processor automatically begins a new transaction, on commit or rollback, so it can be reused.
Note that exceptions do not get swallowed by this system, even if an automatic rollback occurs.
Subclasses of TransactionFailure are used to report errors linked to the transaction systemn, as exceptions.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file RSTransaction-0.2.tar.gz
.
File metadata
- Download URL: RSTransaction-0.2.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/2.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e1c4f9751d4a6a38531daade393a4af00cb41678fddf19913c42080c436f55c |
|
MD5 | c986c57af225ecb77a1e4f7cd49d8179 |
|
BLAKE2b-256 | a18cc0a1f4479348feb45f88b563136bbed9751f321d1b40f8dde48f62cb3e11 |