diff --git a/api/views.py b/api/views.py index 429e7d9..832dbca 100755 --- a/api/views.py +++ b/api/views.py @@ -17,8 +17,9 @@ from rest_framework.status import HTTP_202_ACCEPTED, HTTP_401_UNAUTHORIZED, HTTP HTTP_200_OK, HTTP_204_NO_CONTENT from api import serializers +from core.utils.cdn import upload_to_azure from dss import settings -from core.tasks import create_waveform_task +from core.tasks import create_waveform_task, archive_mix_task from spa.models.genre import Genre from spa.models.activity import ActivityPlay from spa.models.mix import Mix @@ -63,6 +64,7 @@ class CommentViewSet(viewsets.ModelViewSet): except Exception, ex: pass + class UserProfileViewSet(viewsets.ModelViewSet): queryset = UserProfile.objects.annotate(mix_count=Count('mixes')).order_by('-mix_count') serializer_class = serializers.UserProfileSerializer @@ -168,8 +170,15 @@ class PartialMixUploadView(views.APIView): response = 'File creation in progress' try: - create_waveform_task.delay(in_file=os.path.join(file_storage.base_location, cache_file), uid=uid) - except Exception, ex: + input_file = in_file = os.path.join(file_storage.base_location, cache_file) + + # Chain the waveform & archive tasks together + # Probably not the best place for them but will do for now + # First argument to archive_mix_task is not specified as it is piped from create_waveform_task + (create_waveform_task.s(input_file, uid) | + archive_mix_task.s(filetype='mp3', uid=uid)).delay() + + except Exception: response = \ 'Unable to connect to waveform generation task, there may be a delay in getting your mix online' diff --git a/core/tasks.py b/core/tasks.py index 774149a..91c2515 100755 --- a/core/tasks.py +++ b/core/tasks.py @@ -24,14 +24,18 @@ def create_waveform_task(in_file, uid): print "Moving cache audio clip from %s to %s" % (in_file, new_file) shutil.move(in_file, new_file) print "Uid: %s" % uid + return new_file else: print "Outfile is missing" @task(time_limit=3600) -def archive_mix_task(in_file, uid): +def archive_mix_task(in_file, filetype, uid): print "Sending {0} to azure".format(uid) - upload_to_azure(in_file, uid) + try: + upload_to_azure(in_file, filetype, uid) + except Exception, ex: + print "Unable to upload: %s".format(ex.message) @task def update_geo_info_task(ip_address, profile_id): diff --git a/core/utils/cdn.py b/core/utils/cdn.py index 58fca12..2ed141f 100755 --- a/core/utils/cdn.py +++ b/core/utils/cdn.py @@ -26,7 +26,8 @@ def upload_to_azure(in_file, filetype, uid): ) print "Uploaded" return obj - + else: + print "infile not found" return None diff --git a/spa/management/commands/azure_util.py b/spa/management/commands/azure_util.py index db5e979..d18e62e 100755 --- a/spa/management/commands/azure_util.py +++ b/spa/management/commands/azure_util.py @@ -10,7 +10,7 @@ class Command(NoArgsCommand): mixes = Mix.objects.filter(archive_updated=False) for mix in mixes: blob_name, download_name = mix.get_cdn_details() - upload_to_azure(blob_name, download_name) + upload_to_azure(blob_name, "mp3", download_name) mix.archive_updated = True mix.save()