a state machine that support multi process
Project description
state-machine
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
Usage
- 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
pip3 install -e ./
cd tests
python3 __init__.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
state-machine-2-0.2.1.tar.gz
(15.9 kB
view hashes)
Built Distribution
Close
Hashes for state_machine_2-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23b78f4c8485e4b2bec512cf8b652ef0e61bbbb7606684f9bac5a4ac87640cdb |
|
MD5 | c382642bcc28376161d50900e374e654 |
|
BLAKE2b-256 | 4cd8b970dae4409a8ac428a7c5ecc8142407eb4ce04f8c42e372c33960fd6c00 |