This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from openedx/bmtcril/add_event_listener
Add Course Published event listener and plugin plumbing
- Loading branch information
Showing
24 changed files
with
1,402 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
Default settings for the openedx_event_sink_clickhouse app. | ||
""" | ||
|
||
|
||
def plugin_settings(settings): | ||
""" | ||
Adds default settings | ||
""" | ||
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG = { | ||
# URL to a running ClickHouse server's HTTP interface. ex: https://foo.openedx.org:8443/ or | ||
# http://foo.openedx.org:8123/ . Note that we only support the ClickHouse HTTP interface | ||
# to avoid pulling in more dependencies to the platform than necessary. | ||
"url": "http://clickhouse:8123", | ||
"username": "changeme", | ||
"password": "changeme", | ||
"database": "event_sink", | ||
"timeout_secs": 3, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Production settings for the openedx_event_sink_clickhouse app. | ||
""" | ||
|
||
|
||
def plugin_settings(settings): | ||
""" | ||
Override the default app settings with production settings. | ||
""" | ||
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG = settings.ENV_TOKENS.get( | ||
'EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG', | ||
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Signal handler functions, mapped to specific signals in apps.py. | ||
""" | ||
|
||
|
||
def receive_course_publish(sender, course_key, **kwargs): # pylint: disable=unused-argument | ||
""" | ||
Receives COURSE_PUBLISHED signal and queues the dump job. | ||
""" | ||
# import here, because signal is registered at startup, but items in tasks are not yet able to be loaded | ||
from .tasks import dump_course_to_clickhouse # pylint: disable=import-outside-toplevel | ||
|
||
dump_course_to_clickhouse.delay(str(course_key)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Base classes for event sinks | ||
""" | ||
from collections import namedtuple | ||
|
||
import requests | ||
from django.conf import settings | ||
|
||
ClickHouseAuth = namedtuple("ClickHouseAuth", ["username", "password"]) | ||
|
||
|
||
class BaseSink: | ||
""" | ||
Base class for ClickHouse event sink, allows overwriting of default settings | ||
""" | ||
def __init__(self, connection_overrides, log): | ||
self.log = log | ||
self.ch_url = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["url"] | ||
self.ch_auth = ClickHouseAuth(settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["username"], | ||
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["password"]) | ||
self.ch_database = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["database"] | ||
self.ch_timeout_secs = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["timeout_secs"] | ||
|
||
# If any overrides to the ClickHouse connection | ||
if connection_overrides: | ||
self.ch_url = connection_overrides.get("url", self.ch_url) | ||
self.ch_auth = ClickHouseAuth(connection_overrides.get("username", self.ch_auth.username), | ||
connection_overrides.get("password", self.ch_auth.password)) | ||
self.ch_database = connection_overrides.get("database", self.ch_database) | ||
self.ch_timeout_secs = connection_overrides.get("timeout_secs", self.ch_timeout_secs) | ||
|
||
def _send_clickhouse_request(self, request): | ||
""" | ||
Perform the actual HTTP requests to ClickHouse. | ||
""" | ||
session = requests.Session() | ||
prepared_request = request.prepare() | ||
|
||
try: | ||
response = session.send(prepared_request, timeout=self.ch_timeout_secs) | ||
response.raise_for_status() | ||
except requests.exceptions.HTTPError as e: | ||
self.log.error(str(e)) | ||
self.log.error(e.response.headers) | ||
self.log.error(e.response) | ||
self.log.error(e.response.text) | ||
raise |
Oops, something went wrong.