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
To start up machinery instance for Python:
from machinery import Value, Machinery
def add(a: Value, b: Value):
return (Value("int64", a.value() + b.value()))
def multiply(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_callback("add", add)
machinery.register_callback("multiply", multiply)
machinery.register_callback("hello", worker)
# Note that start() is a blocking function.
machinery.start()
To send a machinery task and receive its results:
task = machinery.send_task(queue, "add", [
Value("int64", 30),
Value("int64", 50)
])
# Note that wait_for_results() is a blocking function.
results = machinery.wait_for_results(task)
print(results) # [ Value("int64", 80) ]
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
Metadata
Release files for pymachinery 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pymachinery-0.1.3.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pymachinery-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / pymachinery-0.1.3.tar.gz
| Download URL | pymachinery-0.1.3.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49aee5a4887c7661ab4db48b8bc97a3b69d9148e169fa58cb8f782ba80ed2836
|
|
BLAKE2b-256 checksum How to use checksums |
0fe1399f29f9ab3a22e7e8e8a401053be677b4ae9e15ef3f7f35cc35becd039a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3
|
Release files / pymachinery-0.1.3-py3-none-any.whl
| Download URL | pymachinery-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4fbf60a91b5acc679317dd44b2cc48a551136e20ba9e2bc0a49b5be83ba88329
|
|
BLAKE2b-256 checksum How to use checksums |
195eebbfbdf626331fa43d0bfe800c20dfc279948502d2e41f45854b0b4952ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3
|