From 9f2086aec1c0f996e5b950a27de40aa83f99ad3b Mon Sep 17 00:00:00 2001 From: Brian Mesick Date: Tue, 13 Feb 2024 10:11:16 -0500 Subject: [PATCH] feat: Add a default consumer for login --- .../patches/local-docker-compose-services | 20 ++++++++++ ...penedx-dockerfile-post-python-requirements | 0 tutorevent_bus_redis/plugin.py | 38 +++++++++---------- 3 files changed, 39 insertions(+), 19 deletions(-) delete mode 100644 tutorevent_bus_redis/patches/openedx-dockerfile-post-python-requirements diff --git a/tutorevent_bus_redis/patches/local-docker-compose-services b/tutorevent_bus_redis/patches/local-docker-compose-services index 7e12281..e8ec9ed 100644 --- a/tutorevent_bus_redis/patches/local-docker-compose-services +++ b/tutorevent_bus_redis/patches/local-docker-compose-services @@ -67,3 +67,23 @@ kafka-control-center: CONFLUENT_METRICS_TOPIC_REPLICATION: 1 PORT: 9021 {% endif %} + +{% if EVENT_BUS_BACKEND %} +# This is just a stub test for showing how we could run consumers +login-consumer: + image: docker.io/overhangio/openedx:17.0.1-nightly + environment: + SERVICE_VARIANT: lms + DJANGO_SETTINGS_MODULE: lms.envs.tutor.production + command: > + ./manage.py lms consume_events -t user-login -g user-activity-service {% if EVENT_BUS_BACKEND == "redis" %}--extra '{"consumer_name": "user-login-1"}'{% endif %} + restart: unless-stopped + volumes: + - ../apps/openedx/settings/lms:/openedx/edx-platform/lms/envs/tutor:ro + - ../apps/openedx/settings/cms:/openedx/edx-platform/cms/envs/tutor:ro + - ../apps/openedx/config:/openedx/config:ro + - ../../data/lms:/openedx/data + - ../../data/openedx-media:/openedx/media + depends_on: + - {% if EVENT_BUS_BACKEND == "redis" %}redis{% elif EVENT_BUS_BACKEND == "kafka" %}kafka{% endif %} +{% endif %} diff --git a/tutorevent_bus_redis/patches/openedx-dockerfile-post-python-requirements b/tutorevent_bus_redis/patches/openedx-dockerfile-post-python-requirements deleted file mode 100644 index e69de29..0000000 diff --git a/tutorevent_bus_redis/plugin.py b/tutorevent_bus_redis/plugin.py index 77027ea..a5a0fbe 100644 --- a/tutorevent_bus_redis/plugin.py +++ b/tutorevent_bus_redis/plugin.py @@ -13,6 +13,24 @@ ######################################## # CONFIGURATION ######################################## +# FIXME: Update this to a saner config structure less likely to break, and able +# to activate and deactivate individual events more easily. +PRODUCER_CONFIG = """{ + 'org.openedx.content_authoring.xblock.published.v1': { + 'content-authoring-xblock-lifecycle': + {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, + 'content-authoring-xblock-published': + {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, + }, + 'org.openedx.content_authoring.xblock.deleted.v1': { + 'content-authoring-xblock-lifecycle': + {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, + }, + 'org.openedx.learning.auth.session.login.completed.v1': { + 'user-login': {'event_key_field': 'user.pii.username', 'enabled': True}, + }, +} +""" hooks.Filters.CONFIG_DEFAULTS.add_items( [ @@ -37,25 +55,7 @@ "confluent_kafka[avro,schema-registry]", ], ), - - # These are a subset of known events, there are many more. - # FIXME: Update this to a saner config structure less likely to break - ("EVENT_BUS_PRODUCER_CONFIG", """{ - 'org.openedx.content_authoring.xblock.published.v1': { - 'content-authoring-xblock-lifecycle': - {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, - 'content-authoring-xblock-published': - {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, - }, - 'org.openedx.content_authoring.xblock.deleted.v1': { - 'content-authoring-xblock-lifecycle': - {'event_key_field': 'xblock_info.usage_key', 'enabled': False}, - }, - 'org.openedx.learning.auth.session.login.completed.v1': { - 'user-login': {'event_key_field': 'user.pii.username', 'enabled': True}, - }, -} - """), + ("EVENT_BUS_PRODUCER_CONFIG", PRODUCER_CONFIG), ###################################### # redis backend settings