[DCP - Ingestion] Allow Ingestion Helper to start clearing the redis cache#2035
[DCP - Ingestion] Allow Ingestion Helper to start clearing the redis cache#2035gmechali wants to merge 1 commit into
Conversation
| return jsonify({'status': 'SUCCESS', 'message': 'Cache cleared'}), 200 | ||
| except Exception as e: | ||
| logging.error(f"Failed to flush Redis cache: {e}") | ||
| return jsonify({'status': 'ERROR', 'message': str(e)}), 500 |
There was a problem hiding this comment.
Code Review
This pull request introduces a new clear_redis_cache action to the ingestion helper, enabling asynchronous flushing of the Redis cache using environment-configured host and port settings. The redis library has been added to the project dependencies. Review feedback recommends using a context manager for the Redis connection and specifying a connection timeout to ensure better resource management and prevent potential hangs.
| import redis | ||
| r = redis.Redis(host=redis_host, port=int(redis_port)) | ||
| r.flushall(asynchronous=True) |
There was a problem hiding this comment.
It is recommended to use a context manager for the Redis connection to ensure that the connection pool is properly managed and resources are released. Additionally, specifying a socket_connect_timeout is a best practice to prevent the function from hanging indefinitely if the Redis server is unreachable or the network is slow.
| import redis | |
| r = redis.Redis(host=redis_host, port=int(redis_port)) | |
| r.flushall(asynchronous=True) | |
| import redis | |
| with redis.Redis(host=redis_host, port=int(redis_port), socket_connect_timeout=5) as r: | |
| r.flushall(asynchronous=True) |
This needs to be triggered by the workflow at the end of every workflow