mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-13 11:08:18 -06:00
Implement thread lock for change log signalling
This commit is contained in:
parent
a090955918
commit
9544519798
@ -1,11 +1,14 @@
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
|
|
||||||
|
import threading
|
||||||
from django.db.models.signals import m2m_changed, pre_delete, post_save
|
from django.db.models.signals import m2m_changed, pre_delete, post_save
|
||||||
|
|
||||||
from extras.signals import clear_webhooks, _clear_webhook_queue, _handle_changed_object, _handle_deleted_object
|
from extras.signals import clear_webhooks, _clear_webhook_queue, _handle_changed_object, _handle_deleted_object
|
||||||
from utilities.utils import curry
|
from utilities.utils import curry
|
||||||
from .webhooks import flush_webhooks
|
from .webhooks import flush_webhooks
|
||||||
|
|
||||||
|
changelog_lock = threading.Lock()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def change_logging(request):
|
def change_logging(request):
|
||||||
@ -15,8 +18,11 @@ def change_logging(request):
|
|||||||
|
|
||||||
:param request: WSGIRequest object with a unique `id` set
|
:param request: WSGIRequest object with a unique `id` set
|
||||||
"""
|
"""
|
||||||
|
|
||||||
webhook_queue = []
|
webhook_queue = []
|
||||||
|
|
||||||
|
with changelog_lock:
|
||||||
|
|
||||||
# Curry signals receivers to pass the current request
|
# Curry signals receivers to pass the current request
|
||||||
handle_changed_object = curry(_handle_changed_object, request, webhook_queue)
|
handle_changed_object = curry(_handle_changed_object, request, webhook_queue)
|
||||||
handle_deleted_object = curry(_handle_deleted_object, request, webhook_queue)
|
handle_deleted_object = curry(_handle_deleted_object, request, webhook_queue)
|
||||||
@ -37,6 +43,7 @@ def change_logging(request):
|
|||||||
pre_delete.disconnect(handle_deleted_object, dispatch_uid='handle_deleted_object')
|
pre_delete.disconnect(handle_deleted_object, dispatch_uid='handle_deleted_object')
|
||||||
clear_webhooks.disconnect(clear_webhook_queue, dispatch_uid='clear_webhook_queue')
|
clear_webhooks.disconnect(clear_webhook_queue, dispatch_uid='clear_webhook_queue')
|
||||||
|
|
||||||
|
|
||||||
# Flush queued webhooks to RQ
|
# Flush queued webhooks to RQ
|
||||||
flush_webhooks(webhook_queue)
|
flush_webhooks(webhook_queue)
|
||||||
del webhook_queue
|
del webhook_queue
|
||||||
|
Loading…
Reference in New Issue
Block a user