Skip to content

Commit c7f880a

Browse files
authored
Merge pull request #9 from flowdacity/feat/migrate-env-and-cli-args
Migrate to environment variables for configuration and enhance documentation
2 parents db50801 + 38f534c commit c7f880a

29 files changed

+1813
-1806
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
uses: codecov/codecov-action@v5
4949
with:
5050
token: ${{ secrets.CODECOV_TOKEN }}
51-
slug: flowdacity/flowdacity-queue-server
51+
slug: flowdacity/queue-server

README.md

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1-
[![Run tests and upload coverage](https://github.com/flowdacity/flowdacity-queue-server/actions/workflows/test.yml/badge.svg)](https://github.com/flowdacity/flowdacity-queue-server/actions/workflows/test.yml)
2-
[![codecov](https://codecov.io/github/flowdacity/flowdacity-queue-server/graph/badge.svg?token=9AK3GR856C)](https://codecov.io/github/flowdacity/flowdacity-queue-server)
1+
[![Run tests and upload coverage](https://github.com/flowdacity/queue-server/actions/workflows/test.yml/badge.svg)](https://github.com/flowdacity/queue-server/actions/workflows/test.yml)
2+
[![codecov](https://codecov.io/github/flowdacity/queue-server/graph/badge.svg?token=9AK3GR856C)](https://codecov.io/github/flowdacity/queue-server)
33

44
Flowdacity Queue Server
55
=======================
66

7-
An async HTTP API for the [Flowdacity Queue (FQ)](https://github.com/flowdacity/flowdacity-queue) core, built with Starlette and Uvicorn. It keeps the original SHARQ behavior (leaky-bucket rate limiting and dynamic queues) while modernizing the stack.
7+
An async HTTP API for [Flowdacity Queue (FQ)](https://github.com/flowdacity/queue-engine), built with Starlette and Uvicorn.
88

99
## Prerequisites
1010

1111
- Python 3.12+
12-
- Redis 7+ reachable from the server
13-
- A Flowdacity Queue config file (see `default.conf` for a starter)
12+
- Redis 7+
1413

1514
## Installation
1615

17-
Clone the repo and install the package plus dev tools (uses [`uv`](https://github.com/astral-sh/uv) by default):
18-
1916
```bash
2017
uv sync --group dev
21-
# or: uv pip install --system .
2218
```
2319

24-
If you prefer pip/venv without `uv`:
20+
If you prefer a virtualenv without `uv`:
2521

2622
```bash
2723
python -m venv .venv
@@ -32,29 +28,48 @@ pip install pytest pytest-cov
3228

3329
## Configuration
3430

35-
- Point the server at your FQ config via `FQ_CONFIG` (defaults to `./default.conf`).
36-
- `default.conf` defines three sections:
37-
- `[fq]` queue behavior (intervals, requeue limits).
38-
- `[fq-server]` host/port for the HTTP server (used by Docker/local defaults).
39-
- `[redis]` connection details for your Redis instance.
40-
- Copy and tweak as needed:
31+
The server reads all queue and Redis settings from environment variables. No config file is required.
32+
These application settings are validated at startup by `QueueServerSettings` with `pydantic-settings`.
33+
34+
| Variable | Default | Description |
35+
| --- | --- | --- |
36+
| `JOB_EXPIRE_INTERVAL` | `1000` | Milliseconds before a dequeued job is considered expired. |
37+
| `JOB_REQUEUE_INTERVAL` | `1000` | Milliseconds between expired-job requeue passes. |
38+
| `DEFAULT_JOB_REQUEUE_LIMIT` | `-1` | Default retry limit. `-1` retries forever. |
39+
| `ENABLE_REQUEUE_SCRIPT` | `true` | Enables the background requeue loop. |
40+
| `LOG_LEVEL` | `INFO` | Application log level. |
41+
| `REDIS_DB` | `0` | Redis database number. |
42+
| `REDIS_KEY_PREFIX` | `fq_server` | Prefix used for Redis keys. |
43+
| `REDIS_CONN_TYPE` | `tcp_sock` | Redis connection type: `tcp_sock` or `unix_sock`. |
44+
| `REDIS_HOST` | `127.0.0.1` | Redis host for TCP connections. |
45+
| `REDIS_PORT` | `6379` | Redis port for TCP connections. |
46+
| `REDIS_PASSWORD` | empty | Redis password. |
47+
| `REDIS_CLUSTERED` | `false` | Enables Redis Cluster mode. |
48+
| `REDIS_UNIX_SOCKET_PATH` | `/tmp/redis.sock` | Redis socket path when `REDIS_CONN_TYPE=unix_sock`. |
49+
50+
Boolean env vars accept only `true` or `false`.
51+
52+
`PORT` is not part of `QueueServerSettings`. It is runtime launcher configuration used by the container entrypoint or by the `uvicorn` CLI, so pass it as a launcher environment variable or `--port` argument.
53+
54+
## Run locally
55+
56+
Start Redis:
4157

4258
```bash
43-
cp default.conf local.conf
44-
# edit local.conf to match your Redis host/port/password
59+
make redis-up
4560
```
4661

47-
## Run the server locally
62+
Run the API:
4863

4964
```bash
50-
# ensure Redis is running (make redis starts a container)
51-
make redis
52-
53-
# start the ASGI server
54-
FQ_CONFIG=./local.conf uv run uvicorn asgi:app --host 0.0.0.0 --port 8080
65+
export PORT=8300
66+
export REDIS_HOST=127.0.0.1
67+
uv run uvicorn asgi:app --host 0.0.0.0 --port "${PORT}"
5568
```
5669

57-
Docker Compose is also available:
70+
## Docker
71+
72+
`docker-compose.yml` now passes the queue settings through env vars, so there is no mounted config file:
5873

5974
```bash
6075
docker compose up --build
@@ -63,34 +78,23 @@ docker compose up --build
6378
## API quick start
6479

6580
```bash
66-
# health
67-
curl http://127.0.0.1:8080/
81+
curl http://127.0.0.1:8300/
6882

69-
# enqueue a job
70-
curl -X POST http://127.0.0.1:8080/enqueue/sms/user42/ \
83+
curl -X POST http://127.0.0.1:8300/enqueue/sms/user42/ \
7184
-H "Content-Type: application/json" \
7285
-d '{"job_id":"job-1","payload":{"message":"hi"},"interval":1000}'
7386

74-
# dequeue
75-
curl http://127.0.0.1:8080/dequeue/sms/
87+
curl http://127.0.0.1:8300/dequeue/sms/
7688

77-
# mark finished
78-
curl -X POST http://127.0.0.1:8080/finish/sms/user42/job-1/
89+
curl -X POST http://127.0.0.1:8300/finish/sms/user42/job-1/
7990

80-
# metrics
81-
curl http://127.0.0.1:8080/metrics/
82-
curl http://127.0.0.1:8080/metrics/sms/user42/
91+
curl http://127.0.0.1:8300/metrics/
92+
curl http://127.0.0.1:8300/metrics/sms/user42/
8393
```
8494

85-
All endpoints return JSON; failures surface as HTTP 4xx/5xx with a `status` field in the body.
86-
8795
## Testing
8896

89-
Redis must be available. With dev deps installed:
90-
9197
```bash
92-
uv run pytest
93-
# or
9498
make test
9599
```
96100

asgi.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
# Copyright (c) 2025 Flowdacity Team. See LICENSE.txt for details.
22
# ASGI application entrypoint for Flowdacity Queue (FQ) Server
33

4-
import os
5-
from fq_server import setup_server
6-
7-
# read config path from env variable, use default if not set
8-
fq_config_path = os.environ.get("FQ_CONFIG")
9-
if fq_config_path is None:
10-
print(
11-
"Warning: FQ_CONFIG environment variable not set. Using default config path './default.conf'."
12-
)
13-
fq_config_path = "./default.conf"
14-
fq_config_path = os.path.abspath(fq_config_path)
15-
16-
server = setup_server(fq_config_path)
4+
import logging
5+
6+
from fq_server import QueueServerSettings, setup_server
7+
8+
9+
def configure_logging(log_level: str) -> None:
10+
level = getattr(logging, log_level)
11+
root_logger = logging.getLogger()
12+
13+
if not root_logger.handlers:
14+
logging.basicConfig(
15+
level=level,
16+
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
17+
)
18+
19+
logging.getLogger("fq_server").setLevel(level)
20+
21+
22+
settings = QueueServerSettings.from_env()
23+
configure_logging(settings.log_level)
24+
server = setup_server(settings.to_fq_config())
1725

1826
# ASGI app exposed for Uvicorn/Hypercorn
1927
app = server.app

default.conf

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker-compose.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ services:
22
app:
33
build: .
44
environment:
5-
- FQ_CONFIG=/app/default.conf
6-
- PORT=8080
5+
JOB_EXPIRE_INTERVAL: 1000
6+
JOB_REQUEUE_INTERVAL: 1000
7+
DEFAULT_JOB_REQUEUE_LIMIT: -1
8+
ENABLE_REQUEUE_SCRIPT: "true"
9+
LOG_LEVEL: INFO
10+
REDIS_DB: 0
11+
REDIS_KEY_PREFIX: fq_server
12+
REDIS_CONN_TYPE: tcp_sock
13+
REDIS_HOST: redis
14+
REDIS_PORT: 6379
15+
REDIS_PASSWORD: ""
16+
REDIS_CLUSTERED: "false"
717
ports:
8-
- "8080:8080"
9-
volumes:
10-
- ./default.conf:/app/default.conf:ro
18+
- "8300:8300"
1119
depends_on:
1220
redis:
1321
condition: service_healthy

docs/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,17 @@ qthelp:
8585
@echo
8686
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
8787
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
88-
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/fqserver.qhcp"
88+
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/queue-server.qhcp"
8989
@echo "To view the help file:"
90-
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/fqserver.qhc"
90+
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/queue-server.qhc"
9191

9292
devhelp:
9393
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
9494
@echo
9595
@echo "Build finished."
9696
@echo "To view the help file:"
97-
@echo "# mkdir -p $$HOME/.local/share/devhelp/fqserver"
98-
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/fqserver"
97+
@echo "# mkdir -p $$HOME/.local/share/devhelp/queue-server"
98+
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/queue-server"
9999
@echo "# devhelp"
100100

101101
epub:

docs/_templates/layout.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% extends "!layout.html" %}
22

33
{%- block extrahead %}
4-
<a href="https://github.com/plivo/fq-server"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
4+
<a href="https://github.com/flowdacity/queue-server"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/e7bbb0521b397edbd5fe43e7f760759336b5e05f/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_green_007200.png"></a>
55
{% endblock %}

0 commit comments

Comments
 (0)