Skip to content

Commit c2cebfb

Browse files
committed
Merge branch 'release/0.11.0'
2 parents 1d12dea + dfdcb2b commit c2cebfb

36 files changed

+1461
-3951
lines changed

docs/.vuepress/config.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineUserConfig } from "vuepress";
2-
import { searchProPlugin } from "vuepress-plugin-search-pro";
32
import { hopeTheme } from "vuepress-theme-hope";
3+
import { viteBundler } from '@vuepress/bundler-vite'
44

55
export default defineUserConfig({
66
lang: "en-US",
@@ -16,6 +16,8 @@ export default defineUserConfig({
1616
],
1717
],
1818

19+
bundler: viteBundler(),
20+
1921
theme: hopeTheme({
2022
hostname: "https://taskiq-python.github.io",
2123
logo: "/logo.svg",
@@ -28,7 +30,6 @@ export default defineUserConfig({
2830
sidebar: "structure",
2931

3032
pure: true,
31-
backToTop: false,
3233

3334
plugins: {
3435
readingTime: false,
@@ -45,8 +46,10 @@ export default defineUserConfig({
4546
changefreq: "daily",
4647
sitemapFilename: "sitemap.xml",
4748
},
49+
searchPro: {
50+
indexContent: true,
51+
autoSuggestions: false,
52+
}
4853
},
49-
}),
50-
51-
plugins: [searchProPlugin({ indexContent: true })],
54+
})
5255
});

docs/available-components/schedule-sources.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,23 @@ order: 4
77
These objects are used to fetch current schedule for tasks.
88
Currently we have only one schedule source.
99

10+
## RedisScheduleSource
11+
12+
This source is capable of adding new schedules in runtime. It uses Redis as a storage for schedules.
13+
To use this source you need to install `taskiq-redids` package.
14+
15+
```python
16+
from taskiq_redis import RedisScheduleSource
17+
18+
from taskiq import TaskiqScheduler
19+
20+
redis_source = RedisScheduleSource("redis://localhost:6379/0")
21+
scheduler = TaskiqScheduler(broker, sources=[redis_source])
22+
```
23+
24+
For more information on how to use dynamic schedule sources read [Dynamic scheduling section](../guide/scheduling-tasks.md#dynamic-scheduling).
25+
26+
1027
## LabelScheduleSource
1128

1229
This source parses labels of tasks, and if it finds a `schedule` label, it considers this task as scheduled.

docs/contrib.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@ order: 5
44

55
# Contribution guide
66

7-
We love contributions. This guide is for all folks who want to make taskiq
8-
better together.
9-
10-
We have several rules for contributors:
11-
* Please do not add malware.
12-
* Please make sure that your request solves problem.
13-
14-
If you struggle with something or feel frustrating, you either create an issue, create a discussion on page or publish draft PR and ask your question in description.
15-
16-
We have lots of tests in CI. But since runs from first-time contributors should be approved you better test locally, it just takes less time.
17-
187
We love contributions. This guide is for all folks who want to make taskiq better together.
198
We have several rules for contributors:
209
* Please do not add malware.

docs/examples/extending/schedule_source.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ async def pre_send(self, task: "ScheduledTask") -> None:
3838
"""
3939
Actions to execute before task will be sent to broker.
4040
41+
This method may raise ScheduledTaskCancelledError.
42+
This cancels the task execution.
43+
4144
:param task: task that will be sent
4245
"""
4346

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from taskiq_redis import ListQueueBroker, RedisScheduleSource
2+
3+
from taskiq import TaskiqScheduler
4+
5+
# Here's the broker that is going to execute tasks
6+
broker = ListQueueBroker("redis://localhost:6379/0")
7+
8+
# Here's the source that is used to store scheduled tasks
9+
redis_source = RedisScheduleSource("redis://localhost:6379/0")
10+
11+
# And here's the scheduler that is used to query scheduled sources
12+
scheduler = TaskiqScheduler(broker, sources=[redis_source])
13+
14+
15+
@broker.task
16+
async def my_task(arg1: int, arg2: str) -> None:
17+
"""Example task."""
18+
print("Hello from my_task!", arg1, arg2) # noqa: T201
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
order: 3
3+
---
4+
5+
# Taskiq + FastStream
6+
7+
[FastStream](https://faststream.airt.ai/latest/) is a library that allows you to write consumers and producers for different message brokers almost like taskiq. But the differense is that taskiq is more focused on tasks for a specific project and more like celery but async, while FastStream is more focused on events and defining how different systems communicate with each other using distributed brokers.
8+
9+
If you want to declare communication between different projects you can use taskiq, but it might be a bit more complex than using FastStream.
10+
11+
Although these libraries solve different problems, they have integration between each other, so you can use FastStream as a broker for taskiq. It allows FastStream to use taskiq's scheduler along with its own features.
12+
13+
To use FastStream as a broker for taskiq you need to install the `taskiq-faststream` library:
14+
15+
```bash:no-line-numbers
16+
pip install "taskiq-faststream"
17+
```
18+
19+
And you can use it like this:
20+
21+
```python
22+
from faststream import FastStream
23+
from faststream.kafka import KafkaBroker
24+
from taskiq_faststream import BrokerWrapper
25+
26+
broker = KafkaBroker("localhost:9092")
27+
app = FastStream(broker)
28+
29+
taskiq_broker = BrokerWrapper(broker)
30+
```
31+
32+
You can read more about scheduling tasks for FastStream in the [FastStream documentation](https://faststream.airt.ai/latest/scheduling/?h=schedule).
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Taskiq + Aiogram
2+
3+
[Taskiq-Aiogram](https://github.com/taskiq-python/taskiq-aiogram) is a nice integration with one of the best telegram bot libraries - [aiogram](https://docs.aiogram.dev/en/latest/).
4+
5+
This integration allows you to easily send delayed messages or run intensive functions without blocking the message handing.
6+
7+
This integration adds three main dependencies which you can use in your taskiq functions:
8+
9+
- `aiogram.Bot` - the bot instance that you can use to send messages or perform other actions. If multiple bots listen to the same dispatcher, this dependency will be resolved to the latest bot passed in the `taskiq_aiogram.init` function.
10+
- `aiogram.Dispatcher` - current dispatcher instance.
11+
- `List[aiogram.Bot]` - list of all bots that were passed to the `taskiq_aiogram.init` function.
12+
13+
To enable the integration, please install the `taskiq-aiogram` library:
14+
15+
```bash:no-line-numbers
16+
pip install "taskiq-aiogram"
17+
```
18+
19+
After the installation is complete, add an initialization function call to your broker's main file so it becomes something like this:
20+
21+
```python title="tkq.py"
22+
import asyncio
23+
24+
import taskiq_aiogram
25+
from aiogram import Bot
26+
from taskiq import TaskiqDepends
27+
from taskiq_redis import ListQueueBroker
28+
29+
broker = ListQueueBroker("redis://localhost")
30+
31+
# This line is going to initialize everything.
32+
taskiq_aiogram.init(
33+
broker,
34+
# This is path to the dispatcher.
35+
"bot:dp",
36+
# This is path to the bot instance.
37+
"bot:bot",
38+
# You can specify more bots here.
39+
)
40+
41+
42+
@broker.task(task_name="my_task")
43+
async def my_task(chat_id: int, bot: Bot = TaskiqDepends()) -> None:
44+
print("I'm a task")
45+
await asyncio.sleep(4)
46+
await bot.send_message(chat_id, "task completed")
47+
48+
```
49+
50+
Let's see how to use this integration.
51+
52+
```python title="bot.py"
53+
import asyncio
54+
import logging
55+
import sys
56+
57+
from aiogram import Bot, Dispatcher, types
58+
from aiogram.filters import Command
59+
60+
from tkq import broker, my_task
61+
62+
dp = Dispatcher()
63+
bot = Bot(token="TOKEN")
64+
65+
66+
# Taskiq calls this function when starting the worker.
67+
@dp.startup()
68+
async def setup_taskiq(bot: Bot, *_args, **_kwargs):
69+
# Here we check if it's a clien-side,
70+
# Becuase otherwise you're going to
71+
# create infinite loop of startup events.
72+
if not broker.is_worker_process:
73+
logging.info("Setting up taskiq")
74+
await broker.startup()
75+
76+
77+
# Taskiq calls this function when shutting down the worker.
78+
@dp.shutdown()
79+
async def shutdown_taskiq(bot: Bot, *_args, **_kwargs):
80+
if not broker.is_worker_process:
81+
logging.info("Shutting down taskiq")
82+
await broker.shutdown()
83+
84+
85+
## Simple command to handle
86+
@dp.message(Command("task"))
87+
async def message(message: types.Message):
88+
await my_task.kiq(message.chat.id)
89+
90+
91+
## Main function that starts the bot.
92+
async def main():
93+
await dp.start_polling(bot)
94+
95+
96+
if __name__ == "__main__":
97+
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
98+
asyncio.run(main())
99+
100+
```
101+
102+
That's it. Now you can easily call tasks from your bots and access bots from within your tasks.

docs/framework_integrations/taskiq-with-aiohttp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ order: 2
66

77
AioHTTP is a framework for building robust applications. We created several libraries to make the experience with AioHTTP even better.
88

9-
# Dependency inecjeciton for AioHTTP
9+
# Dependency injection for AioHTTP
1010

1111
We created a library [aiohttp-deps](https://pypi.org/project/aiohttp-deps/) to add FastAPI-like dependency injection in AioHTTP.
1212

docs/guide/architecture-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you use dark theme and cannot see words on diagram,
1515
try switching to light theme and back to dark.
1616
:::
1717

18-
```mermaid
18+
```sequence
1919
rect rgb(191, 223, 255)
2020
note right of Your code: Client side.
2121
Your code ->> Kicker: assemble message

docs/guide/cli.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ That's why taskiq can auto-discover tasks in current directory recursively.
2626
We have two options for this:
2727

2828
- `--tasks-pattern` or `-tp`.
29-
It's a name of files to import. By default is searches for all `tasks.py` files.
29+
It's a glob pattern of files to import. By default it is `**/tasks.py` which searches for all `tasks.py` files. May be specified multiple times.
3030
- `--fs-discover` or `-fsd`. This option enables search of task files in current directory recursively, using the given pattern.
3131

3232
### Acknowledgements
@@ -87,13 +87,15 @@ when you modify ignored files. To disable this functionality pass `--do-not-use-
8787
### Other parameters
8888

8989
* `--no-configure-logging` - disables default logging configuration for workers.
90+
- `--log-level` is used to set a log level (default `INFO`).
9091
* `--max-async-tasks` - maximum number of simultaneously running async tasks.
9192
* `--max-prefetch` - number of tasks to be prefetched before execution. (Useful for systems with high message rates, but brokers should support acknowledgements).
9293
* `--max-threadpool-threads` - number of threads for sync function exection.
9394
* `--no-propagate-errors` - if this parameter is enabled, exceptions won't be thrown in generator dependencies.
9495
* `--receiver` - python path to custom receiver class.
9596
* `--receiver_arg` - custom args for receiver.
9697
* `--ack-type` - Type of acknowledgement. This parameter is used to set when to acknowledge the task. Possible values are `when_received`, `when_executed`, `when_saved`. Default is `when_saved`.
98+
- `--shutdown-timeout` - maximum amount of time for graceful broker's shutdown in seconds.
9799

98100
## Scheduler
99101

@@ -116,6 +118,8 @@ taskiq scheduler my_project.broker:scheduler my_project.module1 my_project.modul
116118
Path to scheduler is the only required argument.
117119

118120
- `--tasks-pattern` or `-tp`.
119-
It's a name of files to import. By default is searches for all `tasks.py` files.
121+
It's a glob pattern of files to import. By default it is `**/tasks.py` which searches for all `tasks.py` files. May be specified multiple times.
120122
- `--fs-discover` or `-fsd`. This option enables search of task files in current directory recursively, using the given pattern.
121-
- `--log-level` is used to set a log level.
123+
- `--no-configure-logging` - use this parameter if your application configures custom logging.
124+
- `--log-level` is used to set a log level (default `INFO`).
125+
- `--skip-first-run` - skip first run of scheduler. This option skips running tasks immediately after scheduler start.

0 commit comments

Comments
 (0)