49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""Вспомогательный модуль для постановки LDAP-операций в очередь retry."""
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _enqueue(operation: str, model_name: str, object_pk, payload: dict):
|
|
"""Ставит неудавшуюся LDAP-операцию в очередь для отложенного retry.
|
|
|
|
Создаёт запись LdapSyncQueue и сразу пытается запустить Celery-задачу.
|
|
Если Celery недоступен — periodic task process_ldap_queue подберёт позже.
|
|
"""
|
|
from employees.models import LdapSyncQueue
|
|
|
|
item = LdapSyncQueue.objects.create(
|
|
operation=operation,
|
|
model_name=model_name,
|
|
object_pk=str(object_pk),
|
|
payload=payload,
|
|
)
|
|
|
|
try:
|
|
from employees.tasks import process_ldap_queue_item
|
|
|
|
process_ldap_queue_item.delay(item.pk)
|
|
except Exception as exc:
|
|
logger.warning(
|
|
"Immediate LDAP queue dispatch failed; periodic retry will handle it",
|
|
extra={
|
|
"event": "ldap.queue.dispatch_failed",
|
|
"queue_id": item.pk,
|
|
"error_type": type(exc).__name__,
|
|
},
|
|
exc_info=True,
|
|
)
|
|
|
|
logger.info(
|
|
"LDAP operation enqueued",
|
|
extra={
|
|
"event": "ldap.queue.item_enqueued",
|
|
"queue_id": item.pk,
|
|
"ldap_operation": operation,
|
|
"ldap_model": model_name,
|
|
"object_id": object_pk,
|
|
},
|
|
)
|
|
return item
|