Skip to content

Commit 0adfcee

Browse files
committed
Merge branch 'release/0.10.0'
2 parents 3e9ff9d + e9431bd commit 0adfcee

File tree

28 files changed

+899
-167
lines changed

28 files changed

+899
-167
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Testing taskiq
22

3-
on: [pull_request]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- develop
8+
- master
49

510
jobs:
611
lint:
@@ -21,7 +26,7 @@ jobs:
2126
python-version: "3.11"
2227
cache: "poetry"
2328
- name: Install deps
24-
run: poetry install
29+
run: poetry install --all-extras
2530
- name: Run lint check
2631
run: poetry run pre-commit run -a ${{ matrix.cmd }}
2732
pytest:
@@ -31,7 +36,7 @@ jobs:
3136
contents: write
3237
strategy:
3338
matrix:
34-
py_version: ["3.8", "3.9", "3.10", "3.11"]
39+
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
3540
os: [ubuntu-latest, windows-latest]
3641
runs-on: "${{ matrix.os }}"
3742
steps:
@@ -44,7 +49,7 @@ jobs:
4449
python-version: "${{ matrix.py_version }}"
4550
cache: "poetry"
4651
- name: Install deps
47-
run: poetry install
52+
run: poetry install --all-extras
4853
- name: Run pytest check
4954
run: poetry run pytest -vv -n auto --cov="taskiq" .
5055
- name: Generate report

docs/examples/extending/schedule_source.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ async def get_schedules(self) -> List["ScheduledTask"]:
1919
args=[],
2020
kwargs={},
2121
cron="* * * * *",
22-
#
23-
# We need point on self source for calling pre_send / post_send when
24-
# task is ready to be enqueued.
25-
source=self,
2622
),
2723
]
2824

2925
# This method is optional. You may not implement this.
3026
# It's just a helper to people to be able to interact with your source.
31-
async def add_schedule(self, schedule: "ScheduledTask") -> None:
32-
return await super().add_schedule(schedule)
27+
# This method can be either sync or async.
28+
def add_schedule(self, schedule: "ScheduledTask") -> None:
29+
print("New schedule added:", schedule)
3330

3431
# This method is optional. You may not implement this.
3532
# It's just a helper to people to be able to interact with your source.

docs/examples/schedule/intro.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from taskiq_aio_pika import AioPikaBroker
22

33
from taskiq.schedule_sources import LabelScheduleSource
4-
from taskiq.scheduler import TaskiqScheduler
4+
from taskiq import TaskiqScheduler
55

66
broker = AioPikaBroker("amqp://guest:guest@localhost:5672/")
77

docs/guide/message-format.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
order: 11
3+
---
4+
5+
# Taskiq message format
6+
7+
Taskiq doesn't force you to use any specific message format. We define default message format,
8+
but you can use any format you want.
9+
10+
The default message format is:
11+
12+
13+
::: tabs
14+
15+
@tab example
16+
17+
```json
18+
{
19+
"task_name": "my_project.module1.task",
20+
"args": [1, 2, 3],
21+
"kwargs": {"a": 1, "b": 2, "c": 3},
22+
"labels": {
23+
"label1": "value1",
24+
"label2": "value2"
25+
}
26+
}
27+
```
28+
29+
@tab json schema
30+
31+
```json
32+
{
33+
"properties": {
34+
"task_id": {
35+
"title": "Task Id",
36+
"type": "string"
37+
},
38+
"task_name": {
39+
"title": "Name of the task",
40+
"type": "string"
41+
},
42+
"labels": {
43+
"title": "Additional labels",
44+
"type": "object"
45+
},
46+
"args": {
47+
"items": {},
48+
"title": "Arguments",
49+
"type": "array"
50+
},
51+
"kwargs": {
52+
"title": "Keyword arguments",
53+
"type": "object"
54+
}
55+
},
56+
"required": [
57+
"task_id",
58+
"task_name",
59+
"labels",
60+
"args",
61+
"kwargs"
62+
],
63+
"type": "object"
64+
}
65+
```
66+
67+
:::
68+
69+
But this can be easily changed by creating your own implementation of the TaskiqFormatter class or TaskiqSerializer class.
70+
71+
72+
### Serializers
73+
74+
Serializers define the format of the message but not the structure. For example, if you want to use msgpack or ORJson to serialize your message, you should update the serializer of your broker.
75+
76+
Be default, Taskiq uses JSON serializer. But we also have some implementations of other serializers:
77+
78+
* ORJSONSerializer - faster [JSON implementation](https://pypi.org/project/orjson/). Also, it supports datetime and UUID serialization.
79+
* MSGPackSerializer - [MsgPack](https://pypi.org/project/msgpack/) format serializer. It might be useful to send less data over the network.
80+
* CBORSerializer - [CBOR](https://pypi.org/project/cbor2/) format serializer. It is also has a smaller size than JSON.
81+
82+
To define your own serializer, you have to subclass the TaskiqSerializer class and implement `dumpb` and `loadb` methods. You can take a look at the existing implementations from the `taskiq.serializers` module.
83+
84+
To install taskiq with libraries for non-JSON serializers, you should install taskiq with extras.
85+
86+
::: tabs
87+
88+
@tab orjson
89+
90+
```bash
91+
pip install "taskiq[orjson]"
92+
```
93+
94+
@tab msgpack
95+
96+
```bash
97+
pip install "taskiq[msgpack]"
98+
```
99+
100+
@tab cbor
101+
102+
```bash
103+
pip install "taskiq[cbor]"
104+
```
105+
106+
:::
107+
108+
### Formatters
109+
110+
Formatters define the format of the message. It might be useful if you'd like to send a task to a celery worker for a different project. You can do it in seriazier as well, but formatters give you correct type hints.
111+
112+
By default we use a formatter that dumps the message to dict and serializes it using serializer. But you can define your own formatter to send a message in any format you want. To define a new formatter, you have to subclass the TaskiqFormatter class and implement `dumps` and `loads` methods.
113+
As an example, you can take a look at the `JSONFormatter` from `taskiq.formatters` implementation.

0 commit comments

Comments
 (0)