1616import os
1717import sys
1818import threading
19+ from enum import Enum
1920from http import HTTPStatus
2021
2122import requests
2223from flask import Flask , jsonify , request
2324from 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.
4048logging .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
4452PROCESSING_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
133141def 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