Project setup and ideas
This commit is contained in:
parent
0b869ff3ea
commit
1701c7fb6b
6
ARCHITECTURE.md
Normal file
6
ARCHITECTURE.md
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Controller (master)
|
||||||
|
|
||||||
|
Worker (minion)
|
||||||
|
|
||||||
|
API
|
||||||
|
|
||||||
19
Makefile
Normal file
19
Makefile
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
run-controller:
|
||||||
|
venv/bin/mypy --strict phasmplatform
|
||||||
|
venv/bin/pyflakes phasmplatform
|
||||||
|
venv/bin/pycodestyle phasmplatform
|
||||||
|
venv/bin/python -m phasmplatform.controller
|
||||||
|
|
||||||
|
init:
|
||||||
|
docker compose up -d
|
||||||
|
|
||||||
|
redis-sh:
|
||||||
|
docker compose exec -it redis redis-cli
|
||||||
|
|
||||||
|
setup:
|
||||||
|
python3.10 -m venv venv
|
||||||
|
venv/bin/pip install --upgrade pip wheel setuptools
|
||||||
|
venv/bin/pip install -r requirements.txt -r requirements-dev.txt
|
||||||
|
|
||||||
|
update:
|
||||||
|
venv/bin/pip install -r requirements.txt -r requirements-dev.txt
|
||||||
@ -1,2 +1,8 @@
|
|||||||
# phasm-platform
|
# phasm-platform
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
```sh
|
||||||
|
make setup
|
||||||
|
make init
|
||||||
|
make run-controller
|
||||||
|
```
|
||||||
7
config.toml
Normal file
7
config.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[controller.redis.write]
|
||||||
|
host = 'localhost'
|
||||||
|
port = 17859
|
||||||
|
|
||||||
|
[controller.redis.read]
|
||||||
|
host = 'localhost'
|
||||||
|
port = 17859
|
||||||
5
docker-compose.yaml
Normal file
5
docker-compose.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
services:
|
||||||
|
redis:
|
||||||
|
image: 'redis:7.0-alpine'
|
||||||
|
ports:
|
||||||
|
- '17859:6379'
|
||||||
0
phasmplatform/__init__.py
Normal file
0
phasmplatform/__init__.py
Normal file
0
phasmplatform/common/__init__.py
Normal file
0
phasmplatform/common/__init__.py
Normal file
58
phasmplatform/common/config.py
Normal file
58
phasmplatform/common/config.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
from typing import TYPE_CHECKING, BinaryIO
|
||||||
|
|
||||||
|
import redis
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
import tomli as tomllib
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
import tomllib
|
||||||
|
except ImportError:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
|
|
||||||
|
class ControllerConfig:
|
||||||
|
__slots__ = ('redis_read', 'redis_write', )
|
||||||
|
|
||||||
|
redis_read: 'redis.Redis[bytes]' # Set decode_responses to False
|
||||||
|
redis_write: 'redis.Redis[bytes]' # Set decode_responses to False
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
redis_read: 'redis.Redis[bytes]',
|
||||||
|
redis_write: 'redis.Redis[bytes]',
|
||||||
|
) -> None:
|
||||||
|
self.redis_read = redis_read
|
||||||
|
self.redis_write = redis_write
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
__slots__ = ('controller_config', )
|
||||||
|
|
||||||
|
controller_config: ControllerConfig
|
||||||
|
|
||||||
|
def __init__(self, controller_config: ControllerConfig) -> None:
|
||||||
|
self.controller_config = controller_config
|
||||||
|
|
||||||
|
|
||||||
|
def from_toml(toml: BinaryIO) -> Config:
|
||||||
|
"""
|
||||||
|
Loads the given toml and builds a config instance out of it
|
||||||
|
"""
|
||||||
|
toml_dict = tomllib.load(toml)
|
||||||
|
|
||||||
|
redis_read = redis.Redis(
|
||||||
|
host=toml_dict['controller']['redis']['read']['host'],
|
||||||
|
port=toml_dict['controller']['redis']['read']['port'],
|
||||||
|
decode_responses=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
redis_write = redis.Redis(
|
||||||
|
host=toml_dict['controller']['redis']['write']['host'],
|
||||||
|
port=toml_dict['controller']['redis']['write']['port'],
|
||||||
|
decode_responses=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
controller_config = ControllerConfig(redis_read, redis_write)
|
||||||
|
|
||||||
|
return Config(controller_config)
|
||||||
0
phasmplatform/controller/__init__.py
Normal file
0
phasmplatform/controller/__init__.py
Normal file
16
phasmplatform/controller/__main__.py
Normal file
16
phasmplatform/controller/__main__.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from phasmplatform.common.config import from_toml
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
with open('config.toml', 'rb') as fil:
|
||||||
|
config = from_toml(fil)
|
||||||
|
|
||||||
|
del config
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
||||||
4
requirements-dev.txt
Normal file
4
requirements-dev.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
mypy==1.2.0
|
||||||
|
pycodestyle==2.10.0
|
||||||
|
pyflakes==3.0.1
|
||||||
|
types-redis==4.5.4.1
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
redis==4.5.4
|
||||||
|
tomli==2.0.1 ; python_version < '3.11'
|
||||||
Loading…
x
Reference in New Issue
Block a user