state-machine
documentation
a state machine that can change difference backends (current only redis backend, lately the filelockbackend)
and keep state synchronously in different state even different host.
Install
sudo pip3 install state-machine-2
Quick Start
- Create a State Backend
from state_machine import StateMachine, RedisBackend
from redis import Redis
# you will need to install redis
# see more information here: https://redis.io/download#installation
redis_backend = RedisBackend(con=Redis(decode_responses=True))
- Create a State Machine Class
class Job(StateMachine):
backend = redis_backend
def __init__(self, state=None, jobid=None):
self.jobid = jobid
super().__init__(state=state, jobid=jobid)
def __str__(self):
return f"Job: {self.jobid}"
- Use
# first progress
>>> job1_0 = Job(jobid=1, state="NEW")
>>> job1_0.state = "STARTED"
# second progress
>>> job1_1 = Job(jobid=1, state="NEW")
>>> job1_1.state = "STARTED"
Error: StateChangedException() # raise Exception because the state has changed by job1_0
test and contribute
git clone git@github.com:ramwin/state-machine.git
cd state-machine
pip3 install -e ./
sh test.sh
Metadata
Release files for state-machine-2 0.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| state-machine-2-0.2.4.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| state_machine_2-0.2.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 33.6 kB
Release files / state-machine-2-0.2.4.tar.gz
| Download URL | state-machine-2-0.2.4.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf165cfb5d75960652c3ae1a5fa24842cb0545e0ed17380db622d55c3e374c2d
|
|
BLAKE2b-256 checksum How to use checksums |
59ea3d8e3d22f2f873c1a4c7e2fe2264c769e16183b0399df11273397ebbf954
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / state_machine_2-0.2.4-py3-none-any.whl
| Download URL | state_machine_2-0.2.4-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d83cdd681e99b252c14cbacca37140c6723199ccddef6057833e3c0011127f18
|
|
BLAKE2b-256 checksum How to use checksums |
79980fe1cffa58fed826f9097813c437228438ce05ec5237b7c8e987c55f8ece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|