mirror of
https://github.com/fergalmoran/dss.api.git
synced 2026-01-03 15:13:57 +00:00
Fixed azure celery stuff
This commit is contained in:
15
api/views.py
15
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'
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -26,7 +26,8 @@ def upload_to_azure(in_file, filetype, uid):
|
||||
)
|
||||
print "Uploaded"
|
||||
return obj
|
||||
|
||||
else:
|
||||
print "infile not found"
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user