Skip to content

Commit

Permalink
Improve readme documentation (#74)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kaypee90 authored Oct 12, 2023
1 parent 41ae391 commit 47791e4
Showing 1 changed file with 45 additions and 41 deletions.
86 changes: 45 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 47791e4

Please sign in to comment.