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")