Commit 47006569 by Calen Pennington

Move bin-count constants into resolvers.py nearer to the queries that use them

parent 31db37ea
...@@ -81,7 +81,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -81,7 +81,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
retry=False, retry=False,
) )
mock_schedule_bin.apply_async.assert_any_call( mock_schedule_bin.apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), -3, tasks.RECURRING_NUDGE_NUM_BINS - 1, [], True, None), (self.site_config.site.id, serialize(test_day), -3, resolvers.RECURRING_NUDGE_NUM_BINS - 1, [], True, None),
retry=False, retry=False,
) )
self.assertFalse(mock_ace.send.called) self.assertFalse(mock_ace.send.called)
...@@ -97,11 +97,11 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -97,11 +97,11 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
) for i in range(schedule_count) ) for i in range(schedule_count)
] ]
bins_in_use = frozenset((s.enrollment.user.id % tasks.RECURRING_NUDGE_NUM_BINS) for s in schedules) bins_in_use = frozenset((s.enrollment.user.id % resolvers.RECURRING_NUDGE_NUM_BINS) for s in schedules)
test_datetime = datetime.datetime(2017, 8, 3, 18, tzinfo=pytz.UTC) test_datetime = datetime.datetime(2017, 8, 3, 18, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime) test_datetime_str = serialize(test_datetime)
for b in range(tasks.RECURRING_NUDGE_NUM_BINS): for b in range(resolvers.RECURRING_NUDGE_NUM_BINS):
expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES
if b in bins_in_use: if b in bins_in_use:
# to fetch course modes for valid schedules # to fetch course modes for valid schedules
...@@ -126,7 +126,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -126,7 +126,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
test_datetime = datetime.datetime(2017, 8, 3, 20, tzinfo=pytz.UTC) test_datetime = datetime.datetime(2017, 8, 3, 20, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime) test_datetime_str = serialize(test_datetime)
for b in range(tasks.RECURRING_NUDGE_NUM_BINS): for b in range(resolvers.RECURRING_NUDGE_NUM_BINS):
with self.assertNumQueries(NUM_QUERIES_NO_MATCHING_SCHEDULES, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(NUM_QUERIES_NO_MATCHING_SCHEDULES, table_blacklist=WAFFLE_TABLES):
tasks.recurring_nudge_schedule_bin( tasks.recurring_nudge_schedule_bin(
self.site_config.site.id, target_day_str=test_datetime_str, day_offset=-3, bin_num=b, self.site_config.site.id, target_day_str=test_datetime_str, day_offset=-3, bin_num=b,
...@@ -143,7 +143,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -143,7 +143,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
@patch.object(tasks, '_recurring_nudge_schedule_send') @patch.object(tasks, '_recurring_nudge_schedule_send')
def test_send_after_course_end(self, mock_schedule_send): def test_send_after_course_end(self, mock_schedule_send):
user1 = UserFactory.create(id=tasks.RECURRING_NUDGE_NUM_BINS) user1 = UserFactory.create(id=resolvers.RECURRING_NUDGE_NUM_BINS)
schedule = ScheduleFactory.create( schedule = ScheduleFactory.create(
start=datetime.datetime(2017, 8, 3, 20, 34, 30, tzinfo=pytz.UTC), start=datetime.datetime(2017, 8, 3, 20, 34, 30, tzinfo=pytz.UTC),
...@@ -199,8 +199,8 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -199,8 +199,8 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
for config in (limited_config, unlimited_config): for config in (limited_config, unlimited_config):
ScheduleConfigFactory.create(site=config.site) ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=tasks.RECURRING_NUDGE_NUM_BINS) user1 = UserFactory.create(id=resolvers.RECURRING_NUDGE_NUM_BINS)
user2 = UserFactory.create(id=tasks.RECURRING_NUDGE_NUM_BINS * 2) user2 = UserFactory.create(id=resolvers.RECURRING_NUDGE_NUM_BINS * 2)
ScheduleFactory.create( ScheduleFactory.create(
start=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC), start=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
...@@ -247,7 +247,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -247,7 +247,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
with self.assertNumQueries(NUM_QUERIES_WITH_MATCHES, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(NUM_QUERIES_WITH_MATCHES, table_blacklist=WAFFLE_TABLES):
tasks.recurring_nudge_schedule_bin( tasks.recurring_nudge_schedule_bin(
self.site_config.site.id, target_day_str=test_datetime_str, day_offset=-3, self.site_config.site.id, target_day_str=test_datetime_str, day_offset=-3,
bin_num=user.id % tasks.RECURRING_NUDGE_NUM_BINS, bin_num=user.id % resolvers.RECURRING_NUDGE_NUM_BINS,
org_list=[schedules[0].enrollment.course.org], org_list=[schedules[0].enrollment.course.org],
) )
self.assertEqual(mock_schedule_send.apply_async.call_count, 1) self.assertEqual(mock_schedule_send.apply_async.call_count, 1)
...@@ -434,7 +434,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -434,7 +434,7 @@ class TestSendRecurringNudge(FilteredQueryCountMixin, CacheIsolationTestCase):
return templates_override return templates_override
def _calculate_bin_for_user(self, user): def _calculate_bin_for_user(self, user):
return user.id % tasks.RECURRING_NUDGE_NUM_BINS return user.id % resolvers.RECURRING_NUDGE_NUM_BINS
def _contains_upsell_attribute(self, msg_attr): def _contains_upsell_attribute(self, msg_attr):
msg = Message.from_string(msg_attr) msg = Message.from_string(msg_attr)
......
...@@ -85,7 +85,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -85,7 +85,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
retry=False, retry=False,
) )
mock_schedule_bin.apply_async.assert_any_call( mock_schedule_bin.apply_async.assert_any_call(
(self.site_config.site.id, serialize(test_day), 2, tasks.UPGRADE_REMINDER_NUM_BINS - 1, [], True, None), (self.site_config.site.id, serialize(test_day), 2, resolvers.UPGRADE_REMINDER_NUM_BINS - 1, [], True, None),
retry=False, retry=False,
) )
self.assertFalse(mock_ace.send.called) self.assertFalse(mock_ace.send.called)
...@@ -101,11 +101,11 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -101,11 +101,11 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
) for i in range(schedule_count) ) for i in range(schedule_count)
] ]
bins_in_use = frozenset((s.enrollment.user.id % tasks.UPGRADE_REMINDER_NUM_BINS) for s in schedules) bins_in_use = frozenset((s.enrollment.user.id % resolvers.UPGRADE_REMINDER_NUM_BINS) for s in schedules)
test_datetime = datetime.datetime(2017, 8, 3, 18, tzinfo=pytz.UTC) test_datetime = datetime.datetime(2017, 8, 3, 18, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime) test_datetime_str = serialize(test_datetime)
for b in range(tasks.UPGRADE_REMINDER_NUM_BINS): for b in range(resolvers.UPGRADE_REMINDER_NUM_BINS):
expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES expected_queries = NUM_QUERIES_NO_MATCHING_SCHEDULES
if b in bins_in_use: if b in bins_in_use:
# to fetch course modes for valid schedules # to fetch course modes for valid schedules
...@@ -131,7 +131,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -131,7 +131,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
test_datetime = datetime.datetime(2017, 8, 3, 20, tzinfo=pytz.UTC) test_datetime = datetime.datetime(2017, 8, 3, 20, tzinfo=pytz.UTC)
test_datetime_str = serialize(test_datetime) test_datetime_str = serialize(test_datetime)
for b in range(tasks.UPGRADE_REMINDER_NUM_BINS): for b in range(resolvers.UPGRADE_REMINDER_NUM_BINS):
with self.assertNumQueries(NUM_QUERIES_NO_MATCHING_SCHEDULES, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(NUM_QUERIES_NO_MATCHING_SCHEDULES, table_blacklist=WAFFLE_TABLES):
tasks.upgrade_reminder_schedule_bin( tasks.upgrade_reminder_schedule_bin(
self.site_config.site.id, target_day_str=test_datetime_str, day_offset=2, bin_num=b, self.site_config.site.id, target_day_str=test_datetime_str, day_offset=2, bin_num=b,
...@@ -183,8 +183,8 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -183,8 +183,8 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
for config in (limited_config, unlimited_config): for config in (limited_config, unlimited_config):
ScheduleConfigFactory.create(site=config.site) ScheduleConfigFactory.create(site=config.site)
user1 = UserFactory.create(id=tasks.UPGRADE_REMINDER_NUM_BINS) user1 = UserFactory.create(id=resolvers.UPGRADE_REMINDER_NUM_BINS)
user2 = UserFactory.create(id=tasks.UPGRADE_REMINDER_NUM_BINS * 2) user2 = UserFactory.create(id=resolvers.UPGRADE_REMINDER_NUM_BINS * 2)
ScheduleFactory.create( ScheduleFactory.create(
upgrade_deadline=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC), upgrade_deadline=datetime.datetime(2017, 8, 3, 17, 44, 30, tzinfo=pytz.UTC),
...@@ -231,7 +231,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -231,7 +231,7 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
with self.assertNumQueries(NUM_QUERIES_WITH_MATCHES, table_blacklist=WAFFLE_TABLES): with self.assertNumQueries(NUM_QUERIES_WITH_MATCHES, table_blacklist=WAFFLE_TABLES):
tasks.upgrade_reminder_schedule_bin( tasks.upgrade_reminder_schedule_bin(
self.site_config.site.id, target_day_str=test_datetime_str, day_offset=2, self.site_config.site.id, target_day_str=test_datetime_str, day_offset=2,
bin_num=user.id % tasks.UPGRADE_REMINDER_NUM_BINS, bin_num=user.id % resolvers.UPGRADE_REMINDER_NUM_BINS,
org_list=[schedules[0].enrollment.course.org], org_list=[schedules[0].enrollment.course.org],
) )
self.assertEqual(mock_schedule_send.apply_async.call_count, 1) self.assertEqual(mock_schedule_send.apply_async.call_count, 1)
...@@ -309,4 +309,4 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase): ...@@ -309,4 +309,4 @@ class TestUpgradeReminder(FilteredQueryCountMixin, CacheIsolationTestCase):
return templates_override return templates_override
def _calculate_bin_for_user(self, user): def _calculate_bin_for_user(self, user):
return user.id % tasks.RECURRING_NUDGE_NUM_BINS return user.id % resolvers.RECURRING_NUDGE_NUM_BINS
...@@ -18,10 +18,6 @@ from openedx.core.djangoapps.schedules.config import COURSE_UPDATE_WAFFLE_FLAG ...@@ -18,10 +18,6 @@ from openedx.core.djangoapps.schedules.config import COURSE_UPDATE_WAFFLE_FLAG
from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist from openedx.core.djangoapps.schedules.exceptions import CourseUpdateDoesNotExist
from openedx.core.djangoapps.schedules.models import Schedule, ScheduleConfig from openedx.core.djangoapps.schedules.models import Schedule, ScheduleConfig
from openedx.core.djangoapps.schedules.tasks import ( from openedx.core.djangoapps.schedules.tasks import (
DEFAULT_NUM_BINS,
RECURRING_NUDGE_NUM_BINS,
UPGRADE_REMINDER_NUM_BINS,
COURSE_UPDATE_NUM_BINS,
recurring_nudge_schedule_bin, recurring_nudge_schedule_bin,
upgrade_reminder_schedule_bin, upgrade_reminder_schedule_bin,
course_update_schedule_bin, course_update_schedule_bin,
...@@ -41,6 +37,11 @@ from xmodule.modulestore.django import modulestore ...@@ -41,6 +37,11 @@ from xmodule.modulestore.django import modulestore
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DEFAULT_NUM_BINS = 24
RECURRING_NUDGE_NUM_BINS = DEFAULT_NUM_BINS
UPGRADE_REMINDER_NUM_BINS = DEFAULT_NUM_BINS
COURSE_UPDATE_NUM_BINS = DEFAULT_NUM_BINS
class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver): class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
""" """
Starts num_bins number of async tasks, each of which sends emails to an equal group of learners. Starts num_bins number of async tasks, each of which sends emails to an equal group of learners.
......
...@@ -31,10 +31,6 @@ KNOWN_RETRY_ERRORS = ( # Errors we expect occasionally that could resolve on re ...@@ -31,10 +31,6 @@ KNOWN_RETRY_ERRORS = ( # Errors we expect occasionally that could resolve on re
DatabaseError, DatabaseError,
ValidationError, ValidationError,
) )
DEFAULT_NUM_BINS = 24
RECURRING_NUDGE_NUM_BINS = DEFAULT_NUM_BINS
UPGRADE_REMINDER_NUM_BINS = DEFAULT_NUM_BINS
COURSE_UPDATE_NUM_BINS = DEFAULT_NUM_BINS
@task(bind=True, default_retry_delay=30, routing_key=ROUTING_KEY) @task(bind=True, default_retry_delay=30, routing_key=ROUTING_KEY)
......
...@@ -6,7 +6,7 @@ from django.conf import settings ...@@ -6,7 +6,7 @@ from django.conf import settings
from mock import patch from mock import patch
from openedx.core.djangoapps.schedules.resolvers import BinnedSchedulesBaseResolver from openedx.core.djangoapps.schedules.resolvers import BinnedSchedulesBaseResolver
from openedx.core.djangoapps.schedules.tasks import DEFAULT_NUM_BINS from openedx.core.djangoapps.schedules.resolvers import DEFAULT_NUM_BINS
from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory from openedx.core.djangoapps.schedules.tests.factories import ScheduleConfigFactory
from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory from openedx.core.djangoapps.site_configuration.tests.factories import SiteConfigurationFactory, SiteFactory
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms from openedx.core.djangolib.testing.utils import CacheIsolationTestCase, skip_unless_lms
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment