Skip to content

Commit

Permalink
chore: fix conflicts after rebasing with main
Browse files Browse the repository at this point in the history
  • Loading branch information
salman2013 committed Feb 19, 2024
2 parents 49ba742 + 8d7a182 commit 776299e
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 171 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/upgrade-python-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
branch: ${{ github.event.inputs.branch || 'main' }}
# optional parameters below; fill in if you'd like github or email notifications
# user_reviewers: ""
# team_reviewers: ""
# email_address: ""
team_reviewers: 'axim-aximprovements'
email_address: '[email protected]'
# send_success_notification: false
secrets:
requirements_bot_github_token: ${{ secrets.REQUIREMENTS_BOT_GITHUB_TOKEN }}
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Unreleased

*

[0.3.3] - 2023-10-13
************************************************

Added
=====
* Use utility from openedx_events to reset application state before processing
event

[0.3.2] - 2023-09-01
************************************************

Expand Down
4 changes: 2 additions & 2 deletions catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ metadata:
# We use it in Open edX repos to have a comma-separated list of GitHub user
# names that might be interested in changes to the architecture of this
# component.
openedx.org/arch-interest-groups: "bmtcril"
openedx.org/arch-interest-groups: ""
spec:

# (Required) This can be a group(`group:<group_name>` or a user(`user:<github_username>`)
owner: "user:bmtcril"
owner: "group:axim-engineering"

# (Required) Acceptable Type Values: service, website, library
type: 'library'
Expand Down
23 changes: 4 additions & 19 deletions edx_event_bus_redis/internal/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
from typing import Optional

from django.conf import settings
from django.db import connection
from edx_django_utils.monitoring import record_exception, set_custom_attribute
from edx_toggles.toggles import SettingToggle
from openedx_events.event_bus import EventBusConsumer
from openedx_events.event_bus.avro.deserializer import deserialize_bytes_to_event_data
from openedx_events.tooling import OpenEdxPublicSignal
from openedx_events.tooling import OpenEdxPublicSignal, prepare_for_new_work_cycle
from redis.exceptions import ConnectionError as RedisConnectionError
from redis.exceptions import ResponseError
from walrus import Database
Expand Down Expand Up @@ -70,21 +69,6 @@ class EventConsumptionException(Exception):
"""


def _reconnect_to_db_if_needed():
"""
Reconnects the db connection if needed.
This is important because Django only does connection validity/age checks as part of
its request/response cycle, which isn't in effect for the consume-loop. If we don't
force these checks, a broken connection will remain broken indefinitely. For most
consumers, this will cause event processing to fail.
"""
has_connection = bool(connection.connection)
requires_reconnect = has_connection and not connection.is_usable()
if requires_reconnect:
connection.connect()


class RedisEventConsumer(EventBusConsumer):
"""
Construct consumer for the given topic and group. The consumer can then
Expand Down Expand Up @@ -240,8 +224,9 @@ def _consume_indefinitely(self):
if isinstance(redis_raw_msg, list):
redis_raw_msg = redis_raw_msg[0]
msg = RedisMessage.parse(redis_raw_msg, self.full_topic)
# Before processing, make sure our db connection is still active
_reconnect_to_db_if_needed()
# Before processing, try to make sure our application state is cleaned
# up as would happen at the start of a Django request/response cycle.
prepare_for_new_work_cycle()
self.emit_signals_from_message(msg)
consecutive_errors = 0

Expand Down
2 changes: 1 addition & 1 deletion edx_event_bus_redis/internal/tests/test_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def test_consecutive_error_limit(self):
assert mock_emit.call_args_list == [call(self.normal_message)] * exception_count
assert exc_info.value.args == ("Too many consecutive errors, exiting (4 in a row)",)

@patch('edx_event_bus_redis.internal.consumer.connection')
@patch('openedx_events.tooling.connection')
@ddt.data(
(False, False, False), # no connection, don't reconnect
(True, False, True), # connection unusable, reconnect expected
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-c constraints.txt

Django # Web application framework
# openedx-events 8.0.0 removes an argument from consumer initialization
openedx-events>=8.0.0 # Events API
# openedx-events 9.5.0 adds utitily to reset app state
openedx-events>=9.5.0 # Events API
edx_django_utils
edx_toggles

Expand Down
31 changes: 16 additions & 15 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ asgiref==3.7.2
# via django
async-timeout==4.0.3
# via redis
attrs==23.1.0
attrs==23.2.0
# via openedx-events
cffi==1.16.0
# via pynacl
click==8.1.7
# via
# code-annotations
# edx-django-utils
code-annotations==1.5.0
code-annotations==1.6.0
# via edx-toggles
django==3.2.23
django==3.2.24
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# -r requirements/base.in
Expand All @@ -31,41 +31,42 @@ django-crum==0.7.9
# via
# edx-django-utils
# edx-toggles
django-waffle==4.0.0
django-waffle==4.1.0
# via
# edx-django-utils
# edx-toggles
edx-django-utils==5.8.0
edx-django-utils==5.10.1
# via
# -r requirements/base.in
# edx-toggles
# openedx-events
edx-opaque-keys[django]==2.5.1
# via openedx-events
edx-toggles==5.1.0
edx-toggles==5.1.1
# via -r requirements/base.in
fastavro==1.9.0
fastavro==1.9.3
# via openedx-events
jinja2==3.1.2
jinja2==3.1.3
# via code-annotations
markupsafe==2.1.3
markupsafe==2.1.5
# via jinja2
newrelic==9.2.0
newrelic==9.6.0
# via edx-django-utils
openedx-events==9.2.0
openedx-events==9.5.0
# via -r requirements/base.in
pbr==6.0.0
# via stevedore
psutil==5.9.6
psutil==5.9.8
# via edx-django-utils
pycparser==2.21
# via cffi
pymongo==3.13.0
# via edx-opaque-keys
pynacl==1.5.0
# via edx-django-utils
python-slugify==8.0.1
python-slugify==8.0.4
# via code-annotations
pytz==2023.3.post1
pytz==2024.1
# via django
pyyaml==6.0.1
# via code-annotations
Expand All @@ -80,7 +81,7 @@ stevedore==5.1.0
# edx-opaque-keys
text-unidecode==1.3
# via python-slugify
typing-extensions==4.8.0
typing-extensions==4.9.0
# via
# asgiref
# edx-opaque-keys
Expand Down
11 changes: 5 additions & 6 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chardet==5.2.0
# via tox
colorama==0.4.6
# via tox
distlib==0.3.7
distlib==0.3.8
# via virtualenv
filelock==3.13.1
# via
Expand All @@ -20,20 +20,19 @@ packaging==23.2
# via
# pyproject-api
# tox
platformdirs==3.11.0
platformdirs==4.2.0
# via
# -c https://raw.githubusercontent.com/edx/edx-lint/master/edx_lint/files/common_constraints.txt
# tox
# virtualenv
pluggy==1.3.0
pluggy==1.4.0
# via tox
pyproject-api==1.6.1
# via tox
tomli==2.0.1
# via
# pyproject-api
# tox
tox==4.11.3
tox==4.12.1
# via -r requirements/ci.in
virtualenv==20.24.6
virtualenv==20.25.0
# via tox
Loading

0 comments on commit 776299e

Please sign in to comment.