From 47791e4faa605b3d44315dc2f1b40c3d113b120b Mon Sep 17 00:00:00 2001 From: Kaypee Date: Thu, 12 Oct 2023 00:43:15 +0000 Subject: [PATCH] Improve readme documentation (#74) * Add black to pre commit hooks * Update readme to include how to run examples with docker compose * Improve readme organization * Highlight filenames in readme file * Highlight filenames in readme file * Re-organize readme content --- README.md | 86 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 0db4d91..75e960a 100644 --- a/README.md +++ b/README.md @@ -4,47 +4,6 @@ Brokerless task queue for python based on 0Mq -### - How to use zebrok -======================== - -* Configuring Environment Variables: - - WORKER_HOST         # The IP address to expose running workers on - - WORKER_PORT               # The port number workers should listen on - - -- `If not set defaults to localhost:5690` - -* Creating A Task [tasks.py] -``` -from zebrok import app - -@app.Task -def long_running_task(param): - do_some_time_consuming_task(param) -``` - -* Configuring a worker and registering the task [examples/start.py] - - NB: `A task can also be discovered automatically if placed in a tasks.py file in the root folder of the project.` - `- You can also set number of slave worker threads to be running by passing number_of_slaves argument` -``` -from zebrok.worker import WorkerInitializer -from tasks import long_running_task - - -worker = WorkerInitializer(number_of_slaves=1, auto_discover=True) -worker.register_task(long_running_task) -worker.start() -``` - -* Starting the Zebrok Worker to listen for tasks - -`python examples/start.py` where start.py is the file in which you configured the worker - -* Executing a task [examples/client.py] -``` -from tasks import long_running_task - -long_running_task.run(param="dowork") -``` - - This library comes with the benefits of 0Mq - Low Latency - Lightweight @@ -95,6 +54,51 @@ DONE!!! DONE!!! ``` +### - Trying out zebrok +======================== + +* Install zebrok using the command `pip install git+https://github.com/kaypee90/zebrok.git#egg=zebrok` + +* Configuring Environment Variables: + - WORKER_HOST         # The IP address for running workers + - WORKER_PORT               # The port number workers should listen on + + -- `If not set defaults to localhost:5690` + +* Creating A Task `[tasks.py]` +``` +from zebrok import app + +@app.Task +def long_running_task(param): + do_some_time_consuming_task(param) +``` + +* Configuring a worker and registering the task `[examples/start.py]` + - NB: `A task can also be discovered automatically if placed in a tasks.py file in the root folder of the project.` + `- You can also set number of slave worker threads to be running by passing number_of_slaves argument` +``` +from zebrok.worker import WorkerInitializer +from tasks import long_running_task + + +worker = WorkerInitializer(number_of_slaves=1, auto_discover=True) +worker.register_task(long_running_task) +worker.start() +``` + +* Starting the Zebrok Worker to listen for tasks - +`python examples/start.py` where start.py is the file in which you configured the worker + +* Executing a task `[examples/client.py]` +``` +from tasks import long_running_task + +long_running_task.run(param="dowork") +``` + +[Link to sample fastapi project using Zebrok](https://github.com/kaypee90/sample-zebrok-1) + ### Using a container orchestration technology (like Kubernetes): - `number_of_slaves` must always be set to 0, then you can spin a number of replicas for the workers.