Skip to content

Getting all running tasks #235

Answered by s3rius
kevinhikaruevans asked this question in Q&A
Discussion options

You must be logged in to vote

Actually, not bad implementation. But there's a small flaw in the design. You perform N operations every time you delete a task. It's fine for not highload systems, but may result in poor performance.

I'd suggest you to use scan for keys and batch operations, like mget.

from typing import Any
from taskiq import TaskiqMessage, TaskiqMiddleware, TaskiqResult
from taskiq_redis import ListQueueBroker, RedisAsyncResultBackend
from taskiq_redis.redis_broker import BaseRedisBroker
from redis.asyncio import Redis


class RunningTasksMiddleware(TaskiqMiddleware):
    def __init__(self, prefix: str = "running:") -> None:
        super().__init__()

        self.prefix = prefix

    async def startup(

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@kevinhikaruevans
Comment options

@s3rius
Comment options

Answer selected by kevinhikaruevans
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants