Skip to content

Commit

Permalink
Merge branch 'nh/iter_repeaters_1' into autostaging
Browse files Browse the repository at this point in the history
  • Loading branch information
kaapstorm committed Aug 26, 2024
2 parents 4cab9bb + 161d38e commit 3bb1112
Show file tree
Hide file tree
Showing 19 changed files with 799 additions and 80 deletions.
1 change: 1 addition & 0 deletions corehq/apps/reports/filters/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def options(self):
State.Pending,
State.Cancelled,
State.Fail,
State.InvalidPayload,
]]


Expand Down
23 changes: 16 additions & 7 deletions corehq/apps/zapier/tests/test_zapier_forwarding.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import uuid
from collections import namedtuple
from datetime import datetime, timedelta
from unittest.mock import patch

from django.test import TestCase

from casexml.apps.case.mock import CaseBlock
from corehq.apps.hqcase.utils import submit_case_blocks

from corehq.apps.hqcase.utils import submit_case_blocks
from corehq.apps.zapier.consts import EventTypes
from corehq.apps.zapier.models import ZapierSubscription
from corehq.apps.zapier.tests.test_utils import bootrap_domain_for_zapier
Expand All @@ -15,19 +17,26 @@
ZAPIER_CASE_TYPE = 'animal'


ResponseMock = namedtuple('ResponseMock', ['status_code', 'reason'])


class TestZapierCaseForwarding(TestCase):

@classmethod
def setUpClass(cls):
super(TestZapierCaseForwarding, cls).setUpClass()
cls.domain = DOMAIN
cls.domain_object, cls.web_user, cls.api_key = bootrap_domain_for_zapier(cls.domain)

@classmethod
def tearDownClass(cls):
cls.web_user.delete(cls.domain, deleted_by=None)
cls.domain_object.delete()
super(TestZapierCaseForwarding, cls).tearDownClass()
cls.addClassCleanup(cls.domain_object.delete)
cls.addClassCleanup(cls.web_user.delete, cls.domain, deleted_by=None)

simple_request_patch = patch('corehq.motech.repeaters.models.simple_request')
simple_request_func = simple_request_patch.start()
simple_request_func.return_value = ResponseMock(
status_code=503,
reason='Service Unavailable',
)
cls.addClassCleanup(simple_request_patch.stop)

def tearDown(self):
ZapierSubscription.objects.all().delete()
Expand Down
4 changes: 4 additions & 0 deletions corehq/motech/repeaters/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
CHECK_REPEATERS_INTERVAL = timedelta(minutes=5)
CHECK_REPEATERS_PARTITION_COUNT = settings.CHECK_REPEATERS_PARTITION_COUNT
CHECK_REPEATERS_KEY = 'check-repeaters-key'
PROCESS_REPEATERS_INTERVAL = timedelta(minutes=1)
PROCESS_REPEATERS_KEY = 'process-repeaters-key'
ENDPOINT_TIMER = 'endpoint_timer'
# Number of attempts to an online endpoint before cancelling payload
MAX_ATTEMPTS = 3
Expand All @@ -27,13 +29,15 @@ class State(IntegerChoices):
Success = 4, _('Succeeded')
Cancelled = 8, _('Cancelled')
Empty = 16, _('Empty') # There was nothing to send. Implies Success.
InvalidPayload = 32, _('Invalid Payload') # Implies Cancelled.


RECORD_PENDING_STATE = State.Pending
RECORD_SUCCESS_STATE = State.Success
RECORD_FAILURE_STATE = State.Fail
RECORD_CANCELLED_STATE = State.Cancelled
RECORD_EMPTY_STATE = State.Empty
RECORD_INVALIDPAYLOAD_STATE = State.InvalidPayload


class UCRRestrictionFFStatus(IntegerChoices):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("repeaters", "0012_formexpressionrepeater_arcgisformexpressionrepeater"),
]

operations = [
migrations.AlterField(
model_name="repeatrecord",
name="state",
field=models.PositiveSmallIntegerField(
choices=[
(1, "Pending"),
(2, "Failed"),
(4, "Succeeded"),
(8, "Cancelled"),
(16, "Empty"),
(32, "Invalid Payload"),
],
default=1,
),
),
migrations.AlterField(
model_name="repeatrecordattempt",
name="state",
field=models.PositiveSmallIntegerField(
choices=[
(1, "Pending"),
(2, "Failed"),
(4, "Succeeded"),
(8, "Cancelled"),
(16, "Empty"),
(32, "Invalid Payload"),
]
),
),
]
16 changes: 16 additions & 0 deletions corehq/motech/repeaters/migrations/0014_repeater_max_workers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("repeaters", "0013_alter_repeatrecord_state_and_more"),
]

operations = [
migrations.AddField(
model_name="repeater",
name="max_workers",
field=models.IntegerField(default=0),
),
]
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,
),
),
]
Loading

0 comments on commit 3bb1112

Please sign in to comment.