Going from this question, I have this task:
@task()
def create_user(data):
try:
User.objects.get(username=data['username'])
return 'Username already exists'
except:
user = User.objects.create_user(username=data['username'], email=None, password=data['password']
)
user.save()
profile = UserProfile()
profile.user = user
profile.token = generate_token()
profile.save()
return profile.token
The way I understand Celery works is that this task can be put in a qeue and executed after some time, assuming there a lot of requests.
Let's assume a mobile app is communicating with this server. The user sends the combination of username and password to the server to register. The server will return the token only after it has processed the task. There's no way the customer can login if it doesn't have the token. So I have to wait until the task is processed to be able to send the token. So everything becomes asynchronous processing. How does Celery solve the problem then?