SIENTIAPDE-1082

Implement shutdown methods for Activities and Kafka; enhance error handling in worker main function
This commit is contained in:
vitor-aignosi
2025-06-09 15:09:53 -03:00
parent b8beb0e151
commit 8cf3273714
3 changed files with 25 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ from temporalio import workflow, client
from temporalio.worker import Worker
with workflow.unsafe.imports_passed_through():
import sys
import os
from sientia_do.notifications.handlers import NotificationHandler
from sientia_do.temporal.utils.logger import get_logger
@@ -91,7 +92,18 @@ async def main():
logger.info('Workers started successfully')
await asyncio.gather(*handlers)
try:
await asyncio.gather(*handlers)
except BaseException as e:
logger.error("An unhandled exception occurred: %s", e, exc_info=True)
finally:
if notification_handler:
notification_handler.shutdown()
if activities:
activities.shutdown()
# Exit with a non-zero status code to indicate failure to Kubernetes
sys.exit(1)
if __name__ == '__main__':
asyncio.run(main())