From 952e3c643480e5af730a71ffc8d12d00d07ead5e Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Mon, 1 Apr 2024 14:30:49 -0700 Subject: [PATCH] clean templates out of redis when we do update-templates --- app/commands.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/commands.py b/app/commands.py index 17e8e1058..7e382745d 100644 --- a/app/commands.py +++ b/app/commands.py @@ -18,7 +18,7 @@ from sqlalchemy import and_ from sqlalchemy.exc import IntegrityError from sqlalchemy.orm.exc import NoResultFound -from app import db +from app import db, redis_store from app.aws import s3 from app.celery.nightly_tasks import cleanup_unfinished_jobs from app.celery.tasks import process_row @@ -799,6 +799,24 @@ def update_templates(): data = json.load(f) for d in data: _update_template(d["id"], d["name"], d["type"], d["content"], d["subject"]) + _clear_templates_from_cache() + + +def _clear_templates_from_cache(): + # When we update-templates in the db, we need to make sure to delete them + # from redis, otherwise the old versions will stick around forever. + CACHE_KEYS = [ + "service-????????-????-????-????-????????????-templates", + "service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-version-*", # noqa + "service-????????-????-????-????-????????????-template-????????-????-????-????-????????????-versions", # noqa + ] + + + count1 = redis_store.delete_by_pattern(CACHE_KEYS[1]) + num_deleted = sum( + redis_store.delete_by_pattern(pattern) for pattern in CACHE_KEYS + ) + @notify_command(name="create-new-service")