Skip to content

Commit d1551d2

Browse files
authored
feat: adds redis kwargs and info command
feat: adds redis kwargs and info command
2 parents cfd337f + 4baea50 commit d1551d2

5 files changed

Lines changed: 50 additions & 30 deletions

File tree

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: mixed-line-ending
1818
- id: trailing-whitespace
1919
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: "v0.0.292"
20+
rev: "v0.1.0"
2121
hooks:
2222
- id: ruff
2323
args: ["--fix"]
@@ -53,6 +53,6 @@ repos:
5353
"litestar[cli]",
5454
]
5555
- repo: https://github.com/sphinx-contrib/sphinx-lint
56-
rev: "v0.6.8"
56+
rev: "v0.8.1"
5757
hooks:
5858
- id: sphinx-lint

litestar_saq/cli.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def build_cli_app() -> Group:
1919
from click import IntRange, group, option
2020
from litestar.cli._utils import LitestarGroup, console
2121

22-
@group(cls=LitestarGroup, name="workers")
22+
@group(cls=LitestarGroup, name="workers", no_args_is_help=True)
2323
def background_worker_group() -> None:
2424
"""Manage background task workers."""
2525

@@ -66,6 +66,26 @@ def run_worker(
6666
for worker_instance in plugin.get_workers():
6767
loop.run_until_complete(worker_instance.stop())
6868

69+
@background_worker_group.command(
70+
name="status",
71+
help="Check the status of currently configured workers and queues.",
72+
)
73+
@option("-v", "--verbose", help="Enable verbose logging.", is_flag=True, default=None, type=bool, required=False)
74+
@option("-d", "--debug", help="Enable debugging.", is_flag=True, default=None, type=bool, required=False)
75+
def worker_status(
76+
app: Litestar,
77+
verbose: bool | None,
78+
debug: bool | None,
79+
) -> None:
80+
"""Run the API server."""
81+
console.rule("[yellow]Checking SAQ worker status[/]", align="left")
82+
if app.logging_config is not None:
83+
app.logging_config.configure()
84+
if debug is not None or verbose is not None:
85+
app.debug = True
86+
plugin = get_saq_plugin(app)
87+
show_saq_info(app, 1, plugin)
88+
6989
return background_worker_group
7090

7191

litestar_saq/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class SAQConfig:
6262
"""Pre-configured Redis instance to use."""
6363
redis_url: str | None = None
6464
"""Redis URL to connect with."""
65+
redis_kwargs: dict[str, Any] = field(
66+
default_factory=lambda: {"socket_connect_timeout": 2, "socket_keepalive": 5, "health_check_interval": 5},
67+
)
68+
"""Redis kwargs to pass into a redis instance."""
6569
namespace: str = "saq"
6670
"""Namespace to use for Redis"""
6771
queue_instances: Mapping[str, Queue] | None = None
@@ -139,12 +143,8 @@ def get_redis(self) -> Redis:
139143
return self.redis
140144
pool = ConnectionPool.from_url(
141145
url=cast("str", self.redis_url),
142-
decode_responses=False,
143-
socket_connect_timeout=2,
144-
socket_keepalive=5,
145-
health_check_interval=5,
146146
)
147-
self.redis = Redis(connection_pool=pool)
147+
self.redis = Redis(connection_pool=pool, **self.redis_kwargs)
148148
return self.redis
149149

150150
def get_queues(self) -> TaskQueues:

pdm.lock

Lines changed: 21 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 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.8"
33+
version = "0.1.9"
3434

3535
[project.urls]
3636
Changelog = "https://cofin.github.io/litesatr-saq/latest/changelog"

0 commit comments

Comments
 (0)