Skip to content

Commit 0ece3c9

Browse files
add status to delete requests
1 parent 7e71e58 commit 0ece3c9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

cads_broker/entry_points.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import random
66
import sqlite3
77
import uuid
8+
from enum import Enum
89
from typing import Any, Optional
910

1011
import sqlalchemy as sa
@@ -108,16 +109,24 @@ def requests_cleaner(
108109
raise
109110

110111

112+
class RequestStatus(str, Enum):
113+
"""Enum for request status."""
114+
115+
running = "running"
116+
accepted = "accepted"
117+
118+
111119
@app.command()
112-
def delete_running_requests(
120+
def delete_requests(
121+
status: RequestStatus = RequestStatus.running,
113122
connection_string: Optional[str] = None,
114123
minutes: float = typer.Option(0.0),
115124
seconds: float = typer.Option(0.0),
116125
hours: float = typer.Option(0.0),
117126
days: float = typer.Option(0.0),
118127
skip_confirmation: Annotated[bool, typer.Option("--yes", "-y")] = False,
119128
) -> None:
120-
"""Remove records from the system_requests table that are currently running.
129+
"""Remove records from the system_requests table that are in the specified status.
121130
122131
Parameters
123132
----------
@@ -133,7 +142,7 @@ def delete_running_requests(
133142
database.logger.info(f"deleting old system_requests before {timestamp}.")
134143
statement = (
135144
sa.select(database.SystemRequest)
136-
.where(database.SystemRequest.status == "running")
145+
.where(database.SystemRequest.status == status)
137146
.where(database.SystemRequest.created_at < timestamp)
138147
)
139148
requests = session.scalars(statement).all()

0 commit comments

Comments
 (0)