Skip to content

Commit 6fbd409

Browse files
committed
Add fabric task to clear cached templates
The templates in static and frontend are cached in the application. When the emergency banner is deployed (and removed) we need to purge these caches so that static will regenerate the templates. There is already a fabric function that clears down the wrapper templates that display the banner on most pages. We need to add the homepage template to this list. We also need to purge tmp/cache in the frontend app. Set the `warn_only` flag to True so that fabric won't throw an error and quit if the template it's trying to purge has already been removed. This fabric script is a temporary work around until centralised caching is implemented.
1 parent b599f60 commit 6fbd409

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

campaigns.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import StringIO
22

3-
from fabric.api import env, put, roles, runs_once, sudo, task
3+
from fabric.api import env, put, roles, runs_once, settings, sudo, task
44
from fabric.operations import prompt
55
from fabric.tasks import execute
66

@@ -14,6 +14,12 @@
1414

1515
APPLICATIONS = ['static', 'frontend']
1616
CAMPAIGN_CLASSES = ['red', 'black', 'green']
17+
TEMPLATES = [
18+
'wrapper.html.erb',
19+
'homepage.html.erb',
20+
'header_footer_only.html.erb',
21+
'core_layout.html.erb',
22+
]
1723

1824

1925
def validate_classes(campaign_class):
@@ -70,8 +76,13 @@ def clear_static_generated_templates():
7076
This function clears the public/template directory to force it to
7177
be regenerated to include the emergency campaign.
7278
"""
73-
for template in ('wrapper.html.erb', 'header_footer_only.html.erb', 'core_layout.html.erb'):
74-
sudo('rm /var/apps/static/public/templates/{}'.format(template))
79+
for template in TEMPLATES:
80+
with settings(warn_only=True):
81+
sudo('rm /var/apps/static/public/templates/{}'.format(template))
82+
83+
84+
def clear_frontend_cache():
85+
sudo("rm -rf /var/apps/frontend/tmp/cache/*")
7586

7687

7788
def deploy_banner(application):
@@ -117,3 +128,13 @@ def remove_emergency_banner():
117128
"""Remove all banners from GOV.UK"""
118129
for application in APPLICATIONS:
119130
remove_banner(application)
131+
132+
133+
@task
134+
@roles('class-frontend')
135+
def clear_cached_templates():
136+
for application in APPLICATIONS:
137+
if application == 'frontend':
138+
clear_frontend_cache()
139+
if application == 'static':
140+
clear_static_generated_templates()

0 commit comments

Comments
 (0)