clean templates out of redis when we do update-templates

This commit is contained in:
Kenneth Kehl
2024-04-01 14:30:49 -07:00
parent 24aea5efc3
commit 952e3c6434

View File

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