I have the following task for Django Celery (using Amazon SQS).
@task
def upload_task(request, **kwargs):
file = request.FILES['file']
ContactCSVModel.import_from_file(file)
return True
This appears to work i.e. the file is successfully added it to my database, but I'm not sure it's using Celery at all. How do I know if this worked. Should I see something? In the terminal I ran...
manage.py celery worker --loglevel=info
, which states I have one task called contacts.tasks.upload_task
, but I never see anything happen it just states...
[2013-03-14 20:52:47,947: INFO/MainProcess] consumer: Connected to sqs://AJSUQJZKNSJA81JM@localhost//
Any idea's if my task has run and was completed (yes I know it completed due to it being in the database, but was that via Celery?)
this is where the task gets run from
views.py
@login_required
def upload(request):
# If we had a POST then get the request post values.
if request.method == 'POST':
form = ContactUploadForm(request.POST, request.FILES)
# Check we have valid data
if form.is_valid():
upload_task(request)
#file = request.FILES['file']
#ContactCSVModel.import_from_file(file)
messages.add_message(request, messages.SUCCESS, 'Items have been added')
else:
messages.add_message(request, messages.ERROR, ' Cannot upload CSV file.')
return render_to_response('contacts/home.html', context_instance=RequestContext(request))
else:
form = ContactUploadForm()
# Do this part no matter the outcome above.
context = {'form': form}
return render_to_response('contacts/home.html', context, context_instance=RequestContext(request))
like I said this works the csv data in loaded into the database, but I don't think Celery is doing anything.
this is my Celery settings....
# Celery
BROKER_TRANSPORT_OPTIONS = {'queue_name_prefix': 'celery-'}
BROKER_TRANSPORT = 'sqs'
BROKER_TRANSPORT_OPTIONS = {
'region': 'eu-west-1',
}
BROKER_USER = 'xyz'
BROKER_PASSWORD = 'xyz'