broker pool limit
[oweals/karmaworld.git] / karmaworld / settings / vmdev.py
1 #!/usr/bin/env python
2 # -*- coding:utf8 -*-
3 # Copyright (C) 2012  FinalsClub Foundation
4 """ Production settings and globals. """
5 from os import environ
6 from datetime import timedelta
7 from S3 import CallingFormat
8
9 from common import *
10
11 from karmaworld.secret.static_s3 import *
12
13 try:
14     # Include email is settings are there
15     from karmaworld.secret.email import SMTP_HOST
16     from karmaworld.secret.email import SMTP_USERNAME
17     from karmaworld.secret.email import SMTP_PASSWORD
18     EMAIL = True
19 except:
20     EMAIL = False
21
22 ########## EMAIL CONFIGURATION
23 if EMAIL:
24     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend
25     EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
26     
27     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host
28     EMAIL_HOST = environ.get('EMAIL_HOST', SMTP_HOST)
29     
30     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password
31     EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', SMTP_PASSWORD)
32     
33     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user
34     EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', SMTP_USERNAME)
35     
36     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port
37     EMAIL_PORT = environ.get('EMAIL_PORT', 587)
38     
39     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix
40     EMAIL_SUBJECT_PREFIX = 'KarmaNotes '
41     
42     # See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls
43     EMAIL_USE_TLS = True
44     
45     DEFAULT_FROM_EMAIL = 'info@karmanotes.org'
46     
47     # See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email
48     SERVER_EMAIL = EMAIL_HOST_USER
49 ########## END EMAIL CONFIGURATION
50
51
52 ########## DATABASE CONFIGURATION
53 DATABASES = {
54     'default': {
55     'ENGINE': 'django.db.backends.postgresql_psycopg2',
56     'NAME': PROD_DB_NAME,
57     'USER': PROD_DB_USERNAME,
58     'PASSWORD': PROD_DB_PASSWORD,
59     'HOST': '',
60     'PORT': '',                      # Set to empty string for default. Not used with sqlite3.
61     }
62 }
63 ########## END DATABASE CONFIGURATION
64
65
66 ########## CACHE CONFIGURATION
67 # See: https://docs.djangoproject.com/en/dev/ref/settings/#caches
68 CACHES = {
69     'default': {
70         'BACKEND': 'django.core.cache.backends.memcached.PyLibMCCache',
71     }
72 }
73 ########## END CACHE CONFIGURATION
74
75
76 ########## CELERY CONFIGURATION
77 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-transport
78 BROKER_TRANSPORT = 'amqplib'
79
80 # Set this number to the amount of allowed concurrent connections on your AMQP
81 # provider, divided by the amount of active workers you have.
82 #
83 # For example, if you have the 'Little Lemur' CloudAMQP plan (their free tier),
84 # they allow 3 concurrent connections. So if you run a single worker, you'd
85 # want this number to be 3. If you had 3 workers running, you'd lower this
86 # number to 1, since 3 workers each maintaining one open connection = 3
87 # connections total.
88 #
89 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-pool-limit
90 BROKER_POOL_LIMIT = 3
91
92 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-connection-max-retries
93 BROKER_CONNECTION_MAX_RETRIES = 0
94
95 # See: http://docs.celeryproject.org/en/latest/configuration.html#broker-url
96 BROKER_URL = environ.get('RABBITMQ_URL') or environ.get('CLOUDAMQP_URL')
97
98 # See: http://docs.celeryproject.org/en/latest/configuration.html#celery-result-backend
99 CELERY_RESULT_BACKEND = 'amqp'
100
101 # Periodic tasks
102 CELERYBEAT_SCHEDULE = {
103     'tweet-about-notes': {
104         'task': 'tweet_note',
105         'schedule': timedelta(minutes=60),
106     },
107 }
108
109 CELERY_TIMEZONE = 'UTC'
110
111 ########## END CELERY CONFIGURATION
112
113
114 ########## STORAGE CONFIGURATION
115 # See: http://django-storages.readthedocs.org/en/latest/index.html
116 INSTALLED_APPS += (
117     'storages',
118     'gunicorn',
119 )
120
121 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
122 STATICFILES_STORAGE = DEFAULT_FILE_STORAGE
123
124 # See: http://django-storages.readthedocs.org/en/latest/backends/amazon-S3.html#settings
125 AWS_CALLING_FORMAT = CallingFormat.SUBDOMAIN
126
127 # Put static files in the folder 'static' in our S3 bucket.
128 # This is so they have the same path as they do when served
129 # locally for development.
130 AWS_LOCATION = 'static'
131
132 # AWS cache settings, don't change unless you know what you're doing:
133 AWS_EXPIREY = 60 * 60 * 24 * 7
134 AWS_HEADERS = {
135     'Cache-Control': 'max-age=%d, s-maxage=%d, must-revalidate' % (AWS_EXPIREY,
136         AWS_EXPIREY)
137 }
138
139 # See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url
140 STATIC_URL = CLOUDFRONT_URL + AWS_LOCATION + '/'
141 ########## END STORAGE CONFIGURATION
142
143
144 ########## SSL FORWARDING CONFIGURATION
145 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
146 ########## END SSL FORWARDING CONFIGURATION
147
148
149 ########## COMPRESSION CONFIGURATION
150 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_OFFLINE
151 COMPRESS_OFFLINE = True
152
153 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_STORAGE
154 COMPRESS_STORAGE = DEFAULT_FILE_STORAGE
155
156 # Make sure that django-compressor serves from CloudFront
157 AWS_S3_CUSTOM_DOMAIN = CLOUDFRONT_DOMAIN
158
159 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_CSS_FILTERS
160 COMPRESS_CSS_FILTERS += [
161     'compressor.filters.datauri.CssDataUriFilter',
162     'compressor.filters.cssmin.CSSMinFilter',
163 ]
164 COMPRESS_DATA_URI_MAX_SIZE = 5120
165
166 # See: http://django_compressor.readthedocs.org/en/latest/settings/#django.conf.settings.COMPRESS_JS_FILTERS
167 COMPRESS_JS_FILTERS += [
168     'compressor.filters.closure.ClosureCompilerFilter',
169 ]
170 COMPRESS_CLOSURE_COMPILER_BINARY = 'java -jar /usr/bin/compiler.jar'
171
172 # Links generated by compress are valid for about ten years
173 AWS_QUERYSTRING_EXPIRE = 60 * 60 * 24 * 365 * 10
174 ########## END COMPRESSION CONFIGURATION
175
176
177 ########## SECRET CONFIGURATION
178 # See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
179 SECRET_KEY = environ.get('SECRET_KEY', SECRET_KEY)
180 ########## END SECRET CONFIGURATION
181
182 ########## DEBUG CONFIGURATION
183 # See: https://docs.djangoproject.com/en/dev/ref/settings/#debug
184 DEBUG = True
185
186 # See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug
187 TEMPLATE_DEBUG = DEBUG
188 ########## END DEBUG CONFIGURATION
189
190 ########## TESTING CONFIGURATION
191 # Use django-nose to test our app, see https://github.com/jbalogh/django-nose
192 TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
193 ########## END TESTING CONFIGURATION
194
195 ########## TOOLBAR CONFIGURATION
196 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
197 INSTALLED_APPS += (
198     'debug_toolbar',
199     'django_extensions',
200     'django_nose',
201 )
202
203 DEBUG_TOOLBAR_PANELS = (
204     'debug_toolbar.panels.versions.VersionsPanel',
205     'debug_toolbar.panels.timer.TimerPanel',
206     'debug_toolbar.panels.settings.SettingsPanel',
207     'debug_toolbar.panels.headers.HeadersPanel',
208     'debug_toolbar.panels.request.RequestPanel',
209     'debug_toolbar.panels.sql.SQLPanel',
210     'debug_toolbar.panels.staticfiles.StaticFilesPanel',
211     'debug_toolbar.panels.templates.TemplatesPanel',
212     'debug_toolbar.panels.cache.CachePanel',
213     'debug_toolbar.panels.signals.SignalsPanel',
214     'debug_toolbar.panels.logging.LoggingPanel',
215 )
216
217 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
218 INTERNAL_IPS = ('127.0.0.1',)
219
220 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
221 MIDDLEWARE_CLASSES += (
222     'debug_toolbar.middleware.DebugToolbarMiddleware',
223 )
224 ########## END TOOLBAR CONFIGURATION
225
226 ########## PROFILING CONFIGURATION
227 MIDDLEWARE_CLASSES += (
228     'karmaworld.apps.courses.middleware.ProfileMiddleware',
229 )
230 ########## END PROFILING CONFIGURATION
231
232 ########## STATIC CONFIGURATION
233 STATIC_URL = CLOUDFRONT_URL
234 ########## END STATIC CONFIGURATION