Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Make sync of OFF daily delta files a celery task

Roland Geiderfdca08d4092c
diff --git a/extras/docker/development/settings.py b/extras/docker/development/settings.py
index 59f37f0e5..a0be29daa 100644
--- a/extras/docker/development/settings.py
+++ b/extras/docker/development/settings.py
@@ -99,6 +99,7 @@ WGER_SETTINGS["SYNC_EXERCISES_CELERY"] = env.bool("SYNC_EXERCISES_CELERY", False
WGER_SETTINGS["SYNC_EXERCISE_IMAGES_CELERY"] = env.bool("SYNC_EXERCISE_IMAGES_CELERY", False)
WGER_SETTINGS["SYNC_EXERCISE_VIDEOS_CELERY"] = env.bool("SYNC_EXERCISE_VIDEOS_CELERY", False)
WGER_SETTINGS["SYNC_INGREDIENTS_CELERY"] = env.bool("SYNC_INGREDIENTS_CELERY", False)
+WGER_SETTINGS["SYNC_OFF_DAILY_DELTA_CELERY"] = env.bool("SYNC_OFF_DAILY_DELTA_CELERY", False)
WGER_SETTINGS["USE_RECAPTCHA"] = env.bool("USE_RECAPTCHA", False)
WGER_SETTINGS["USE_CELERY"] = env.bool("USE_CELERY", False)
diff --git a/wger/nutrition/tasks.py b/wger/nutrition/tasks.py
index b3182d3b4..f476042d6 100644
--- a/wger/nutrition/tasks.py
+++ b/wger/nutrition/tasks.py
@@ -14,10 +14,14 @@
# Standard Library
import logging
-import random
+from random import (
+ choice,
+ randint,
+)
# Django
from django.conf import settings
+from django.core.management import call_command
# Third Party
from celery.schedules import crontab
@@ -62,15 +66,34 @@ def sync_all_ingredients_task():
sync_ingredients(logger.info)
+def sync_off_daily_delta():
+ """
+ Fetches OFF's daily delta product updates
+ """
+ call_command('import-off-products', '--delta-updates')
+
+
@app.on_after_finalize.connect
def setup_periodic_tasks(sender, **kwargs):
if settings.WGER_SETTINGS['SYNC_INGREDIENTS_CELERY']:
sender.add_periodic_task(
crontab(
- hour=str(random.randint(0, 23)),
- minute=str(random.randint(0, 59)),
- day_of_month=f'{random.randint(1, 12)},{random.randint(18, 28)}',
+ hour=str(randint(0, 23)),
+ minute=str(randint(0, 59)),
+ day_of_month=str(randint(1, 28)),
+ month_of_year=choice(['1, 4, 7, 10', '2, 5, 8, 11', '3, 6, 9, 12']),
),
sync_all_ingredients_task.s(),
- name='Sync exercises',
+ name='Sync ingredients',
+ )
+
+ if settings.WGER_SETTINGS['SYNC_OFF_DAILY_DELTA_CELERY']:
+ sender.add_periodic_task(
+ crontab(
+ hour=str(randint(0, 23)),
+ minute=str(randint(0, 59)),
+ ),
+ sync_off_daily_delta.s(),
+ name='Sync OFF daily delta updates',
)
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 2cf80e560..6221c05bb 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -171,8 +171,7 @@ TEMPLATES = [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
- 'debug':
- False
+ 'debug': False
},
},
]
@@ -257,7 +256,7 @@ AVAILABLE_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'
@@ -498,7 +497,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
@@ -537,6 +536,7 @@ WGER_SETTINGS = {
'SYNC_EXERCISE_IMAGES_CELERY': False,
'SYNC_EXERCISE_VIDEOS_CELERY': False,
'SYNC_INGREDIENTS_CELERY': False,
+ 'SYNC_OFF_DAILY_DELTA_CELERY': False,
'TWITTER': False,
'MASTODON': 'https://fosstodon.org/@wger',
'USE_CELERY': False,