Python workers for RichardKnop/machinery
Project description
Machinery Python SDK
This is a subset Python implementation of a worker for RichardKnop/machinery
.
Limitations
- Broker is strictly only for Redis
- BackendResult is strictly only for MongoDB
Development Environment
Use venv
with python 3.
# ---- Setup
$ sudo apt install python3 python3-venv
$ python3 -m venv ~/.venv/simcel
# ---- Activate venv
$ source ~/.venv/simcel/bin/activate
(simcel) $ pip3 install -r requirements.txt
# ---- Running
(simcel) $ python3 main.py
Usage
from pymachinery import Value, Machinery
def add_worker(a: Value, b: Value):
return (Value("int64", a.value() + b.value()))
def multiply_worker(a: Value, b: Value):
return (Value("int64", a.value() * b.value()))
def worker(name: Value, delayms: Value):
return (
Value("string", f"hello {name.value()}"),
Value("int64", delayms),
)
machinery = Machinery(
broker_uri="redis://:helloworld@localhost:6379",
backend_uri="mongodb://mongo:moonbucks@localhost:27017/?authSource=admin",
queue="machinery_tasks",
)
machinery.register_worker("add", add_worker)
machinery.register_worker("multiply", multiply_worker)
machinery.register_worker("hello", worker)
machinery.start()
Creating a Worker
Workers have these restrictions:
- Inputs should be of type pymachinery.Value
- Outputs should be of type pymachinery.Value, or a tuple of pymachinery.Value
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
pymachinery-0.0.7.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for pymachinery-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ec2a54ce5a4a9bb50a0b0916b80eace7cf95d8eabdf72e8e5dc56dfc0ff0862 |
|
MD5 | f23edfa3a51a356f8269415a544cb50a |
|
BLAKE2b-256 | 11885091a0dfe4c97bcee6e73f49810e2220a51d332e6f68fac7f248210ae755 |