Skip to content

Commit c56bd85

Browse files
authored
Merge pull request alphagov#240 from alphagov/clear-template-cache
Add fabric task to clear cached templates
2 parents b599f60 + 6fbd409 commit c56bd85

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)