|
4 | 4 |
|
5 | 5 | import dj_database_url |
6 | 6 | from celery.schedules import crontab |
| 7 | +from platformshconfig import Config |
7 | 8 |
|
| 9 | +config = Config() |
8 | 10 |
|
9 | 11 | ALLOWED_HOSTS = [] |
10 | 12 |
|
|
28 | 30 |
|
29 | 31 | BASE_DIR = pathlib.Path(__file__).parent.parent.parent |
30 | 32 |
|
31 | | -CACHES = { |
32 | | - 'default': { |
33 | | - 'BACKEND': 'django_redis.cache.RedisCache', |
34 | | - 'LOCATION': os.getenv('REDIS_URL', 'redis://'), |
35 | | - 'OPTIONS': { |
36 | | - 'CLIENT_CLASS': 'django_redis.client.DefaultClient', |
| 33 | + |
| 34 | +if config.is_valid_platform(): |
| 35 | + redis_credentials = config.credentials('redis') |
| 36 | + |
| 37 | + CACHES = { |
| 38 | + 'default': { |
| 39 | + 'BACKEND': 'django_redis.cache.RedisCache', |
| 40 | + 'LOCATION': f"redis://{redis_credentials['host']}:{redis_credentials['port']}", |
| 41 | + 'OPTIONS': { |
| 42 | + 'CLIENT_CLASS': 'django_redis.client.DefaultClient', |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +else: |
| 47 | + CACHES = { |
| 48 | + 'default': { |
| 49 | + 'BACKEND': 'django_redis.cache.RedisCache', |
| 50 | + 'LOCATION': os.getenv('REDIS_URL', 'redis://'), |
| 51 | + 'OPTIONS': { |
| 52 | + 'CLIENT_CLASS': 'django_redis.client.DefaultClient', |
| 53 | + } |
37 | 54 | } |
38 | 55 | } |
39 | | -} |
40 | 56 |
|
41 | 57 | CSRF_USE_SESSIONS = True |
42 | 58 |
|
43 | | -DATABASES = { |
44 | | - 'default': dj_database_url.config(default='postgres://postgres:@127.0.0.1:5432/postgres'), # noqa |
45 | | -} |
| 59 | +if config.is_valid_platform(): |
| 60 | + DATABASES = { |
| 61 | + 'default': dj_database_url.config(default=config.formatted_credentials('postgresql', 'postgresql_dsn')), # noqa |
| 62 | + } |
| 63 | +else: |
| 64 | + DATABASES = { |
| 65 | + 'default': dj_database_url.config(default='postgres://postgres:@127.0.0.1:5432/postgres'), # noqa |
| 66 | + } |
46 | 67 |
|
47 | 68 | DEBUG = False |
48 | 69 |
|
|
191 | 212 | # CELERY |
192 | 213 | ################# |
193 | 214 |
|
194 | | -BROKER_URL = os.getenv('REDIS_URL', 'redis://') |
195 | | - |
196 | | -CELERY_RESULT_BACKEND = os.getenv('REDIS_URL', BROKER_URL) |
| 215 | +if config.is_valid_platform(): |
| 216 | + redis_credentials = config.credentials('redis') |
| 217 | + BROKER_URL = f"redis://{redis_credentials['host']}:{redis_credentials['port']}" |
| 218 | + CELERY_RESULT_BACKEND = f"redis://{redis_credentials['host']}:{redis_credentials['port']}" |
| 219 | +else: |
| 220 | + BROKER_URL = os.getenv('REDIS_URL', 'redis://') |
| 221 | + CELERY_RESULT_BACKEND = os.getenv('REDIS_URL', BROKER_URL) |
197 | 222 |
|
198 | 223 | CELERYBEAT_SCHEDULE = { |
199 | 224 | 'capture-snapshot-of-slack-users': { |
|
0 commit comments