Support standard GRANIAN_* env vars and the rloop event loop
CI / Build and push docker image (push) Successful in 2m52s

- Launcher now only injects --interface/--host/--port when the matching
  GRANIAN_* env var is unset, so every granian option (GRANIAN_LOOP,
  GRANIAN_WORKERS, GRANIAN_HTTP, GRANIAN_HOST, GRANIAN_PORT, ...) can be
  configured via granian's standard GRANIAN_* environment variables
- Add the rloop event loop as a runtime dependency so GRANIAN_LOOP=rloop
  works out of the box (previously failed with a missing 'rloop' package)
This commit is contained in:
2026-08-03 05:28:04 +00:00
parent 96cf433793
commit c7d75f6899
5 changed files with 45 additions and 9 deletions
+29
View File
@@ -52,6 +52,35 @@ Configuration is read from environment variables:
| `RBCS_DIGEST` | *(unset)* | Hash the key with this algorithm (e.g. `sha256`) | | `RBCS_DIGEST` | *(unset)* | Hash the key with this algorithm (e.g. `sha256`) |
| `RBCS_MAX_AGE` | `7d` | Value TTL (`s`/`m`/`h`/`d`) | | `RBCS_MAX_AGE` | `7d` | Value TTL (`s`/`m`/`h`/`d`) |
### Configuring Granian
The server runs on [Granian](https://github.com/emmett-framework/granian) via
its RSGI interface. Any granian option can be configured with its standard
`GRANIAN_*` environment variables (see `granian --help`), for example:
```bash
GRANIAN_LOOP=rloop GRANIAN_WORKERS=4 GRANIAN_HTTP=2 rbcs-server
```
Every granian CLI option has a matching `GRANIAN_*` variable
(`GRANIAN_LOOP`, `GRANIAN_WORKERS`, `GRANIAN_HTTP`, `GRANIAN_TASK_IMPL`,
`GRANIAN_RUNTIME_THREADS`, `GRANIAN_BLOCKING_THREADS`, `GRANIAN_LOG_LEVEL`,
`GRANIAN_METRICS`, `GRANIAN_WS`, ...).
When a `GRANIAN_*` variable and the corresponding `RBCS_*` variable are both
set, the granian one wins:
- `GRANIAN_HOST` overrides `RBCS_HOST` (default `127.0.0.1`)
- `GRANIAN_PORT` overrides `RBCS_PORT` (default `8080`)
- `GRANIAN_INTERFACE` overrides the default `rsgi` interface
The Docker image ships the `rloop` event loop, so `GRANIAN_LOOP=rloop` works
out of the box:
```bash
docker run -e GRANIAN_LOOP=rloop -e RBCS_MEMCACHE_HOST=memcached kaya-rbcs
```
The app is also a plain ASGI application, so it can be served by any ASGI The app is also a plain ASGI application, so it can be served by any ASGI
server, e.g. `daphne kaya_rbcs.app:app`. server, e.g. `daphne kaya_rbcs.app:app`.
+1
View File
@@ -26,6 +26,7 @@ dependencies = [
server = [ server = [
"kaya-rsgi", "kaya-rsgi",
"granian", "granian",
"rloop",
] ]
dev = [ dev = [
"httpx", "httpx",
+1
View File
@@ -4,3 +4,4 @@ kaya-core
aiomcache aiomcache
kaya-rsgi kaya-rsgi
granian granian
rloop
+2
View File
@@ -25,6 +25,8 @@ pwo==0.1.2
# via # via
# kaya-core # kaya-core
# kaya-rsgi # kaya-rsgi
rloop==0.3.1
# via -r requirements.in
typing-extensions==4.16.0 typing-extensions==4.16.0
# via # via
# kaya-core # kaya-core
+12 -9
View File
@@ -1,3 +1,4 @@
import os
import sys import sys
from typing import List, NoReturn from typing import List, NoReturn
@@ -14,15 +15,17 @@ def main() -> NoReturn:
) from exc ) from exc
config = Config.from_env() config = Config.from_env()
args: List[str] = [ args: List[str] = []
'--interface', # Only inject our own values when the equivalent GRANIAN_* environment
'rsgi', # variable is not set, so every granian option stays configurable via
'--host', # granian's standard GRANIAN_* environment variables.
config.host, if not os.getenv('GRANIAN_INTERFACE'):
'--port', args += ['--interface', 'rsgi']
str(config.port), if not os.getenv('GRANIAN_HOST'):
'kaya_rbcs.app:app', args += ['--host', config.host]
] if not os.getenv('GRANIAN_PORT'):
args += ['--port', str(config.port)]
args.append('kaya_rbcs.app:app')
sys.argv = [sys.argv[0], *args] sys.argv = [sys.argv[0], *args]
entrypoint() # type: ignore[no-untyped-call] entrypoint() # type: ignore[no-untyped-call]
raise SystemExit(0) raise SystemExit(0)