From f1a329c946dc21c61fbb5fffada2f0ae20e251be Mon Sep 17 00:00:00 2001 From: afabiani Date: Tue, 22 Oct 2019 14:57:23 +0200 Subject: [PATCH 1/2] [Fixes #5096] Disabling geonode.monitoring causes model exceptions on views --- geonode/settings.py | 55 ++++++++++++++++++++++++--------------------- pavement.py | 19 ++++++++++------ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/geonode/settings.py b/geonode/settings.py index 60d5ed757a2..49de6bfb4bf 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -314,6 +314,7 @@ 'geonode.upload', 'geonode.tasks', 'geonode.messaging', + 'geonode.monitoring', ) GEONODE_CONTRIB_APPS = ( @@ -355,7 +356,6 @@ 'mptt', 'storages', 'floppyforms', - 'django_celery_beat', # Theme 'django_forms_bootstrap', @@ -382,7 +382,12 @@ # GeoNode 'geonode', -) + GEONODE_APPS +) + +if 'postgresql' in DATABASE_URL or 'postgis' in DATABASE_URL: + INSTALLED_APPS += ('django_celery_beat',) + +INSTALLED_APPS += GEONODE_APPS REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, @@ -1207,29 +1212,29 @@ MIDDLEWARE_CLASSES += \ ('geonode.monitoring.middleware.MonitoringMiddleware',) -# skip certain paths to not to mud stats too much -MONITORING_SKIP_PATHS = ('/api/o/', - '/monitoring/', - '/admin', - '/lang.js', - '/jsi18n', - STATIC_URL, - MEDIA_URL, - re.compile('^/[a-z]{2}/admin/'), - ) - -# configure aggregation of past data to control data resolution -# list of data age, aggregation, in reverse order -# for current data, 1 minute resolution -# for data older than 1 day, 1-hour resolution -# for data older than 2 weeks, 1 day resolution -MONITORING_DATA_AGGREGATION = ( - (timedelta(seconds=0), timedelta(minutes=1),), - (timedelta(days=1), timedelta(minutes=60),), - (timedelta(days=14), timedelta(days=1),), -) -USER_ANALYTICS_ENABLED = ast.literal_eval(os.getenv('USER_ANALYTICS_ENABLED', 'False')) -GEOIP_PATH = os.getenv('GEOIP_PATH', os.path.join(PROJECT_ROOT, 'GeoIPCities.dat')) + # skip certain paths to not to mud stats too much + MONITORING_SKIP_PATHS = ('/api/o/', + '/monitoring/', + '/admin', + '/lang.js', + '/jsi18n', + STATIC_URL, + MEDIA_URL, + re.compile('^/[a-z]{2}/admin/'), + ) + + # configure aggregation of past data to control data resolution + # list of data age, aggregation, in reverse order + # for current data, 1 minute resolution + # for data older than 1 day, 1-hour resolution + # for data older than 2 weeks, 1 day resolution + MONITORING_DATA_AGGREGATION = ( + (timedelta(seconds=0), timedelta(minutes=1),), + (timedelta(days=1), timedelta(minutes=60),), + (timedelta(days=14), timedelta(days=1),), + ) + USER_ANALYTICS_ENABLED = ast.literal_eval(os.getenv('USER_ANALYTICS_ENABLED', 'False')) + GEOIP_PATH = os.getenv('GEOIP_PATH', os.path.join(PROJECT_ROOT, 'GeoIPCities.dat')) # -- END Settings for MONITORING plugin CACHES = { diff --git a/pavement.py b/pavement.py index 30cf36cf36f..ace1da3b491 100644 --- a/pavement.py +++ b/pavement.py @@ -415,7 +415,8 @@ def sync(options): sh("%s python -W ignore manage.py loaddata sample_admin.json" % settings) sh("%s python -W ignore manage.py loaddata geonode/base/fixtures/default_oauth_apps.json" % settings) sh("%s python -W ignore manage.py loaddata geonode/base/fixtures/initial_data.json" % settings) - sh("%s python -W ignore manage.py loaddata geonode/base/fixtures/django_celery_beat.json" % settings) + if 'django_celery_beat' in INSTALLED_APPS: + sh("%s python -W ignore manage.py loaddata geonode/base/fixtures/django_celery_beat.json" % settings) sh("%s python -W ignore manage.py set_all_layers_alternate" % settings) @@ -617,12 +618,16 @@ def start_django(options): # "notifications.events", # "geonode.layer.viewer" ] - sh('%s celery -A geonode.celery_app:app worker -Q %s -B -E -l INFO %s %s' % ( - settings, - ",".join(celery_queues), - '--scheduler django_celery_beat.schedulers:DatabaseScheduler', - foreground - )) + if 'django_celery_beat' not in INSTALLED_APPS: + sh('%s celery -A geonode.celery_app:app worker -Q %s -B -E -l INFO %s' % + (settings, ",".join(celery_queues), foreground)) + else: + sh('%s celery -A geonode.celery_app:app worker -Q %s -B -E -l INFO %s %s' % ( + settings, + ",".join(celery_queues), + '--scheduler django_celery_beat.schedulers:DatabaseScheduler', + foreground + )) if ASYNC_SIGNALS: sh('%s python -W ignore manage.py runmessaging %s' % (settings, foreground)) From b2709d7128c7cc4867a4788ea7e5f0fdd22b83e3 Mon Sep 17 00:00:00 2001 From: Alessio Fabiani Date: Tue, 22 Oct 2019 15:07:47 +0200 Subject: [PATCH 2/2] Update settings.py --- geonode/settings.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geonode/settings.py b/geonode/settings.py index 49de6bfb4bf..6972bbf87d0 100644 --- a/geonode/settings.py +++ b/geonode/settings.py @@ -1233,8 +1233,9 @@ (timedelta(days=1), timedelta(minutes=60),), (timedelta(days=14), timedelta(days=1),), ) - USER_ANALYTICS_ENABLED = ast.literal_eval(os.getenv('USER_ANALYTICS_ENABLED', 'False')) - GEOIP_PATH = os.getenv('GEOIP_PATH', os.path.join(PROJECT_ROOT, 'GeoIPCities.dat')) + +USER_ANALYTICS_ENABLED = ast.literal_eval(os.getenv('USER_ANALYTICS_ENABLED', 'False')) +GEOIP_PATH = os.getenv('GEOIP_PATH', os.path.join(PROJECT_ROOT, 'GeoIPCities.dat')) # -- END Settings for MONITORING plugin CACHES = {