Skip to content

Commit 4c3dd80

Browse files
committed
Use string enum for status
Signed-off-by: M Q <mingmelvinq@nvidia.com>
1 parent 0f6b5fd commit 4c3dd80

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

platforms/aidoc/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ sequenceDiagram
7272
REST Service-->>-Client: HTTP 409 Conflict
7373
7474
Client->>+REST Service: GET /status
75-
REST Service-->>-Client: HTTP 200 OK ("status": "BUSY")
75+
REST Service-->>-Client: HTTP 200 OK ("status": "PROCESSING")
7676
end
7777
7878
AppThread->>+AISpleenSegApp: Create instance(status_callback)
@@ -174,7 +174,7 @@ The script can be run multiple times or modified to loop with different output f
174174
- **Description**: Checks the current status of the processor.
175175
- **Success Response**:
176176
- **Code**: 200 OK
177-
- **Content**: `{ "status": "IDLE" }` or `{ "status": "BUSY" }`
177+
- **Content**: `{ "status": "IDLE" }` or `{ "status": "PROCESSING" }`
178178
179179
### Process Data
180180

platforms/aidoc/restful_app/app.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@
1616
import os
1717
import sys
1818
import threading
19+
from enum import Enum
1920
from http import HTTPStatus
2021

2122
import requests
2223
from flask import Flask, jsonify, request
2324
from flask_wtf.csrf import CSRFProtect
2425

26+
# Processing status enum per Aidoc API specification.
27+
class ProcessingStatus(str, Enum):
28+
INITIALIZING = "INITIALIZING"
29+
IDLE = "IDLE"
30+
PROCESSING = "PROCESSING"
31+
ERROR = "ERROR"
32+
2533
# The MONAI Deploy application to be wrapped.
2634
# This can be changed to any other application in the repository.
2735
# Provide the module path and the class name of the application.
@@ -40,7 +48,7 @@
4048
logging.basicConfig(stream=sys.stdout, level=logging.INFO)
4149

4250
# Global state to track processing status. A lock is used for thread safety.
43-
PROCESSING_STATUS = "IDLE"
51+
PROCESSING_STATUS = ProcessingStatus.IDLE
4452
PROCESSING_LOCK = threading.Lock()
4553

4654

@@ -87,7 +95,7 @@ def app_status_callback(summary: str):
8795

8896
try:
8997
logging.info("Starting processing in a background thread.")
90-
set_processing_status("BUSY")
98+
set_processing_status(ProcessingStatus.PROCESSING)
9199

92100
# Set environment variables for the MONAI Deploy application.
93101
# The application context will pick these up.
@@ -118,7 +126,7 @@ def app_status_callback(summary: str):
118126
app_status_callback(json.dumps(callback_msg))
119127

120128
finally:
121-
set_processing_status("IDLE")
129+
set_processing_status(ProcessingStatus.IDLE)
122130
logging.info("Processor is now IDLE.")
123131

124132

@@ -132,7 +140,7 @@ def status():
132140
@csrf.exempt
133141
def process():
134142
"""Endpoint to start a new processing job."""
135-
if get_processing_status() == "BUSY":
143+
if get_processing_status() == ProcessingStatus.PROCESSING:
136144
return jsonify({"error": "Processor is busy."}), HTTPStatus.CONFLICT
137145

138146
data = request.get_json()

0 commit comments

Comments
 (0)