Skip to content

Commit

Permalink
feat: backport event bus configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wowkalucky authored and kyrylo-kh committed Apr 15, 2024
1 parent 1244a9f commit 8a3ccb7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
41 changes: 41 additions & 0 deletions lms/djangoapps/grades/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
from crum import get_current_user
from django.conf import settings
from eventtracking import tracker
from openedx_events.learning.data import UserCourseData, CourseData, UserData, UserPersonalData
from openedx_events.learning.signals import (
COURSE_GRADE_NOW_PASSED as COURSE_GRADE_NOW_PASSED_PUBLIC,
COURSE_GRADE_NOW_FAILED as COURSE_GRADE_NOW_FAILED_PUBLIC,
)

from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.models import CourseEnrollment
Expand Down Expand Up @@ -190,6 +195,24 @@ def course_grade_now_passed(user, course_id):
}
)

# produce to event bus
COURSE_GRADE_NOW_PASSED_PUBLIC.send_event(
user_course_data=UserCourseData(
user=UserData(
pii=UserPersonalData(
username=user.username,
email=user.email,
name=user.get_full_name(),
),
id=user.id,
is_active=user.is_active,
),
course=CourseData(
course_key=course_id,
),
)
)


def course_grade_now_failed(user, course_id):
"""
Expand All @@ -209,6 +232,24 @@ def course_grade_now_failed(user, course_id):
}
)

# produce to event bus
COURSE_GRADE_NOW_FAILED_PUBLIC.send_event(
user_course_data=UserCourseData(
user=UserData(
pii=UserPersonalData(
username=user.username,
email=user.email,
name=user.get_full_name(),
),
id=user.id,
is_active=user.is_active,
),
course=CourseData(
course_key=course_id,
),
)
)


def fire_segment_event_on_course_grade_passed_first_time(user_id, course_locator):
"""
Expand Down
32 changes: 32 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5418,6 +5418,13 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
def _should_send_certificate_events(settings):
return settings.FEATURES['SEND_LEARNING_CERTIFICATE_LIFECYCLE_EVENTS_TO_BUS']


#### Event bus ####
EVENT_BUS_PRODUCER = "edx_event_bus_redis.create_producer"
EVENT_BUS_CONSUMER = "edx_event_bus_redis.RedisEventConsumer"
EVENT_BUS_REDIS_CONNECTION_URL = "redis://:[email protected]:6379/"
EVENT_BUS_TOPIC_PREFIX = "dev"

#### Event bus producing ####
# .. setting_name: EVENT_BUS_PRODUCER_CONFIG
# .. setting_default: all events disabled
Expand Down Expand Up @@ -5491,11 +5498,36 @@ def _should_send_certificate_events(settings):
'course-authoring-xblock-lifecycle':
{'event_key_field': 'xblock_info.usage_key', 'enabled': False},
},
"org.openedx.learning.course.grade.now.passed.v1": {
"learning-badges-lifecycle": {
"event_key_field": "user_course_data.course.course_key",
"enabled": True,
},
},
"org.openedx.learning.course.grade.now.failed.v1": {
"learning-badges-lifecycle": {
"event_key_field": "user_course_data.course.course_key",
"enabled": True,
},
},
}
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.created.v1',
'learning-certificate-lifecycle', 'enabled')
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.revoked.v1',
'learning-certificate-lifecycle', 'enabled')

# If the consumer encounters this many consecutive errors, exit with an error. This is intended to be used in a context where a management system (such as Kubernetes) will relaunch the consumer automatically.
#EVENT_BUS_REDIS_CONSUMER_CONSECUTIVE_ERRORS_LIMIT (defaults to None)

# How long the consumer should wait for new entries in a stream.
# As we are running the consumer in a while True loop, changing this setting doesn't make much difference
# expect for changing number of monitoring messages while waiting for new events.
# https://redis.io/commands/xread/#blocking-for-data
#EVENT_BUS_REDIS_CONSUMER_POLL_TIMEOUT (defaults to 60 seconds)

# Limits stream size to approximately this number
#EVENT_BUS_REDIS_STREAM_MAX_LEN (defaults to 10_000)

BEAMER_PRODUCT_ID = ""

#### Survey Report ####
Expand Down
5 changes: 3 additions & 2 deletions lms/envs/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ def get_env_setting(setting):
NOTIFICATIONS_EXPIRY = ENV_TOKENS.get('NOTIFICATIONS_EXPIRY', NOTIFICATIONS_EXPIRY)

############## Event bus producer ##############
EVENT_BUS_PRODUCER_CONFIG = merge_producer_configs(EVENT_BUS_PRODUCER_CONFIG,
ENV_TOKENS.get('EVENT_BUS_PRODUCER_CONFIG', {}))
EVENT_BUS_PRODUCER_CONFIG = merge_producer_configs(
EVENT_BUS_PRODUCER_CONFIG, ENV_TOKENS.get("EVENT_BUS_PRODUCER_CONFIG", {})
)
BEAMER_PRODUCT_ID = ENV_TOKENS.get('BEAMER_PRODUCT_ID', BEAMER_PRODUCT_ID)
2 changes: 2 additions & 0 deletions requirements/edx/github.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,5 @@
# django42 support PR merged but new release is pending.
# https://github.com/openedx/edx-platform/issues/33431
-e git+https://github.com/anupdhabarde/edx-proctoring-proctortrack.git@31c6c9923a51c903ae83760ecbbac191363aa2a2#egg=edx_proctoring_proctortrack
-e git+https://github.com/raccoongang/[email protected]#egg=openedx_events
git+https://github.com/openedx/[email protected]

0 comments on commit 8a3ccb7

Please sign in to comment.