Skip to main content

Python workers for RichardKnop/machinery

Project description

Machinery Python SDK

PyPI

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

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.1.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymachinery-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pymachinery-0.1.3.tar.gz.

File metadata

  • Download URL: pymachinery-0.1.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pymachinery-0.1.3.tar.gz
Algorithm Hash digest
SHA256 49aee5a4887c7661ab4db48b8bc97a3b69d9148e169fa58cb8f782ba80ed2836
MD5 f590183fca627a533a78de53a51a8dff
BLAKE2b-256 0fe1399f29f9ab3a22e7e8e8a401053be677b4ae9e15ef3f7f35cc35becd039a

See more details on using hashes here.

File details

Details for the file pymachinery-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pymachinery-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pymachinery-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4fbf60a91b5acc679317dd44b2cc48a551136e20ba9e2bc0a49b5be83ba88329
MD5 82f3605b11db0418221d50a3bf47949a
BLAKE2b-256 195eebbfbdf626331fa43d0bfe800c20dfc279948502d2e41f45854b0b4952ca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page