Skip to content

Commit 3e9ff9d

Browse files
committed
Merge branch 'release/0.9.3'
2 parents e0b4b05 + 8cbbc6d commit 3e9ff9d

File tree

20 files changed

+371
-65
lines changed

20 files changed

+371
-65
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Set up Python
5050
uses: actions/setup-python@v4
5151
with:
52-
python-version: "3.9"
52+
python-version: "3.11"
5353
- name: Install deps
5454
run: poetry install
5555
- name: Release package

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Python
1919
uses: actions/setup-python@v4
2020
with:
21-
python-version: "3.9"
21+
python-version: "3.11"
2222
cache: "poetry"
2323
- name: Install deps
2424
run: poetry install

README.md

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
<hr/>
88
</div>
99

10+
Documentation: https://taskiq-python.github.io/
11+
12+
## What is taskiq?
13+
1014
Taskiq is an asynchronous distributed task queue for python.
1115
This project takes inspiration from big projects such as [Celery](https://docs.celeryq.dev) and [Dramatiq](https://dramatiq.io/).
12-
But taskiq can send and run both the sync and async functions.
13-
Also, we use [PEP-612](https://peps.python.org/pep-0612/) to provide the best autosuggestions possible. But since it's a new PEP, I encourage you to use taskiq with VS code because Pylance understands all types correctly.
16+
But taskiq can send and run both the sync and async functions, has
17+
integration with popular async frameworks, such as [FastAPI](https://fastapi.tiangolo.com/) and [AioHTTP](https://docs.aiohttp.org/en/stable/).
18+
19+
Also, we use [PEP-612](https://peps.python.org/pep-0612/) to provide the best autosuggestions possible. All code is type-hinted.
1420

1521
# Installation
1622

@@ -25,8 +31,69 @@ Or it can be installed directly from git:
2531
pip install git+https://github.com/taskiq-python/taskiq
2632
```
2733

28-
You can read more about how to use it in our docs: https://taskiq-python.github.io/.
34+
# Usage
35+
36+
At first you need to create a broker. Broker is an object that can communicate to workers using distributed queues.
37+
38+
We have differet brokers for different queue backends. For example, we have a broker for [NATS](https://github.com/taskiq-python/taskiq-nats), [Redis](https://github.com/taskiq-python/taskiq-redis), [RabbitMQ](https://github.com/taskiq-python/taskiq-aio-pika), [Kafka](https://github.com/taskiq-python/taskiq-aio-kafka) and even more. Choose the one that fits you and create an instance.
39+
40+
```python
41+
from taskiq_nats import JetStreamBroker
42+
43+
broker = JetStreamBroker("nats://localhost:4222", queue="my_queue")
44+
```
45+
46+
Declaring tasks is as easy as declaring a function. Just add a decorator to your function and you are ready to go.
47+
48+
```python
49+
import asyncio
50+
51+
from taskiq_nats import JetStreamBroker
52+
53+
broker = JetStreamBroker("nats://localhost:4222", queue="my_queue2")
54+
55+
56+
@broker.task
57+
async def my_task(a: int, b: int) -> None:
58+
print("AB", a + b)
59+
60+
61+
async def main():
62+
await broker.startup()
63+
64+
await my_task.kiq(1, 2)
65+
66+
await broker.shutdown()
67+
68+
69+
if __name__ == "__main__":
70+
asyncio.run(main())
71+
72+
73+
```
74+
75+
The message is going to be sent to the broker and then to the worker. The worker will execute the function. To start worker processes, just run the following command:
76+
77+
```bash
78+
taskiq worker path.to.the.module:broker
79+
```
80+
81+
Where `path.to.the.module` is the path to the module where the broker is defined and `broker` is the name of the broker variable.
82+
83+
If you have tasks in different modules, you can ask taskiq to automatically import them by passing the `--fs-discover` flag:
84+
85+
```bash
86+
taskiq worker path.to.the.module:broker --fs-discover
87+
```
88+
89+
It will import all modules called `tasks.py` in the current directory and all subdirectories.
90+
91+
Also, we support hot reload for workers. To enable it, just pass the `--reload` flag. It will reload the worker when the code changes (To use it, install taskiq with reload extra. E.g `pip install taskiq[reload]`).
92+
93+
94+
Also, we have cool integrations with popular async frameworks. For example, we have an integration with [FastAPI](https://taskiq-python.github.io/framework_integrations/taskiq-with-fastapi.html) or [AioHTTP](https://taskiq-python.github.io/framework_integrations/taskiq-with-aiohttp.html). You can use it to reuse dependencies from your web app in your tasks.
2995

96+
Read about all features in our documentation: https://taskiq-python.github.io/
3097

3198
# Local development
3299

docs/guide/dynamic-brokers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Taskiq allows you to set up broker instances throughout your application and reg
1313

1414
To define tasks and assign them to a broker, use `register_task` method.
1515

16-
@[code python](../examples/dynamics/broker.py)
16+
@[code python](../examples/dynamics/dyn_broker.py)
1717

1818
In this example, the task is defined using a lambda within the `main` function. As the lambda is not visible outside of the `main` function scope, the task is not executable by `taskiq worker` command.
1919

@@ -24,10 +24,10 @@ To overcome this issue, you can:
2424

2525
Here's an example of a dynamic worker task creation:
2626

27-
@[code python](../examples/dynamics/receiver.py)
27+
@[code python](../examples/dynamics/dyn_receiver.py)
2828

2929
In this example, a named dynamic lambda task is created and registered in a broker, similar to the previous example. The difference is the creation of a new receiver coroutine for the worker task. It will listen to the new messages and execute them. The worker task will be executed in the current event loop. After exiting the scope, the worker task will get cancelled. For illustration purposes it is cancelled explicitly.
3030

3131
It's possible to run a scheduler in the current event loop as well:
3232

33-
@[code python](../examples/dynamics/scheduler.py)
33+
@[code python](../examples/dynamics/dyn_scheduler.py)

poetry.lock

Lines changed: 51 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "taskiq"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
description = "Distributed task queue with full async support"
55
authors = ["Pavel Kirilin <[email protected]>"]
66
maintainers = ["Pavel Kirilin <[email protected]>"]
@@ -61,6 +61,7 @@ freezegun = "^1.2.2"
6161
pytest-mock = "^3.11.1"
6262
tzlocal = "^5.0.1"
6363
types-tzlocal = "^5.0.1.1"
64+
types-pytz = "^2023.3.1.1"
6465

6566
[tool.poetry.extras]
6667
zmq = ["pyzmq"]

0 commit comments

Comments
 (0)