Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pydantic = ">=1.0,<=3.0"
importlib-metadata = "*"
pycron = "^3.0.0"
taskiq_dependencies = ">=1.3.1,<2"
anyio = ">=3"
anyio = ">=4"
packaging = ">=19"
# For prometheus metrics
prometheus_client = { version = "^0", optional = true }
Expand Down Expand Up @@ -104,6 +104,7 @@ multi_line_output = 3

[tool.pytest.ini_options]
log_level = 'INFO'
anyio_mode = "auto"

[tool.coverage.run]
omit = [
Expand All @@ -122,6 +123,7 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.ruff]
target-version="py39"
# List of enabled rulsets.
# See https://docs.astral.sh/ruff/rules/ for more information.
lint.select = [
Expand Down Expand Up @@ -150,6 +152,7 @@ lint.select = [
"ERA", # Checks for commented out code
"PL", # PyLint checks
"RUF", # Specific to Ruff checks
"FA102", # Future annotations
]
lint.ignore = [
"D105", # Missing docstring in magic method
Expand All @@ -174,6 +177,7 @@ line-length = 88
"SLF001", # Private member accessed
"S311", # Standard pseudo-random generators are not suitable for security/cryptographic purposes
"D101", # Missing docstring in public class
"D102", # Missing docstring in public method
]

[tool.ruff.lint.pydocstyle]
Expand Down
4 changes: 2 additions & 2 deletions taskiq/middlewares/prometheus_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(
logger.debug("Initializing metrics")

try:
from prometheus_client import Counter, Histogram
from prometheus_client import Counter, Histogram # noqa: PLC0415
except ImportError as exc:
raise ImportError(
"Cannot initialize metrics. Please install 'taskiq[metrics]'.",
Expand Down Expand Up @@ -85,7 +85,7 @@ def startup(self) -> None:
This function starts prometheus server.
It starts it only in case if it's a worker process.
"""
from prometheus_client import start_http_server
from prometheus_client import start_http_server # noqa: PLC0415

if self.broker.is_worker_process:
try:
Expand Down
8 changes: 4 additions & 4 deletions taskiq/middlewares/taskiq_admin_middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from datetime import UTC, datetime
from datetime import datetime, timezone
from logging import getLogger
from typing import Any
from typing import Any, Optional
from urllib.parse import urljoin

import aiohttp
Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(
url: str,
api_token: str,
timeout: int = 5,
taskiq_broker_name: str | None = None,
taskiq_broker_name: Optional[str] = None,
) -> None:
super().__init__()
self.url = url
Expand All @@ -48,7 +48,7 @@ def __init__(

@staticmethod
def _now_iso() -> str:
return datetime.now(UTC).replace(tzinfo=None).isoformat()
return datetime.now(timezone.utc).replace(tzinfo=None).isoformat()

def _get_client(self) -> aiohttp.ClientSession:
"""Create and cache session."""
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_receiver_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from tests.utils import AsyncQueueBroker


@pytest.mark.anyio
async def test_successful() -> None:
broker = AsyncQueueBroker()
kicked = 0
Expand All @@ -28,7 +27,6 @@ def test_func() -> None:
assert kicked == desired_kicked


@pytest.mark.anyio
async def test_cancelation() -> None:
broker = AsyncQueueBroker()
kicked = 0
Expand Down
4 changes: 0 additions & 4 deletions tests/api/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
import contextlib
from datetime import datetime, timedelta, timezone

import pytest

from taskiq import TaskiqScheduler
from taskiq.api import run_scheduler_task
from taskiq.schedule_sources import LabelScheduleSource
from tests.utils import AsyncQueueBroker


@pytest.mark.anyio
async def test_successful() -> None:
broker = AsyncQueueBroker()
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])
Expand All @@ -26,7 +23,6 @@ def _() -> None:
scheduler_task.cancel()


@pytest.mark.anyio
async def test_cancelation() -> None:
broker = AsyncQueueBroker()
scheduler = TaskiqScheduler(broker, sources=[LabelScheduleSource(broker)])
Expand Down
7 changes: 0 additions & 7 deletions tests/brokers/test_inmemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from taskiq.state import TaskiqState


@pytest.mark.anyio
async def test_inmemory_success() -> None:
broker = InMemoryBroker()
test_val = uuid.uuid4().hex
Expand All @@ -23,7 +22,6 @@ async def task() -> str:
assert not broker._running_tasks


@pytest.mark.anyio
async def test_cannot_listen() -> None:
broker = InMemoryBroker()

Expand All @@ -32,7 +30,6 @@ async def test_cannot_listen() -> None:
pass


@pytest.mark.anyio
async def test_startup() -> None:
broker = InMemoryBroker()
test_value = uuid.uuid4().hex
Expand All @@ -51,7 +48,6 @@ async def _c_startup(state: TaskiqState) -> None:
assert broker.state.from_client == test_value


@pytest.mark.anyio
async def test_shutdown() -> None:
broker = InMemoryBroker()
test_value = uuid.uuid4().hex
Expand All @@ -70,7 +66,6 @@ async def _c_startup(state: TaskiqState) -> None:
assert broker.state.from_client == test_value


@pytest.mark.anyio
async def test_execution() -> None:
broker = InMemoryBroker()
test_value = uuid.uuid4().hex
Expand All @@ -87,7 +82,6 @@ async def test_task() -> str:
assert result.return_value == test_value


@pytest.mark.anyio
async def test_inline_awaits() -> None:
broker = InMemoryBroker(await_inplace=True)
slept = False
Expand All @@ -104,7 +98,6 @@ async def test_task() -> None:
assert not broker._running_tasks


@pytest.mark.anyio
async def test_wait_all() -> None:
broker = InMemoryBroker()
slept = False
Expand Down
4 changes: 0 additions & 4 deletions tests/cli/scheduler/test_updater.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from datetime import datetime
from typing import List, Union

import pytest

from taskiq import InMemoryBroker, ScheduleSource
from taskiq.cli.scheduler.run import get_all_schedules
from taskiq.scheduler.scheduled_task import ScheduledTask
Expand All @@ -20,7 +18,6 @@ async def get_schedules(self) -> List[ScheduledTask]:
return self.schedules


@pytest.mark.anyio
async def test_get_schedules_success() -> None:
"""Tests that schedules are returned correctly."""
schedules1 = [
Expand Down Expand Up @@ -62,7 +59,6 @@ async def test_get_schedules_success() -> None:
]


@pytest.mark.anyio
async def test_get_schedules_error() -> None:
"""Tests that if source returned an error, empty list will be returned."""
source1 = DummySource(
Expand Down
3 changes: 0 additions & 3 deletions tests/depends/test_progress_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def get_message(
)


@pytest.mark.anyio
@pytest.mark.parametrize(
"state,meta",
[
Expand All @@ -82,7 +81,6 @@ async def test_func(tes_val: ProgressTracker[Any] = TaskiqDepends()) -> None:
assert progress.state == state


@pytest.mark.anyio
async def test_progress_tracker_ctx_none() -> None:
broker = InMemoryBroker()

Expand All @@ -98,7 +96,6 @@ async def test_func() -> None:
assert progress is None


@pytest.mark.anyio
@pytest.mark.parametrize(
"state,meta",
[
Expand Down
4 changes: 0 additions & 4 deletions tests/formatters/test_json_formatter.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import json

import pytest

from taskiq.formatters.json_formatter import JSONFormatter
from taskiq.message import BrokerMessage, TaskiqMessage


@pytest.mark.anyio
async def test_json_dumps() -> None:
fmt = JSONFormatter()
msg = TaskiqMessage(
Expand Down Expand Up @@ -34,7 +31,6 @@ async def test_json_dumps() -> None:
assert json.loads(dumped.message) == json.loads(expected.message)


@pytest.mark.anyio
async def test_json_loads() -> None:
fmt = JSONFormatter()
msg = (
Expand Down
4 changes: 0 additions & 4 deletions tests/formatters/test_proxy_formatter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import pytest

from taskiq.brokers.inmemory_broker import InMemoryBroker
from taskiq.message import BrokerMessage, TaskiqMessage


@pytest.mark.anyio
async def test_proxy_dumps() -> None:
# uses json serializer by default
broker = InMemoryBroker()
Expand All @@ -29,7 +26,6 @@ async def test_proxy_dumps() -> None:
assert broker.formatter.dumps(msg) == expected


@pytest.mark.anyio
async def test_proxy_loads() -> None:
# uses json serializer by default
broker = InMemoryBroker()
Expand Down
3 changes: 0 additions & 3 deletions tests/middlewares/test_simple_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def broker() -> AsyncMock:
return mocked_broker


@pytest.mark.anyio
async def test_successful_retry(broker: AsyncMock) -> None:
middleware = SimpleRetryMiddleware()
middleware.set_broker(broker)
Expand All @@ -39,7 +38,6 @@ async def test_successful_retry(broker: AsyncMock) -> None:
assert resend.labels["_retries"] == "1"


@pytest.mark.anyio
async def test_no_retry(broker: AsyncMock) -> None:
middleware = SimpleRetryMiddleware()
middleware.set_broker(broker)
Expand All @@ -57,7 +55,6 @@ async def test_no_retry(broker: AsyncMock) -> None:
broker.kick.assert_not_called()


@pytest.mark.anyio
async def test_max_retries(broker: AsyncMock) -> None:
middleware = SimpleRetryMiddleware(default_retry_count=3)
middleware.set_broker(broker)
Expand Down
Loading