Skip to content

Commit b77dba6

Browse files
authored
feat: adds additional plugin slot value
feat: adds additional slot value
2 parents 27cfd7b + 6ca2668 commit b77dba6

6 files changed

Lines changed: 62 additions & 6 deletions

File tree

litestar_saq/config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from dataclasses import dataclass, field
44
from pathlib import Path
5-
from typing import TYPE_CHECKING, Callable, Collection, Dict, Mapping, TypeVar, cast
5+
from typing import TYPE_CHECKING, Callable, Collection, Dict, Mapping, TypeVar, Union, cast
66

77
from litestar.exceptions import ImproperlyConfiguredException
88
from litestar.serialization import decode_json, encode_json
@@ -23,8 +23,8 @@
2323
from saq.types import Function
2424

2525
T = TypeVar("T")
26-
TaskQueue = Queue | SaqQueue
27-
DumpType = SaqDumpType | Callable[[Dict], bytes]
26+
TaskQueue = Union[Queue, SaqQueue]
27+
DumpType = Union[SaqDumpType, Callable[[Dict], bytes]]
2828

2929

3030
def serializer(value: Any) -> str:

litestar_saq/controllers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ async def job_info(queue: TaskQueue, job_id: str) -> Job:
2323

2424

2525
@lru_cache(typed=True)
26-
def build_controller(url_base: str = "/saq", controller_guards: list[Guard] | None = None) -> type[Controller]: # noqa: C901
26+
def build_controller( # noqa: C901
27+
url_base: str = "/saq",
28+
controller_guards: list[Guard] | None = None,
29+
) -> type[Controller]:
2730
from litestar import Controller, MediaType, get, post
2831
from litestar.exceptions import NotFoundException
2932
from litestar.status_codes import HTTP_202_ACCEPTED

litestar_saq/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class SAQPlugin(InitPluginProtocol, CLIPluginProtocol):
2424
"""SAQ plugin."""
2525

26-
__slots__ = ("_config",)
26+
__slots__ = ("_config", "_worker_instances")
2727

2828
def __init__(self, config: SAQConfig) -> None:
2929
"""Initialize ``SAQPlugin``.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ license = {text = "MIT"}
3030
name = "litestar-saq"
3131
readme = "README.md"
3232
requires-python = ">=3.8"
33-
version = "0.1.11"
33+
version = "0.1.12"
3434

3535
[project.optional-dependencies]
3636
hiredis = ["hiredis"]
@@ -201,6 +201,7 @@ classmethod-decorators = [
201201
"TRY",
202202
"UP006",
203203
"SLF001",
204+
"ERA001",
204205
]
205206

206207
[tool.ruff.isort]

tests/conftest.py

Whitespace-only changes.

tests/test_plugin.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from unittest.mock import Mock
2+
3+
import pytest
4+
from litestar.cli._utils import LitestarGroup as Group
5+
6+
from litestar_saq.config import SAQConfig, TaskQueues
7+
from litestar_saq.plugin import SAQPlugin
8+
9+
# Assuming SAQConfig, Worker, Group, AppConfig, TaskQueues, Queue are available and can be imported
10+
# Assuming there are meaningful __eq__ methods for comparisons where needed
11+
12+
13+
# Test on_cli_init method
14+
@pytest.mark.parametrize(
15+
"cli_group",
16+
[
17+
# ID: Test-CLI-Init-1
18+
Mock(Group),
19+
],
20+
ids=["happy-path"],
21+
)
22+
def test_on_cli_init(cli_group: Group) -> None:
23+
# Arrange
24+
config = Mock(SAQConfig)
25+
plugin = SAQPlugin(config)
26+
27+
# Act
28+
plugin.on_cli_init(cli_group)
29+
30+
# Assert
31+
cli_group.add_command.assert_called_once()
32+
33+
34+
# Test get_queues method
35+
@pytest.mark.parametrize(
36+
"queues",
37+
[
38+
# ID: Test-Get-Queues-1
39+
Mock(),
40+
],
41+
ids=["happy-path"],
42+
)
43+
def test_get_queues(queues: TaskQueues) -> None:
44+
# Arrange
45+
config = Mock(SAQConfig, get_queues=Mock(return_value=queues))
46+
plugin = SAQPlugin(config)
47+
48+
# Act
49+
result = plugin.get_queues()
50+
51+
# Assert
52+
assert result == queues

0 commit comments

Comments
 (0)