Fix celery task running

This commit is contained in:
2023-02-16 02:38:30 -05:00
parent 21df4e0a77
commit 4ae70ef1f1
3 changed files with 9 additions and 2 deletions

View File

@ -0,0 +1,5 @@
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ('celery_app',)

View File

@ -179,7 +179,9 @@ class AudioScrobblerImportCreateView(
@permission_classes([IsAuthenticated])
@api_view(['GET'])
def lastfm_import(request):
lfm_import = LastFmImport.objects.create(user=request.user)
lfm_import, created = LastFmImport.objects.get_or_create(
user=request.user, processed_on__isnull=True
)
process_lastfm_import.delay(lfm_import.id)

View File

@ -3,7 +3,7 @@ import os
from celery import Celery
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "vrobbler.settings")
app = Celery()
app = Celery("vrobbler")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()