Przeglądaj źródła

Fix celery task running

Colin Powell 2 lat temu
rodzic
commit
4ae70ef1f1
3 zmienionych plików z 9 dodań i 2 usunięć
  1. 5 0
      vrobbler/__init__.py
  2. 3 1
      vrobbler/apps/scrobbles/views.py
  3. 1 1
      vrobbler/celery.py

+ 5 - 0
vrobbler/__init__.py

@@ -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',)

+ 3 - 1
vrobbler/apps/scrobbles/views.py

@@ -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)
 

+ 1 - 1
vrobbler/celery.py

@@ -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()