From 8a3ccb7bb0f1f48f26fc74921f3a50d5ec15b4e6 Mon Sep 17 00:00:00 2001 From: wowkalucky Date: Wed, 13 Mar 2024 18:52:53 +0200 Subject: [PATCH] feat: backport event bus configuration --- lms/djangoapps/grades/events.py | 41 +++++++++++++++++++++++++++++++++ lms/envs/common.py | 32 +++++++++++++++++++++++++ lms/envs/production.py | 5 ++-- requirements/edx/github.in | 2 ++ 4 files changed, 78 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/grades/events.py b/lms/djangoapps/grades/events.py index 90279a3e69f..21693b12d81 100644 --- a/lms/djangoapps/grades/events.py +++ b/lms/djangoapps/grades/events.py @@ -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 @@ -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): """ @@ -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): """ diff --git a/lms/envs/common.py b/lms/envs/common.py index 27e68903520..0d57934d5b9 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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://:password@edx.devstack.redis:6379/" +EVENT_BUS_TOPIC_PREFIX = "dev" + #### Event bus producing #### # .. setting_name: EVENT_BUS_PRODUCER_CONFIG # .. setting_default: all events disabled @@ -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 #### diff --git a/lms/envs/production.py b/lms/envs/production.py index d56a5631bb1..199997ab3cc 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -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) diff --git a/requirements/edx/github.in b/requirements/edx/github.in index ea6d47eec8a..51215f49a04 100644 --- a/requirements/edx/github.in +++ b/requirements/edx/github.in @@ -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/openedx-events.git@aci.main#egg=openedx_events +git+https://github.com/openedx/event-bus-redis.git@v0.4.0