Skip to content

Commit

Permalink
Merge pull request #1876 from crypto-a/master
Browse files Browse the repository at this point in the history
Add Management Command for Async Ingredient Synchronization
  • Loading branch information
rolandgeider authored Jan 17, 2025
2 parents 0996969 + 8aa6e66 commit 2e79f27
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Developers
* eyJhb - https://github.com/eyJhb
* Joshua Shelley - https://github.com/navyjosh
* Matt Harrison - https://github.com/Maralai
* Ali Rahbar - https://github.com/crypto-a


Translators
Expand Down
30 changes: 30 additions & 0 deletions wger/nutrition/management/commands/sync-ingredients-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file is part of wger Workout Manager.
#
# wger Workout Manager is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# wger Workout Manager is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License

from django.core.management.base import BaseCommand
from wger.nutrition.tasks import sync_all_ingredients_task


class Command(BaseCommand):

help = "Asynchronously synchronize all ingredients from another wger instance."

def handle(self, *args, **options):

self.stdout.write("Triggering the Celery task to synchronize all ingredients...")

# Trigger the task asynchronously
sync_all_ingredients_task.delay()

self.stdout.write("Synchronization task has been triggered. Check the Celery worker logs for progress.")
3 changes: 2 additions & 1 deletion wger/nutrition/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
randint,
)

from celery import shared_task
# Django
from django.conf import settings
from django.core.management import call_command
Expand Down Expand Up @@ -58,7 +59,7 @@ def fetch_all_ingredient_images_task():
download_ingredient_images(logger.info)


@app.task
@shared_task
def sync_all_ingredients_task():
"""
Fetches the current ingredients from the default wger instance
Expand Down

0 comments on commit 2e79f27

Please sign in to comment.