Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #162 from pmclanahan/read-only-mode
Browse files Browse the repository at this point in the history
Add a read-only-mode for use with replicant DB
  • Loading branch information
pmac committed Jan 19, 2016
2 parents 0657489 + e67ea30 commit 55994e3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
17 changes: 9 additions & 8 deletions news/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
"""
statsd.incr(self.name + '.failure')
log.error("Task failed: %s" % self.name, exc_info=einfo.exc_info)
FailedTask.objects.create(
task_id=task_id,
name=self.name,
args=args,
kwargs=kwargs,
exc=repr(exc),
einfo=str(einfo), # str() gives more info than repr() on celery.datastructures.ExceptionInfo
)
if settings.STORE_TASK_FAILURES:
FailedTask.objects.create(
task_id=task_id,
name=self.name,
args=args,
kwargs=kwargs,
exc=repr(exc),
einfo=str(einfo), # str() gives more info than repr() on celery.datastructures.ExceptionInfo
)

def on_retry(self, exc, task_id, args, kwargs, einfo):
"""Retry handler.
Expand Down
14 changes: 10 additions & 4 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def path(*args):
# avoids a warning from django
TEST_RUNNER = 'django.test.runner.DiscoverRunner'

READ_ONLY_MODE = config('READ_ONLY_MODE', False, cast=bool)

REDIS_URL = config('REDIS_URL', None)
if REDIS_URL:
REDIS_URL = REDIS_URL.rstrip('/0')
Expand Down Expand Up @@ -70,8 +72,10 @@ def path(*args):
ALLOWED_HOSTS = config('ALLOWED_HOSTS',
default='.allizom.org, basket.mozilla.com, basket.mozilla.org',
cast=Csv())
SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', True, cast=bool)
CSRF_COOKIE_SECURE = config('CSRF_COOKIE_SECURE', True, cast=bool)
SESSION_COOKIE_SECURE = config('SESSION_COOKIE_SECURE', not DEBUG, cast=bool)
CSRF_COOKIE_SECURE = config('CSRF_COOKIE_SECURE', not DEBUG, cast=bool)
DISABLE_ADMIN = config('DISABLE_ADMIN', READ_ONLY_MODE, cast=bool)
STORE_TASK_FAILURES = config('STORE_TASK_FAILURES', not READ_ONLY_MODE, cast=bool)

TIME_ZONE = 'America/Los_Angeles'
USE_TZ = True
Expand Down Expand Up @@ -103,7 +107,6 @@ def path(*args):
)

MIDDLEWARE_CLASSES = (
'sslifyadmin.middleware.SSLifyAdminMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand All @@ -115,6 +118,9 @@ def path(*args):
'ratelimit.middleware.RatelimitMiddleware',
)

if not DISABLE_ADMIN:
MIDDLEWARE_CLASSES = ('sslifyadmin.middleware.SSLifyAdminMiddleware',) + MIDDLEWARE_CLASSES

ROOT_URLCONF = 'urls'

TEMPLATE_DIRS = (
Expand All @@ -136,7 +142,7 @@ def path(*args):
'django.contrib.staticfiles',
)

SSLIFY_ADMIN_DISABLE = config('SSLIFY_ADMIN_DISABLE', DEBUG)
SSLIFY_ADMIN_DISABLE = config('SSLIFY_ADMIN_DISABLE', DEBUG, cast=bool)
if not SSLIFY_ADMIN_DISABLE:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Expand Down
22 changes: 8 additions & 14 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
from django.conf import settings
from django.conf.urls import patterns, include
from django.conf.urls import include, url
from django.contrib import admin


admin.autodiscover()


urlpatterns = patterns('',
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^news/', include('news.urls'))
urlpatterns = (
url(r'^news/', include('news.urls')),
)

if settings.DEBUG:
# Remove leading and trailing slashes so the regex matches.
media_url = settings.MEDIA_URL.lstrip('/').rstrip('/')
urlpatterns += patterns('',
(r'^%s/(?P<path>.*)$' % media_url, 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
if not settings.DISABLE_ADMIN:
admin.autodiscover()
urlpatterns += (
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)

0 comments on commit 55994e3

Please sign in to comment.