Simple async sagas package
Project description
SAGAS
A simple async sagas implementation
Installation
$ pip install pysagas
Usage
Simple example
import asyncio
from sagas import SagaBuilder
counter = [10, 20]
amount = 30
def add(amount, index):
"""Increments array index by amount
Args:
amount (int): increment value
index (int): index of value to increment
"""
counter[index] += amount
def decrement(amount, index):
"""Decrements array index by amount
Args:
amount (int): decrement value
index (int): index of value to decrement
"""
counter[index] -= amount
return counter
saga_builder = SagaBuilder.create()
saga = saga_builder\
.add_step(lambda: add(amount, 0), lambda: decrement(amount, 0))\
.add_step(lambda: add(amount, 1), lambda: decrement(amount, 1))\
.build()
if __name__ == "__main__":
asyncio.run(saga.run(exceptions=(OSError)))
print(counter) # [40, 50]
Failure example
If one step fails, the compensating functions for the executed steps run and the counter values are compensated
import asyncio
from sagas import SagaBuilder
counter = [10, 20]
amount = 30
def add(amount, index):
"""Increments array index by amount
Args:
amount (int): increment value
index (int): index of value to increment
"""
counter[index] += amount
raise Exception('error occurred')
def decrement(amount, index):
"""Decrements array index by amount
Args:
amount (int): decrement value
index (int): index of value to decrement
"""
counter[index] -= amount
return counter
saga_builder = SagaBuilder.create()
saga = saga_builder\
.add_step(lambda: add(amount, 0), lambda: decrement(amount, 0))\
.add_step(lambda: add(amount, 1), lambda: decrement(amount, 1))\
.build()
if __name__ == "__main__":
asyncio.run(saga.run(exceptions=(OSError, Exception)))
print(counter) # [10, 20]
CHANGES
- add test step
- add unit tests
- ch(docs):add documentation- add readme docs- add usage examples
0.0.2
- rename package
- add changelog
- add setup.py file
0.0.1
- remove example
- Setup publishing to pypi
- initial commit
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
pysagas-0.0.3.tar.gz
(5.7 kB
view details)
Built Distribution
File details
Details for the file pysagas-0.0.3.tar.gz
.
File metadata
- Download URL: pysagas-0.0.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
fac84cabaadb0cc018ff0b9aba7f2b45238dc3c97fe09015de53d32c2133d454
|
|
MD5 |
0df7adb7e614c59c3218369396c0e27f
|
|
BLAKE2b-256 |
7b903ca013eef52c0b9dc6db715af2d2fffc8150f3aafaf565d32e185bd2ed6d
|
File details
Details for the file pysagas-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: pysagas-0.0.3-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
235758a594b6f3b043d67b34f43b96362cac1061f24ce90e215718146136a4ee
|
|
MD5 |
0f94e24890a5dbde986a3aa4a1e347f4
|
|
BLAKE2b-256 |
094ed14db12e038bb6f9063a8e97071a8826063c7dd7d6a10fd56e2fd2112d7b
|