Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/celery 4976-In Review #5110

Merged
merged 6 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/app/redis_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.conf import settings
from redis import Redis


class RedisService:
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super().__new__(cls)
return cls.instance

def __init__(self):
redis_url = settings.CELERY_BROKER_URL
self.redis = Redis.from_url(redis_url)
43 changes: 28 additions & 15 deletions app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from easy_thumbnails.conf import Settings as easy_thumbnails_defaults

import warnings

warnings.filterwarnings("ignore", category=UserWarning, module='psycopg2')

root = environ.Path(__file__) - 2 # Set the base directory to two levels.
Expand Down Expand Up @@ -64,6 +65,8 @@
INSTALLED_APPS = [
'corsheaders',
'django.contrib.admin',
'taskapp.celery.CeleryConfig',
'django_celery_beat',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
Expand Down Expand Up @@ -180,8 +183,8 @@
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend', ),
'DEFAULT_THROTTLE_CLASSES': ('rest_framework.throttling.AnonRateThrottle', ),
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
'DEFAULT_THROTTLE_CLASSES': ('rest_framework.throttling.AnonRateThrottle',),
'DEFAULT_THROTTLE_RATES': {
'anon': '1000/day',
},
Expand All @@ -201,7 +204,7 @@
USE_TZ = env.bool('USE_TZ', default=True)
TIME_ZONE = env.str('TIME_ZONE', default='UTC')

LOCALE_PATHS = ('locale', )
LOCALE_PATHS = ('locale',)

LANGUAGES = [
('en', gettext_noop('English')),
Expand Down Expand Up @@ -254,7 +257,6 @@
if RELEASE:
RAVEN_CONFIG['release'] = RELEASE


LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand Down Expand Up @@ -313,13 +315,13 @@
'format': '%(hostname)s %(name)-12s [%(levelname)-8s] %(message)s',
}
LOGGING['handlers']['watchtower'] = {
'level': AWS_LOG_LEVEL,
'class': 'watchtower.django.DjangoCloudWatchLogHandler',
'boto3_session': boto3_session,
'log_group': AWS_LOG_GROUP,
'stream_name': AWS_LOG_STREAM,
'filters': ['host_filter'],
'formatter': 'cloudwatch',
'level': AWS_LOG_LEVEL,
'class': 'watchtower.django.DjangoCloudWatchLogHandler',
'boto3_session': boto3_session,
'log_group': AWS_LOG_GROUP,
'stream_name': AWS_LOG_STREAM,
'filters': ['host_filter'],
'formatter': 'cloudwatch',
}
LOGGING['loggers']['django.db.backends']['level'] = AWS_LOG_LEVEL

Expand All @@ -345,7 +347,7 @@

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/
STATICFILES_DIRS = env.tuple('STATICFILES_DIRS', default=('assets/', ))
STATICFILES_DIRS = env.tuple('STATICFILES_DIRS', default=('assets/',))
STATIC_ROOT = root('static')
STATICFILES_LOCATION = env.str('STATICFILES_LOCATION', default='static')
MEDIAFILES_LOCATION = env.str('MEDIAFILES_LOCATION', default='media')
Expand All @@ -370,7 +372,7 @@
COMPRESS_ROOT = STATIC_ROOT
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)

THUMBNAIL_PROCESSORS = easy_thumbnails_defaults.THUMBNAIL_PROCESSORS + ('app.thumbnail_processors.circular_processor', )
THUMBNAIL_PROCESSORS = easy_thumbnails_defaults.THUMBNAIL_PROCESSORS + ('app.thumbnail_processors.circular_processor',)

THUMBNAIL_ALIASES = {
'': {
Expand All @@ -388,6 +390,7 @@

CACHEOPS_DEGRADE_ON_FAILURE = env.bool('CACHEOPS_DEGRADE_ON_FAILURE', default=True)
CACHEOPS_REDIS = env.str('CACHEOPS_REDIS', default='redis://redis:6379/0')

CACHEOPS_DEFAULTS = {
'timeout': 60 * 60
}
Expand Down Expand Up @@ -451,6 +454,16 @@
},
}


# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-broker_url
CELERY_BROKER_URL = env('CELERY_BROKER_URL', default=CACHEOPS_REDIS)
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-accept_content
CELERY_ACCEPT_CONTENT = ['json']
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-task_serializer
CELERY_TASK_SERIALIZER = 'json'
# http://docs.celeryproject.org/en/latest/userguide/configuration.html#std:setting-result_serializer
CELERY_RESULT_SERIALIZER = 'json'

DJANGO_REDIS_IGNORE_EXCEPTIONS = env.bool('REDIS_IGNORE_EXCEPTIONS', default=True)
DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = env.bool('REDIS_LOG_IGNORED_EXCEPTIONS', default=True)
COLLECTFAST_CACHE = env('COLLECTFAST_CACHE', default='collectfast')
Expand Down Expand Up @@ -642,8 +655,8 @@
AWS_S3_OBJECT_PARAMETERS = {'CacheControl': f'max-age={AWS_S3_CACHE_MAX_AGE}', }

CORS_ORIGIN_ALLOW_ALL = False
CORS_ORIGIN_WHITELIST = ('sumo.com', 'load.sumo.com', 'googleads.g.doubleclick.net', 'gitcoin.co', 'github.com', )
CORS_ORIGIN_WHITELIST = CORS_ORIGIN_WHITELIST + (AWS_S3_CUSTOM_DOMAIN, MEDIA_CUSTOM_DOMAIN, )
CORS_ORIGIN_WHITELIST = ('sumo.com', 'load.sumo.com', 'googleads.g.doubleclick.net', 'gitcoin.co', 'github.com',)
CORS_ORIGIN_WHITELIST = CORS_ORIGIN_WHITELIST + (AWS_S3_CUSTOM_DOMAIN, MEDIA_CUSTOM_DOMAIN,)

S3_REPORT_BUCKET = env('S3_REPORT_BUCKET', default='') # TODO
S3_REPORT_PREFIX = env('S3_REPORT_PREFIX', default='') # TODO
Expand Down
Loading