Skip to content

Commit

Permalink
feat: default stayle start_dates to today in braze assignment task
Browse files Browse the repository at this point in the history
  • Loading branch information
brobro10000 committed Sep 10, 2024
1 parent 53875bd commit d4c064e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions enterprise_access/apps/content_assignments/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class AssignmentAutomaticExpiredReason:

NUM_DAYS_BEFORE_AUTO_EXPIRATION = 90

START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS = 14

RETIRED_EMAIL_ADDRESS_FORMAT = 'retired_user{}@retired.invalid'

BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
25 changes: 20 additions & 5 deletions enterprise_access/apps/content_assignments/tasks.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Tasks for content_assignments app.
"""

import datetime
import logging

from braze.exceptions import BrazeBadRequestError
from celery import shared_task
from dateutil import parser
from django.apps import apps
from django.conf import settings
from pytz import UTC

from enterprise_access.apps.api_client.braze_client import ENTERPRISE_BRAZE_ALIAS_LABEL, BrazeApiClient
from enterprise_access.apps.api_client.lms_client import LmsApiClient
Expand All @@ -21,7 +23,11 @@
from enterprise_access.tasks import LoggedTaskWithRetry
from enterprise_access.utils import get_automatic_expiration_date_and_reason, localized_utcnow

from .constants import BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT, LearnerContentAssignmentStateChoices
from .constants import (
BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT,
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS,
LearnerContentAssignmentStateChoices
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -199,9 +205,18 @@ def get_enrollment_deadline(self):
return get_human_readable_date(self._enrollment_deadline_raw())

def get_start_date(self):
return get_human_readable_date(
self.course_metadata.get('normalized_metadata', {}).get('start_date')
)
"""
Checks if the start_date is before today's date offset by the
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS value and returns today's date
If not, pass through the formatted start date.
"""
start_date = self.course_metadata.get('normalized_metadata', {}).get('start_date')
start_date_datetime = parser.parse(start_date)
now = datetime.datetime.now()
offset_date_from_today = now - datetime.timedelta(days=START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS)
if start_date_datetime < offset_date_from_today.replace(tzinfo=UTC):
return get_human_readable_date(now.strftime(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT))
return get_human_readable_date(start_date)

def get_action_required_by_timestamp(self):
"""
Expand Down

0 comments on commit d4c064e

Please sign in to comment.