Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add configuration option to sync the exercises with celery

Roland Geider7aab43d3b90a
diff --git a/extras/docker/development/settings.py b/extras/docker/development/settings.py
index b5507bc48..733bedbed 100644
--- a/extras/docker/development/settings.py
+++ b/extras/docker/development/settings.py
@@ -45,7 +45,6 @@ TIME_ZONE = env.str("TIME_ZONE", 'Europe/Berlin')
# Make this unique, and don't share it with anybody.
SECRET_KEY = env.str("SECRET_KEY", 'wger-docker-supersecret-key-1234567890!@#$%^&*(-_)')
-
# Your reCaptcha keys
RECAPTCHA_PUBLIC_KEY = env.str('RECAPTCHA_PUBLIC_KEY', '')
RECAPTCHA_PRIVATE_KEY = env.str('RECAPTCHA_PRIVATE_KEY', '')
@@ -84,7 +83,6 @@ if os.environ.get("ENABLE_EMAIL"):
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", True)
EMAIL_TIMEOUT = 60
-
# Sender address used for sent emails
DEFAULT_FROM_EMAIL = env.str("FROM_EMAIL", "wger Workout Manager <[email protected]>")
WGER_SETTINGS['EMAIL_FROM'] = DEFAULT_FROM_EMAIL
@@ -99,7 +97,7 @@ WGER_SETTINGS["MIN_ACCOUNT_AGE_TO_TRUST"] = env.int("MIN_ACCOUNT_AGE_TO_TRUST",
WGER_SETTINGS["EXERCISE_CACHE_TTL"] = env.int("EXERCISE_CACHE_TTL", 3600)
WGER_SETTINGS["USE_CELERY"] = env.bool("USE_CELERY", False)
WGER_SETTINGS["DOWNLOAD_INGREDIENT_IMAGES"] = env.str("DOWNLOAD_INGREDIENT_IMAGES", "WGER")
-
+WGER_SETTINGS["SYNC_EXERCISES_CELERY"] = env.bool("SYNC_EXERCISES_CELERY", False)
# Cache
if os.environ.get("DJANGO_CACHE_BACKEND"):
diff --git a/wger/exercises/tasks.py b/wger/exercises/tasks.py
index 5e12d5e7e..4d4268947 100644
--- a/wger/exercises/tasks.py
+++ b/wger/exercises/tasks.py
@@ -14,6 +14,10 @@
# Standard Library
import logging
+import random
+
+# Django
+from django.conf import settings
# Third Party
from celery.schedules import crontab
@@ -29,7 +33,6 @@ from wger.exercises.sync import (
sync_muscles,
)
-
logger = logging.getLogger(__name__)
@@ -49,8 +52,13 @@ def sync_exercises_task():
@app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
- sender.add_periodic_task(
- crontab(hour=10, minute=30, day_of_week='monday'),
- sync_exercises_task.s(),
- name='Regularly sync exercises',
- )
+ if settings.WGER_SETTINGS['SYNC_EXERCISES_CELERY']:
+ sender.add_periodic_task(
+ crontab(
+ hour=random.randint(0, 23),
+ minute=random.randint(0, 59),
+ day_of_week=random.randint(0, 6),
+ ),
+ sync_exercises_task.s(),
+ name='Regularly sync exercises',
+ )
diff --git a/wger/nutrition/tests/test_tasks.py b/wger/nutrition/tests/test_tasks.py
index 90c91e30a..812bc5be5 100644
--- a/wger/nutrition/tests/test_tasks.py
+++ b/wger/nutrition/tests/test_tasks.py
@@ -45,7 +45,7 @@ class MockOffResponse:
return {
"product": {
'image_front_url':
- 'https://images.openfoodfacts.org/images/products/00975957/front_en.5.400.jpg',
+ 'https://images.openfoodfacts.org/images/products/00975957/front_en.5.400.jpg',
'images': {
'front_en': {
'imgid': '12345',
@@ -69,7 +69,7 @@ class MockWgerApiResponse:
return {
"product": {
'image_front_url':
- 'https://images.openfoodfacts.org/images/products/00975957/front_en.5.400.jpg',
+ 'https://images.openfoodfacts.org/images/products/00975957/front_en.5.400.jpg',
'images': {
'front_en': {
'imgid': '12345',
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 6372d9028..5ac28f51b 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -24,7 +24,6 @@ from datetime import timedelta
# wger
from wger.utils.constants import DOWNLOAD_INGREDIENT_WGER
-
"""
This file contains the global settings that don't usually need to be changed.
For a full list of options, visit:
@@ -170,7 +169,7 @@ TEMPLATES = [
'django.template.loaders.app_directories.Loader',
],
'debug':
- False
+ False
},
},
]
@@ -240,7 +239,7 @@ LANGUAGES = (
LANGUAGE_CODE = 'en'
# All translation files are in one place
-LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'), )
+LOCALE_PATHS = (os.path.join(SITE_ROOT, 'locale'),)
# Primary keys are AutoFields
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
@@ -412,15 +411,15 @@ COMPRESS_ROOT = STATIC_ROOT
# Django Rest Framework
#
REST_FRAMEWORK = {
- 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission', ),
+ 'DEFAULT_PERMISSION_CLASSES': ('wger.utils.permissions.WgerPermission',),
'DEFAULT_PAGINATION_CLASS':
- 'rest_framework.pagination.LimitOffsetPagination',
+ 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE':
- 20,
+ 20,
'PAGINATE_BY_PARAM':
- 'limit', # Allow client to override, using `?limit=xxx`.
+ 'limit', # Allow client to override, using `?limit=xxx`.
'TEST_REQUEST_DEFAULT_FORMAT':
- 'json',
+ 'json',
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
@@ -456,7 +455,7 @@ CORS_URLS_REGEX = r'^/api/.*$'
#
# Ignore these URLs if they cause 404
#
-IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'), )
+IGNORABLE_404_URLS = (re.compile(r'^/favicon\.ico$'),)
#
# Password rules
@@ -495,6 +494,7 @@ WGER_SETTINGS = {
'USE_CELERY': False,
'USE_RECAPTCHA': False,
'WGER_INSTANCE': 'https://wger.de',
+ 'SYNC_EXERCISES_CELERY': False
}