SIENTIAPDE-994Add shutdown methods for Activities and OPC classes; enhance worker error handling
This commit is contained in:
@@ -47,3 +47,7 @@ class Activities(Postgres, MLFlow, Gates, OPC):
|
||||
@activity.defn(name="prepare_activity")
|
||||
async def prepare_activity(self, input_data: dict[str, Any]):
|
||||
await super().prepare_activity(input_data)
|
||||
|
||||
def shutdown(self):
|
||||
Postgres.close(self)
|
||||
OPC.shutdown(self)
|
||||
|
||||
@@ -99,3 +99,7 @@ class OPC(BaseActivity):
|
||||
data_type=tag_config['data_type'],
|
||||
tag_type='confidence'
|
||||
)
|
||||
|
||||
def shutdown(self):
|
||||
for opc in self.opc_repository.values():
|
||||
opc.disconnect()
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user