mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
clean templates out of redis when we do update-templates
This commit is contained in:
@@ -18,7 +18,7 @@ from sqlalchemy import and_
|
|||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from app import db
|
from app import db, redis_store
|
||||||
from app.aws import s3
|
from app.aws import s3
|
||||||
from app.celery.nightly_tasks import cleanup_unfinished_jobs
|
from app.celery.nightly_tasks import cleanup_unfinished_jobs
|
||||||
from app.celery.tasks import process_row
|
from app.celery.tasks import process_row
|
||||||
@@ -799,6 +799,24 @@ def update_templates():
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for d in data:
|
for d in data:
|
||||||
_update_template(d["id"], d["name"], d["type"], d["content"], d["subject"])
|
_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")
|
@notify_command(name="create-new-service")
|
||||||
|
|||||||
Reference in New Issue
Block a user