Running 30s test @ http://rpi:5000/api/v1/url/aaaa
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 489.29ms 196.29ms 1.38s 82.02%
Req/Sec 68.43 31.64 192.00 72.98%
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
celery -A myproject worker -l info -Q celery | |
celery -A myproject worker -l info -Q mail |
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
CELERY_TASK_ROUTES = { | |
'myproject.apps.mail.tasks.send_mail_task': {'queue': 'mail', }, | |
} |
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
send_mail_task.delay(('[email protected]', ), 'Celery cookbook test', 'test', {}) |
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 django.conf import settings | |
from django.core.mail import send_mail | |
from django.template import Engine, Context | |
from myproject.celery import app | |
def render_template(template, context): | |
engine = Engine.get_default() |
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 datetime import datetime | |
send_mail_task.apply_async( | |
(('[email protected]', ), 'Celery cookbook test', 'test', {}), | |
countdown=15 * 60 | |
) | |
send_mail_task.apply_async( | |
(('[email protected]', ), 'Celery cookbook test', 'test', {}), |
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
@celery_app.task | |
def send_good_morning_mail_task(offset=0, limit=100): | |
users = User.objects.filter(is_active=True).order_by('id')[offset:offset + limit] | |
for user in users: | |
send_good_morning_mail(user) | |
if len(users) >= limit: | |
send_good_morning_mail_task.delay(offset + limit, limit) |
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
def view(request): | |
find_job = find_best_service_provider_for_user.delay(request.user.pk) | |
# do other stuff | |
calculations_results = find_job.get().join() | |
# process calculations_results and send response |
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) | |
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
@celery_app.task(bind=True, default_retry_delay=10 * 60) | |
def send_mail_task(self, recipients, subject, template, context): | |
message = render_template(f'{template}.txt', context) | |
html_message = render_template(f'{template}.html', context) | |
try: | |
send_mail( | |
subject=subject, | |
message=message, | |
from_email=settings.DEFAULT_FROM_EMAIL, | |
recipient_list=recipients, |
NewerOlder