Created
February 13, 2017 19:10
-
-
Save Sovetnikov/369a8d05ba2b6482fa20769bc498f122 to your computer and use it in GitHub Desktop.
How to run celery cam to save memory by not loading all modules of your app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
from copy import copy | |
from celery.events.snapshot import evcam | |
from qiwichain import settings as novtest_settings | |
from qiwichain.celery import app | |
DATABASES = copy(novtest_settings.DATABASES) | |
if 'postgis' in DATABASES['default']['ENGINE']: | |
# Just my case, postgis asks for additional libraries, but it's not needed here | |
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' | |
from django.conf import settings | |
settings.configure( | |
INSTALLED_APPS=( | |
'djcelery', | |
), | |
TIME_ZONE=novtest_settings.TIME_ZONE, | |
DATABASES=DATABASES, | |
CACHES={ | |
'default': { | |
'BACKEND': 'django.core.cache.backends.dummy.DummyCache', | |
} | |
} | |
) | |
if hasattr(time, 'tzset'): | |
# Check that it's not development server on Windows | |
os.environ['TZ'] = settings.TIME_ZONE | |
time.tzset() | |
if __name__ == '__main__': | |
import django | |
django.setup() | |
evcam(camera='djcelery.snapshot.Camera', app=app, loglevel='INFO', freq=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment