Skip to content

Commit

Permalink
Index fields used by RepeaterManager.all_ready()
Browse files Browse the repository at this point in the history
  • Loading branch information
kaapstorm committed Aug 27, 2024
1 parent fbaa12a commit e83e925
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("repeaters", "0014_repeater_max_workers"),
]

operations = [
migrations.AlterField(
model_name="repeater",
name="is_paused",
field=models.BooleanField(db_index=True, default=False),
),
migrations.AlterField(
model_name="repeater",
name="next_attempt_at",
field=models.DateTimeField(blank=True, db_index=True, null=True),
),
migrations.AlterField(
model_name="repeatrecord",
name="state",
field=models.PositiveSmallIntegerField(
choices=[
(1, "Pending"),
(2, "Failed"),
(4, "Succeeded"),
(8, "Cancelled"),
(16, "Empty"),
(32, "Invalid Payload"),
],
db_index=True,
default=1,
),
),
]
34 changes: 23 additions & 11 deletions corehq/motech/repeaters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ def all_ready(self):
repeat_records_ready_to_send = models.Q(
repeat_records__state__in=(State.Pending, State.Fail)
)
return (self.get_queryset()
.filter(not_paused)
.filter(next_attempt_not_in_the_future)
.filter(repeat_records_ready_to_send))
return (
self.get_queryset()
.filter(not_paused)
.filter(next_attempt_not_in_the_future)
.filter(repeat_records_ready_to_send)
)

def get_all_ready_ids_by_domain(self):
results = defaultdict(list)
Expand Down Expand Up @@ -265,8 +267,12 @@ class Repeater(RepeaterSuperProxy):
default=REQUEST_POST,
max_length=16,
)
is_paused = models.BooleanField(default=False)
next_attempt_at = models.DateTimeField(null=True, blank=True)
is_paused = models.BooleanField(default=False, db_index=True)
next_attempt_at = models.DateTimeField(
null=True,
blank=True,
db_index=True,
)
last_attempt_at = models.DateTimeField(null=True, blank=True)
max_workers = models.IntegerField(default=0)
options = JSONField(default=dict)
Expand Down Expand Up @@ -1001,11 +1007,17 @@ def get_domains_with_records(self):
class RepeatRecord(models.Model):
domain = models.CharField(max_length=126)
payload_id = models.CharField(max_length=255)
repeater = models.ForeignKey(Repeater,
on_delete=DB_CASCADE,
db_column="repeater_id_",
related_name='repeat_records')
state = models.PositiveSmallIntegerField(choices=State.choices, default=State.Pending)
repeater = models.ForeignKey(
Repeater,
on_delete=DB_CASCADE,
db_column="repeater_id_",
related_name='repeat_records',
)
state = models.PositiveSmallIntegerField(
choices=State.choices,
default=State.Pending,
db_index=True,
)
registered_at = models.DateTimeField()
next_check = models.DateTimeField(null=True, default=None)
max_possible_tries = models.IntegerField(default=MAX_BACKOFF_ATTEMPTS)
Expand Down
1 change: 1 addition & 0 deletions migrations.lock
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ repeaters
0012_formexpressionrepeater_arcgisformexpressionrepeater
0013_alter_repeatrecord_state_and_more
0014_repeater_max_workers
0015_alter_repeater_is_paused_and_more
reports
0001_initial
0002_auto_20171121_1803
Expand Down

0 comments on commit e83e925

Please sign in to comment.