Skip to content

Instantly share code, notes, and snippets.

@Quard
Created April 10, 2019 12:55
Show Gist options
  • Save Quard/cd41095804b94fe458a15330f9dfe4e6 to your computer and use it in GitHub Desktop.
Save Quard/cd41095804b94fe458a15330f9dfe4e6 to your computer and use it in GitHub Desktop.
The Python Celery Cookbook: Small Tool, Big Possibilities
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