Skip to content

Commit 467c252

Browse files
committed
core upgrade
- Core upgraded - max 2 concurrent messages at a time
1 parent ad1b00d commit 467c252

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fastapi==0.88.0
22
pydantic==1.10.4
3-
python-ms-core==0.0.21
3+
python-ms-core==0.0.22
44
uvicorn==0.20.0
55
html_testRunner==1.2.1
66
python-osw-validation==0.2.4

src/main.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
prefix_router = APIRouter(prefix='/health')
1111

12+
# Have a reference to validator in the app object
13+
app.validator = None
1214

1315
@lru_cache()
1416
def get_settings():
@@ -18,7 +20,8 @@ def get_settings():
1820
@app.on_event('startup')
1921
async def startup_event(settings: Settings = Depends(get_settings)) -> None:
2022
try:
21-
OSWValidator()
23+
# OSWValidator()
24+
app.validator = OSWValidator()
2225
except:
2326
print('\n\n\x1b[31m Application startup failed due to missing or invalid .env file \x1b[0m')
2427
print('\x1b[31m Please provide the valid .env file and .env file should contains following parameters\x1b[0m')
@@ -34,6 +37,11 @@ async def startup_event(settings: Settings = Depends(get_settings)) -> None:
3437
child.kill()
3538
parent.kill()
3639

40+
@app.on_event('shutdown')
41+
async def shutdown_event() -> None:
42+
print('Shutting down the application')
43+
if app.validator:
44+
app.validator.stop_listening()
3745

3846
@app.get('/', status_code=status.HTTP_200_OK)
3947
@prefix_router.get('/', status_code=status.HTTP_200_OK)

src/osw_validator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def __init__(self):
3131
self.logger = self.core.get_logger()
3232
self.storage_client = self.core.get_storage_client()
3333
self.auth = self.core.get_authorizer(config=options)
34-
self.start_listening()
34+
self.listener_thread = threading.Thread(target=self.start_listening)
35+
self.listener_thread.start()
3536

3637
def start_listening(self):
3738
def process(message) -> None:
@@ -103,3 +104,6 @@ def has_permission(self, roles: List[str], queue_message: Upload) -> bool:
103104
except Exception as error:
104105
print('Error validating the request authorization:', error)
105106
return False
107+
108+
def stop_listening(self):
109+
self.listener_thread.join(timeout=0) # Stop the thread during shutdown.Its still an attempt. Not sure if this will work.

0 commit comments

Comments
 (0)