Worker, run_once
This commit is contained in:
parent
1701c7fb6b
commit
2063a6ea9c
19
Makefile
19
Makefile
@ -1,11 +1,8 @@
|
||||
run-controller:
|
||||
venv/bin/mypy --strict phasmplatform
|
||||
venv/bin/pyflakes phasmplatform
|
||||
venv/bin/pycodestyle phasmplatform
|
||||
run-controller: sast
|
||||
venv/bin/python -m phasmplatform.controller
|
||||
|
||||
init:
|
||||
docker compose up -d
|
||||
run-worker: sast
|
||||
venv/bin/python -m phasmplatform.worker
|
||||
|
||||
redis-sh:
|
||||
docker compose exec -it redis redis-cli
|
||||
@ -15,5 +12,15 @@ setup:
|
||||
venv/bin/pip install --upgrade pip wheel setuptools
|
||||
venv/bin/pip install -r requirements.txt -r requirements-dev.txt
|
||||
|
||||
init:
|
||||
docker compose up -d
|
||||
|
||||
update:
|
||||
venv/bin/pip install -r requirements.txt -r requirements-dev.txt
|
||||
|
||||
sast:
|
||||
venv/bin/mypy --strict phasmplatform
|
||||
venv/bin/pyflakes phasmplatform
|
||||
venv/bin/pycodestyle --max-line-length=140 phasmplatform
|
||||
|
||||
.PHONY: init redis-sh run-controller run-worker setup sast update
|
||||
|
||||
10
phasmplatform/common/exceptions.py
Normal file
10
phasmplatform/common/exceptions.py
Normal file
@ -0,0 +1,10 @@
|
||||
class PhasmPlatformError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class PhashPlatformRuntimeError(PhasmPlatformError):
|
||||
pass
|
||||
|
||||
|
||||
class PhashPlatformNonIntMainReturnError(PhashPlatformRuntimeError):
|
||||
pass
|
||||
0
phasmplatform/worker/__init__.py
Normal file
0
phasmplatform/worker/__init__.py
Normal file
21
phasmplatform/worker/__main__.py
Normal file
21
phasmplatform/worker/__main__.py
Normal file
@ -0,0 +1,21 @@
|
||||
import sys
|
||||
|
||||
from phasmplatform.common.config import from_toml
|
||||
|
||||
from .runner import run_once
|
||||
|
||||
|
||||
def main() -> int:
|
||||
with open('config.toml', 'rb') as fil:
|
||||
config = from_toml(fil)
|
||||
|
||||
del config
|
||||
|
||||
with open('/home/johan/projects/idea/phasm/examples/crc32.wasm', 'rb') as fil:
|
||||
run_once(fil.read())
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
17
phasmplatform/worker/runner.py
Normal file
17
phasmplatform/worker/runner.py
Normal file
@ -0,0 +1,17 @@
|
||||
import wasm3 # type: ignore
|
||||
|
||||
from phasmplatform.common.exceptions import PhashPlatformNonIntMainReturnError
|
||||
|
||||
|
||||
def run_once(wasm_bin: bytes) -> int:
|
||||
env = wasm3.Environment()
|
||||
rtime = env.new_runtime(1024 * 1024)
|
||||
rtime.load(env.parse_module(wasm_bin))
|
||||
result = rtime.find_function('main')()
|
||||
if result is None:
|
||||
return 0
|
||||
|
||||
if not isinstance(result, int):
|
||||
raise PhashPlatformNonIntMainReturnError(result)
|
||||
|
||||
return result
|
||||
@ -1,2 +1,3 @@
|
||||
pywasm3==0.5.0
|
||||
redis==4.5.4
|
||||
tomli==2.0.1 ; python_version < '3.11'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user