Skip to content

Updating in-memory task data evicts unrelated cached tasks #700

Open

Description

@IlyaKhalafi

Updating an existing task's progress at cache capacity removes another task's progress, even though no new task ID is added.

import asyncio

from taskiq.brokers.inmemory_broker import InmemoryResultBackend
from taskiq.depends.progress_tracker import TaskProgress


async def main():
    backend = InmemoryResultBackend(max_stored_results=2)
    await backend.set_progress("first", TaskProgress(state="STARTED", meta=0))
    await backend.set_progress("second", TaskProgress(state="STARTED", meta=0))
    await backend.set_progress("second", TaskProgress(state="STARTED", meta=50))

    print(await backend.get_progress("first"))  # None


asyncio.run(main())

The progress for first should remain available. Eviction should happen when adding a new task ID to a full cache, rather than when updating an existing entry.

set_result() has the same eviction condition and also removes an unrelated result when an existing ID is updated. I reproduced both cases on master at f08a54a with Python 3.12.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions