Skip to content

Commit e1d221c

Browse files
Switch to Valkey, drop Celery (#18)
Co-authored-by: Filip Vágner <therazix@gmail.com>
1 parent 4394861 commit e1d221c

14 files changed

Lines changed: 721 additions & 368 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,16 @@ jobs:
4242
- name: Create Podman pod
4343
run: |
4444
podman pod create --name tmt-web-pod --infra-image=registry.k8s.io/pause:3.9 -p 8000:8000 -p 6379:6379
45-
# Exposing redis port as well for test_api.py::TestCelery::test_basic_test_request
45+
# Exposing valkey port as well for background task tests
4646
47-
- name: Start Redis container
47+
- name: Start valkey container
4848
run: |
49-
podman run -d --pod tmt-web-pod --name redis redis:latest
50-
51-
- name: Start Celery container
52-
run: |
53-
podman run -d --pod tmt-web-pod --name celery \
54-
-e REDIS_URL=redis://localhost:6379 \
55-
-e API_HOSTNAME=http://localhost:8000 \
56-
tmt-web:latest celery --app=tmt_web.service worker --loglevel=INFO
49+
podman run -d --pod tmt-web-pod --name valkey valkey/valkey:alpine
5750
5851
- name: Start Web container
5952
run: |
6053
podman run -d --pod tmt-web-pod --name web \
61-
-e REDIS_URL=redis://localhost:6379 \
54+
-e VALKEY_URL=valkey://localhost:6379 \
6255
-e API_HOSTNAME=http://localhost:8000 \
6356
tmt-web:latest uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000
6457

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ repos:
2424
additional_dependencies:
2525
- 'tmt'
2626
- 'pydantic'
27-
- 'celery-types'
2827
pass_filenames: false
2928

3029
- repo: https://github.com/charliermarsh/ruff-pre-commit

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ podman-compose up --build
1212

1313
Add `-d` for the service to run in the background.
1414

15-
In order to quickly experiment without using Celery use this:
15+
For quick development without container setup:
1616

1717
```bash
18-
USE_CELERY=false CLONE_DIR_PATH=/var/tmp/test uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000
18+
CLONE_DIR_PATH=/var/tmp/test uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000
1919
```
2020

2121
## Tests
@@ -29,15 +29,19 @@ Run `hatch env show` to see the list of available environments and their scripts
2929

3030
## Environment variables
3131

32-
- `REDIS_URL` - *optional*, passed to Celery on initialization as a `broker` and
33-
`backend` argument, default value is: `redis://localhost:6379`
32+
- `VALKEY_URL` - *optional*, connection URL for Valkey which is used for storing task state,
33+
default value is: `valkey://localhost:6379`
3434
- `CLONE_DIR_PATH` - *optional*, specifies the path where the repositories will
3535
be cloned, default value is: `./.repos/`
36-
- `USE_CELERY` - *optional*, specifies if the app should use Celery, set to
37-
`false` for running without Celery
3836
- `API_HOSTNAME` - *required*, specifies the hostname of the API, used for
3937
creating the callback URL to the service
4038

39+
## Architecture
40+
41+
The application uses FastAPI's built-in background tasks for asynchronous processing and
42+
Valkey for task state storage. This architecture provides a lightweight and efficient
43+
solution for handling long-running tasks without requiring external task queue infrastructure.
44+
4145
## API
4246

4347
The API version is defined by prefix in url, e.g. `/v0.1/status`.
@@ -50,7 +54,7 @@ exclusive.
5054

5155
### `/`
5256

53-
Returns ID of the created Celery task with additional metadata in JSON
57+
Returns ID of the created background task with additional metadata in JSON
5458
and callback url for `/status` endpoint, returns the same in HTML format
5559
if `format` is set to `html`.
5660

compose.yaml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ services:
44
build:
55
context: .
66
dockerfile: ./Containerfile
7-
command: uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000
87
environment:
9-
- REDIS_URL=redis://redis:6379
8+
- VALKEY_URL=valkey://valkey:6379
109
- API_HOSTNAME=http://localhost:8000
1110
ports:
1211
- 8000:8000
@@ -18,31 +17,17 @@ services:
1817
start_period: 5s
1918
restart: unless-stopped
2019
depends_on:
21-
redis:
20+
valkey:
2221
condition: service_healthy
2322

24-
redis:
25-
container_name: redis
26-
image: redis:latest
23+
valkey:
24+
container_name: valkey
25+
image: valkey/valkey:alpine
2726
ports:
2827
- 6379:6379
2928
healthcheck:
30-
test: ["CMD", "redis-cli", "ping"]
29+
test: ["CMD", "valkey-cli", "ping"]
3130
interval: 10s
3231
timeout: 5s
3332
retries: 3
3433
restart: unless-stopped
35-
36-
celery:
37-
container_name: celery
38-
build:
39-
context: .
40-
dockerfile: ./Containerfile
41-
command: celery --app=tmt_web.service worker --loglevel=INFO
42-
environment:
43-
- REDIS_URL=redis://redis:6379
44-
- API_HOSTNAME=http://localhost:8000
45-
depends_on:
46-
redis:
47-
condition: service_healthy
48-
restart: unless-stopped

entrypoint.sh

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,8 @@ error() {
88
# Handle signals
99
trap 'kill -TERM $PID' TERM INT
1010

11-
# Name of container to start
12-
APP=$1
11+
uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000 &
1312

14-
[ -z "$APP" ] && error "No app to run passed to entrypoint script"
15-
16-
case $APP in
17-
uvicorn)
18-
COMMAND="uvicorn tmt_web.api:app --reload --host 0.0.0.0 --port 8000"
19-
;;
20-
celery)
21-
COMMAND="celery --app=tmt_web.service worker --loglevel=INFO"
22-
;;
23-
*)
24-
error "Unknown app '$APP'"
25-
;;
26-
esac
27-
28-
$COMMAND &
2913
PID=$!
3014

3115
wait $PID

pyproject.toml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ classifiers = [
1919
"Programming Language :: Python",
2020
"Programming Language :: Python :: 3.12",
2121
"Framework :: FastAPI",
22-
"Framework :: Celery",
2322
"Topic :: Software Development :: Testing",
2423
"Operating System :: POSIX :: Linux",
2524
]
@@ -28,7 +27,7 @@ dependencies = [
2827
"fastapi~=0.115",
2928
"httpx~=0.27",
3029
"uvicorn~=0.30",
31-
"celery[redis]~=5.4",
30+
"valkey",
3231
]
3332

3433
[project.urls]
@@ -134,7 +133,10 @@ lint.ignore = [
134133
"S101", # Assert usage
135134
"PLR", # Pylint refactor
136135
"E501", # Line length
137-
]
136+
]
137+
"src/tmt_web/generators/html_generator.py" = [
138+
"E501", # Line length
139+
]
138140

139141
[tool.ruff.lint.pydocstyle]
140142
convention = "pep257"
@@ -156,3 +158,15 @@ no_implicit_reexport = true
156158

157159
python_version = "3.12"
158160
files = ["src/"]
161+
162+
[tool.pytest.ini_options]
163+
# Filter out specific warnings
164+
filterwarnings = [
165+
# Ignore pytest collection warnings for model classes that start with 'Test'
166+
"ignore:cannot collect test class 'TestData' because it has a __init__ constructor:pytest.PytestCollectionWarning",
167+
"ignore:cannot collect test class 'TestPlanData' because it has a __init__ constructor:pytest.PytestCollectionWarning",
168+
# Ignore pint and docutils deprecations from tmt
169+
"ignore:The frontend.OptionParser class will be replaced:DeprecationWarning",
170+
"ignore:The frontend.Option class will be removed:DeprecationWarning",
171+
"ignore:This function will be removed in future versions of pint.:DeprecationWarning"
172+
]

0 commit comments

Comments
 (0)