Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 Increase expiry time of redis webhook event locks #963

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shared/services/redis_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async def _extend_lock(self, lock_key: str, interval: datetime.timedelta) -> Non
lock_key: The Redis key of the lock to extend.
interval: Timedelta object representing how long to wait before extending the lock again.
"""
retry_interval = interval.total_seconds() * 0.9
retry_interval = interval.total_seconds() * 0.5
try:
while True:
await asyncio.sleep(retry_interval)
Expand Down
4 changes: 2 additions & 2 deletions webhooks/services/acapy_events_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ def _attempt_process_list_events(self, list_key: str) -> None:
lock_key = f"lock:{list_key}"
extend_lock_task = None

lock_duration = 500 # milliseconds
lock_duration = 2000 # milliseconds

if self.redis_service.set_lock(lock_key, px=lock_duration):
try:
# Start a background task to extend the lock periodically
# This is just to ensure that on the off chance that 500ms isn't enough to process all the
# This is just to ensure that on the off chance that 2000ms isn't enough to process all the
# events in the list, we want to avoid replicas processing the same webhook event twice
extend_lock_task = self.redis_service.extend_lock_task(
lock_key, interval=datetime.timedelta(milliseconds=lock_duration)
Expand Down
2 changes: 1 addition & 1 deletion webhooks/tests/services/test_acapy_events_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async def test_attempt_process_list_events(acapy_events_processor_mock):
acapy_events_processor_mock._attempt_process_list_events(event_key)

acapy_events_processor_mock.redis_service.set_lock.assert_called_with(
lock_key, px=500
lock_key, px=2000
)
acapy_events_processor_mock._process_list_events.assert_called_with(event_key)
acapy_events_processor_mock.redis_service.delete_key.assert_called_with(lock_key)
Expand Down
Loading