Created
April 10, 2019 12:55
-
-
Save Quard/cd41095804b94fe458a15330f9dfe4e6 to your computer and use it in GitHub Desktop.
The Python Celery Cookbook: Small Tool, Big Possibilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import group | |
@celery_app.task | |
def calculate_service_provider_task(user_id, provider_id): | |
user = User.objects.get(pk=user_id) | |
provider = ServiceProvider.objects.get(pk=provider_id) | |
return calculate_service_provider(user, provider) | |
@celery_app.task | |
def find_best_service_provider_for_user(user_id): | |
user = User.objects.get(pk=user_id) | |
providers = ServiceProvider.objects.related_to_user(user) | |
calc_group = group([ | |
calculate_service_provider_task.s(user.pk, provider.pk) | |
for provider in providers | |
]).apply_async() | |
return calc_group |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment