Leverage state machine to simplify code
- We have states: OK, CERTIFY, PRE_CERTIFY, HOLD
- We have transitions: "lock account", "unlock account", "create account", etc.
A state machine could help simplify the architecture. A state machine is a set of states and transitions among those states (a directed graph). A good state machine implementation should allow attaching actions to transitions. Thus, when you enact a transition, the actions will be triggered.
Agents could then be greatly simplified into single, atomic actions.
Example:
- Transition from OK to HOLD
- Action triggered:
lock_account()
- Agents notified in
lock_account()
ssh_disable
ood_disable
slurm_hold_jobs
cron_disable
group_remove
These agents do not exist (exactly) but they would be relatively simple implementations. Each agent would perform precisely one action, simplifying our mental model of larger workflows. The names of the agents would indicate clearly what those agents do, so when we look into lock_account()
we know exactly what to expect.
Possible Architecture
src
|-- agents
| |-- ssh_disable.py
| |-- ood_disable.py
| |-- slurm_hold_jobs.py
| |-- cron_disable.py
| |-- group_remove.py
| |-- transition.py
|-- actions
| |-- lock_account.py
|-- statemachines
| |-- user_state.py
|-- other files...
Resources
- Python Statemachine Package: https://python-statemachine.readthedocs.io/en/latest/index.html
- RabbitMQ Documentation: https://www.rabbitmq.com/tutorials/tutorial-one-python