Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Management Command for Async Ingredient Synchronization #1876

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading