-
Notifications
You must be signed in to change notification settings - Fork 58
Refactor reminders for draft challenge requests #4729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4b78f3c
2145197
e37b725
9d8b6a7
99397c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Generated by Django 5.2.14 on 2026-05-22 09:01 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("challenges", "0071_alter_challengerequest_status_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="challengerequest", | ||
| name="draft_reminder_count", | ||
| field=models.PositiveSmallIntegerField( | ||
| default=0, | ||
| help_text="Number of reminders sent to the challenge organizers to submit this draft for review.", | ||
| ), | ||
| ), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,8 +244,9 @@ def send_challenge_request_draft_reminder_emails(): | |
| for c in ChallengeRequest.objects.filter( | ||
| status=ChallengeRequest.ChallengeRequestStatusChoices.DRAFT, | ||
| created__lte=now() | ||
| - settings.CHALLENGE_REQUEST_AGE_START_REMINDER_CUTOFF, | ||
| created__gte=now() | ||
| - settings.CHALLENGE_REQUEST_AGE_END_REMINDER_CUTOFF, | ||
| - settings.CHALLENGE_REQUEST_AGE_START_DRAFT_REMINDER_CUTOFF, | ||
| draft_reminder_count__lt=settings.CHALLENGE_REQUEST_MAX_DRAFT_REMINDERS, | ||
|
chrisvanrun marked this conversation as resolved.
|
||
| ): | ||
| send_challenge_requests_draft_reminder(challenge_request=c) | ||
| c.draft_reminder_count += 1 | ||
| c.save(update_fields=["draft_reminder_count"]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task is not a singleton so it would be more robust to do this with a single update: requests = ChallengeRequest.objects.filter(
status=ChallengeRequest.ChallengeRequestStatusChoices.DRAFT,
created__lte=now()
- settings.CHALLENGE_REQUEST_AGE_START_DRAFT_REMINDER_CUTOFF,
draft_reminder_count__lt=settings.CHALLENGE_REQUEST_MAX_DRAFT_REMINDERS,Expand commentComment on line R248Resolved
)
for request in requests:
send_challenge_requests_draft_reminder(challenge_request=request)
requests.update(draft_reminder_count=F("draft_reminder_count") + 1)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is superior in that it would prevent an additional DB query per reminder! I am not sure why you would say it is more robust? Any failure would be caught by the transaction wrapper, and doing the update in a single call wouldn't catch other spawned (same) tasks to also send the email afaik.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The task is not a singleton, so n-tasks can run at the same time. Updating the value in python takes the read value and increments it. If n tasks run at the same time, they read
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aaaaah! The increment is applied at the commit of a transaction if using an Today I learned something new! Thank you! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This field should not be editable.