Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
e81931da
Commit
e81931da
authored
Oct 19, 2017
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move get_schedules_with_target_date_by_bin_and_orgs into Resolver baseclass
parent
234780f5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
48 deletions
+32
-48
openedx/core/djangoapps/schedules/resolvers.py
+32
-48
No files found.
openedx/core/djangoapps/schedules/resolvers.py
View file @
e81931da
...
...
@@ -67,6 +67,13 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
exclude_orgs
=
attr
.
ib
(
default
=
False
)
override_recipient_email
=
attr
.
ib
(
default
=
None
)
schedule_date_field
=
None
num_bins
=
DEFAULT_NUM_BINS
def
__attrs_post_init__
(
self
):
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
self
.
current_datetime
=
self
.
target_datetime
-
datetime
.
timedelta
(
days
=
self
.
day_offset
)
def
send
(
self
,
msg_type
):
_annotate_for_monitoring
(
msg_type
,
self
.
site
,
self
.
bin_num
,
self
.
target_datetime
,
self
.
day_offset
)
...
...
@@ -82,9 +89,9 @@ class BinnedSchedulesBaseResolver(PrefixedDebugLoggerMixin, RecipientResolver):
with
function_trace
(
'enqueue_send_task'
):
self
.
async_send_task
.
apply_async
((
self
.
site
.
id
,
str
(
msg
)),
retry
=
False
)
def
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
,
current_datetime
,
target_datetime
,
bin_num
,
num_bins
=
DEFAULT_NUM_BINS
,
org_list
=
None
,
exclude_orgs
=
False
,
order_by
=
'enrollment__user__id'
):
def
get_schedules_with_target_date_by_bin_and_orgs
(
self
,
order_by
=
'enrollment__user__id'
):
"""
Returns Schedules with the target_date, related to Users whose id matches the bin_num, and filtered by org_list.
...
...
@@ -99,23 +106,23 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, current_
or strictly include (False) them (default: False)
order_by -- string for field to sort the resulting Schedules by
"""
target_day
=
_get_datetime_beginning_of_day
(
target_datetime
)
target_day
=
_get_datetime_beginning_of_day
(
self
.
target_datetime
)
schedule_day_equals_target_day_filter
=
{
'courseenrollment__schedule__{}__gte'
.
format
(
schedule_date_field
):
target_day
,
'courseenrollment__schedule__{}__lt'
.
format
(
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
'courseenrollment__schedule__{}__gte'
.
format
(
self
.
schedule_date_field
):
target_day
,
'courseenrollment__schedule__{}__lt'
.
format
(
self
.
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
}
users
=
User
.
objects
.
filter
(
courseenrollment__is_active
=
True
,
**
schedule_day_equals_target_day_filter
)
.
annotate
(
id_mod
=
F
(
'id'
)
%
num_bins
id_mod
=
F
(
'id'
)
%
self
.
num_bins
)
.
filter
(
id_mod
=
bin_num
id_mod
=
self
.
bin_num
)
schedule_day_equals_target_day_filter
=
{
'{}__gte'
.
format
(
schedule_date_field
):
target_day
,
'{}__lt'
.
format
(
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
'{}__gte'
.
format
(
self
.
schedule_date_field
):
target_day
,
'{}__lt'
.
format
(
self
.
schedule_date_field
):
target_day
+
datetime
.
timedelta
(
days
=
1
),
}
schedules
=
Schedule
.
objects
.
select_related
(
'enrollment__user__profile'
,
...
...
@@ -124,17 +131,17 @@ def get_schedules_with_target_date_by_bin_and_orgs(schedule_date_field, current_
'enrollment__course__modes'
)
.
filter
(
Q
(
enrollment__course__end__isnull
=
True
)
|
Q
(
enrollment__course__end__gte
=
current_datetime
),
enrollment__course__end__gte
=
self
.
current_datetime
),
enrollment__user__in
=
users
,
enrollment__is_active
=
True
,
**
schedule_day_equals_target_day_filter
)
.
order_by
(
order_by
)
if
org_list
is
not
None
:
if
exclude_orgs
:
schedules
=
schedules
.
exclude
(
enrollment__course__org__in
=
org_list
)
if
self
.
org_list
is
not
None
:
if
self
.
exclude_orgs
:
schedules
=
schedules
.
exclude
(
enrollment__course__org__in
=
self
.
org_list
)
else
:
schedules
=
schedules
.
filter
(
enrollment__course__org__in
=
org_list
)
schedules
=
schedules
.
filter
(
enrollment__course__org__in
=
self
.
org_list
)
if
"read_replica"
in
settings
.
DATABASES
:
schedules
=
schedules
.
using
(
"read_replica"
)
...
...
@@ -179,20 +186,12 @@ class ScheduleStartResolver(BinnedSchedulesBaseResolver):
Send a message to all users whose schedule started at ``self.current_date`` + ``day_offset``.
"""
log_prefix
=
'Scheduled Nudge'
schedule_date_field
=
'start'
num_bins
=
RECURRING_NUDGE_NUM_BINS
def
schedules_for_bin
(
self
):
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
current_datetime
=
self
.
target_datetime
-
datetime
.
timedelta
(
days
=
self
.
day_offset
)
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'start'
,
current_datetime
=
current_datetime
,
target_datetime
=
self
.
target_datetime
,
bin_num
=
self
.
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
self
.
org_list
,
exclude_orgs
=
self
.
exclude_orgs
,
)
schedules
=
self
.
get_schedules_with_target_date_by_bin_and_orgs
()
LOG
.
debug
(
'Recurring Nudge: Query =
%
r'
,
schedules
.
query
.
sql_with_params
())
...
...
@@ -234,19 +233,11 @@ class UpgradeReminderResolver(BinnedSchedulesBaseResolver):
Send a message to all users whose verified upgrade deadline is at ``self.current_date`` + ``day_offset``.
"""
log_prefix
=
'Upgrade Reminder'
schedule_date_field
=
'upgrade_deadline'
num_bins
=
UPGRADE_REMINDER_NUM_BINS
def
schedules_for_bin
(
self
):
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
current_datetime
=
self
.
target_datetime
-
datetime
.
timedelta
(
days
=
self
.
day_offset
)
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'upgrade_deadline'
,
current_datetime
=
current_datetime
,
target_datetime
=
self
.
target_datetime
,
bin_num
=
self
.
bin_num
,
num_bins
=
RECURRING_NUDGE_NUM_BINS
,
org_list
=
self
.
org_list
,
exclude_orgs
=
self
.
exclude_orgs
,
)
schedules
=
self
.
get_schedules_with_target_date_by_bin_and_orgs
()
for
(
user
,
user_schedules
)
in
groupby
(
schedules
,
lambda
s
:
s
.
enrollment
.
user
):
user_schedules
=
list
(
user_schedules
)
...
...
@@ -314,19 +305,12 @@ class CourseUpdateResolver(BinnedSchedulesBaseResolver):
course has updates.
"""
log_prefix
=
'Course Update'
schedule_date_field
=
'start'
num_bins
=
COURSE_UPDATE_NUM_BINS
def
schedules_for_bin
(
self
):
# TODO: in the next refactor of this task, pass in current_datetime instead of reproducing it here
current_datetime
=
self
.
target_datetime
-
datetime
.
timedelta
(
days
=
self
.
day_offset
)
week_num
=
abs
(
self
.
day_offset
)
/
7
schedules
=
get_schedules_with_target_date_by_bin_and_orgs
(
schedule_date_field
=
'start'
,
current_datetime
=
current_datetime
,
target_datetime
=
self
.
target_datetime
,
bin_num
=
self
.
bin_num
,
num_bins
=
COURSE_UPDATE_NUM_BINS
,
org_list
=
self
.
org_list
,
exclude_orgs
=
self
.
exclude_orgs
,
schedules
=
self
.
get_schedules_with_target_date_by_bin_and_orgs
(
order_by
=
'enrollment__course'
,
)
LOG
.
debug
(
'Course Update: Query =
%
r'
,
schedules
.
query
.
sql_with_params
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment