Skip to content

Commit

Permalink
improve celery task
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelpoi committed Dec 19, 2024
1 parent 4b883bf commit e43151a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demoapp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
'TEMPLATE_ENGINE': 'sendmail',
'CELERY_ENABLED': True,
'MAX_RETRIES': 0,
'BATCH_SIZE': 200,
'BATCH_SIZE': 100,
'BATCH_DELIVERY_TIMEOUT': 30,
'MESSAGE_ID_ENABLED': True,
'DEFAULT_PRIORITY': 'medium',
Expand Down
4 changes: 2 additions & 2 deletions sendmail/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ def send_queued_mail(*args, **kwargs):
To be called by the Celery task manager.
"""
while True:
if not get_queued().exists():
break
queued_emails = get_queued().select_for_update(of=('self',), skip_locked=True)
with transaction.atomic():
if not queued_emails:
break
try:
_send_bulk(queued_emails, uses_multiprocessing=False)
except Exception as e:
Expand Down

0 comments on commit e43151a

Please sign in to comment.