SIENTIAPDE-994Add shutdown methods for Activities and OPC classes; enhance worker error handling

This commit is contained in:
vitor-aignosi
2025-05-28 08:23:50 -03:00
parent 6f81ce7d03
commit 325d22f241
4 changed files with 205 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
from temporalio import workflow, client
from temporalio.worker import Worker
import sys
with workflow.unsafe.imports_passed_through():
import os
@@ -90,7 +91,19 @@ async def main():
logger.info('Workers started successfully')
await asyncio.gather(*handlers)
try:
# This will run the workers and wait for them to complete.
# If an exception occurs in any of the worker handlers, it will be propagated here.
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())