Skip to content

Commit 36996ab

Browse files
authored
V1 of redis clear action (#2035)
1 parent 0e12551 commit 36996ab

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

import-automation/workflow/ingestion-helper/main.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,5 +289,23 @@ def ingestion_helper(request):
289289
except Exception as e:
290290
return (f"Aggregation failed: {str(e)}", 500)
291291

292+
elif action_type == 'clear_redis_cache':
293+
logging.info("Action: clear_redis_cache")
294+
redis_host = os.environ.get("REDIS_HOST")
295+
redis_port = os.environ.get("REDIS_PORT", "6379")
296+
if redis_host:
297+
try:
298+
import redis
299+
r = redis.Redis(host=redis_host, port=int(redis_port))
300+
r.flushall(asynchronous=True)
301+
logging.info(f"Redis cache at {redis_host}:{redis_port} flushed successfully (async).")
302+
return jsonify({'status': 'SUCCESS', 'message': 'Cache cleared'}), 200
303+
except Exception as e:
304+
logging.error(f"Failed to flush Redis cache: {e}")
305+
return jsonify({'status': 'ERROR', 'message': str(e)}), 500
306+
else:
307+
logging.warning("REDIS_HOST not set, skipping cache flush.")
308+
return jsonify({'status': 'SKIPPED', 'message': 'REDIS_HOST not set'}), 200
309+
292310
else:
293311
return (f'Unknown actionType: {action_type}', 400)

import-automation/workflow/ingestion-helper/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies = [
2929
"google-auth",
3030
"absl-py",
3131
"google-cloud-bigquery",
32+
"redis",
3233
]
3334

3435
[tool.hatch.build.targets.wheel]

0 commit comments

Comments
 (0)