Merge pull request #4 from Aignosi/SIENTIAPDE-1082-ajustar-o-worker-e-activities-para-ter-um-destrutor-explicito-como-o-laborious
SIENTIAPDE-1082
This commit is contained in:
@@ -4,4 +4,4 @@ sqlalchemy
|
|||||||
asyncua
|
asyncua
|
||||||
redis
|
redis
|
||||||
git+ssh://git@github.com/Aignosi/sientia-dataops-library.git@1.1.14
|
git+ssh://git@github.com/Aignosi/sientia-dataops-library.git@1.1.14
|
||||||
git+ssh://git@github.com/Aignosi/sientia-mlops-library.git
|
git+ssh://git@github.com/Aignosi/sientia-mlops-library.git@0.38.1
|
||||||
|
|||||||
@@ -65,3 +65,7 @@ class Activities(Postgres, Redis, Kafka, Gates):
|
|||||||
@activity.defn(name="prepare_activity")
|
@activity.defn(name="prepare_activity")
|
||||||
async def prepare_activity(self, input_data: dict[str, Any]):
|
async def prepare_activity(self, input_data: dict[str, Any]):
|
||||||
await super().prepare_activity(input_data)
|
await super().prepare_activity(input_data)
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
Postgres.close(self)
|
||||||
|
Kafka.close(self)
|
||||||
|
|||||||
@@ -25,6 +25,14 @@ class Kafka(BaseActivity):
|
|||||||
|
|
||||||
BaseActivity.__init__(self, logger, notification_handler)
|
BaseActivity.__init__(self, logger, notification_handler)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
"""Closes the connector connection."""
|
||||||
|
self.logger.info("Closing Kafka connector...")
|
||||||
|
self.kafka_connector.close()
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
self.close()
|
||||||
|
|
||||||
@activity.defn(name="load_from_kafka")
|
@activity.defn(name="load_from_kafka")
|
||||||
async def load_from_kafka(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
async def load_from_kafka(self, input_data: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ from temporalio import workflow, client
|
|||||||
from temporalio.worker import Worker
|
from temporalio.worker import Worker
|
||||||
|
|
||||||
with workflow.unsafe.imports_passed_through():
|
with workflow.unsafe.imports_passed_through():
|
||||||
|
import sys
|
||||||
import os
|
import os
|
||||||
from sientia_do.notifications.handlers import NotificationHandler
|
from sientia_do.notifications.handlers import NotificationHandler
|
||||||
from sientia_do.temporal.utils.logger import get_logger
|
from sientia_do.temporal.utils.logger import get_logger
|
||||||
@@ -91,7 +92,18 @@ async def main():
|
|||||||
|
|
||||||
logger.info('Workers started successfully')
|
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__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
||||||
|
|||||||
Reference in New Issue
Block a user