Compare commits

..

2 Commits

Author SHA1 Message Date
pablodanswer
48998a5204 k 2025-02-15 11:22:37 -08:00
pablonyx
697f8bc1c6 Reduce background errors (#4004) 2025-02-14 17:35:26 -08:00
3 changed files with 32 additions and 17 deletions

View File

@@ -94,7 +94,6 @@ from onyx.db.models import User
from onyx.db.users import get_user_by_email
from onyx.redis.redis_pool import get_async_redis_connection
from onyx.redis.redis_pool import get_redis_client
from onyx.server.utils import BasicAuthenticationError
from onyx.utils.logger import setup_logger
from onyx.utils.telemetry import create_milestone_and_report
from onyx.utils.telemetry import optional_telemetry
@@ -108,6 +107,11 @@ from shared_configs.contextvars import CURRENT_TENANT_ID_CONTEXTVAR
logger = setup_logger()
class BasicAuthenticationError(HTTPException):
def __init__(self, detail: str):
super().__init__(status_code=status.HTTP_403_FORBIDDEN, detail=detail)
def is_user_admin(user: User | None) -> bool:
if AUTH_TYPE == AuthType.DISABLED:
return True

View File

@@ -61,6 +61,7 @@ class BookstackConnector(LoadConnector, PollConnector):
)
batch = bookstack_client.get(endpoint, params=params).get("data", [])
doc_batch = [transformer(bookstack_client, item) for item in batch]
return doc_batch, len(batch)
@@ -197,20 +198,31 @@ class BookstackConnector(LoadConnector, PollConnector):
for endpoint, transform in transform_by_endpoint.items():
start_ind = 0
while True:
doc_batch, num_results = self._get_doc_batch(
batch_size=self.batch_size,
bookstack_client=self.bookstack_client,
endpoint=endpoint,
transformer=transform,
start_ind=start_ind,
start=start,
end=end,
)
start_ind += num_results
if doc_batch:
yield doc_batch
try:
doc_batch, num_results = self._get_doc_batch(
batch_size=self.batch_size,
bookstack_client=self.bookstack_client,
endpoint=endpoint,
transformer=transform,
start_ind=start_ind,
start=start,
end=end,
)
start_ind += num_results
if doc_batch:
yield doc_batch
if num_results < self.batch_size:
if num_results < self.batch_size:
break
else:
time.sleep(0.2)
except Exception as e:
# Handle case where user hasn't properly set up permissions for the API key and we
# fail on a specific resource (e.g. /books, /chapters, etc.)
if (
"BookStack Client request failed with status 403: Forbidden"
in str(e)
):
raise
break
else:
time.sleep(0.2)

View File

@@ -251,7 +251,6 @@ def log_http_error(request: Request, exc: Exception) -> JSONResponse:
logger.debug(f"404 error for /metrics endpoint: {str(exc)}")
elif status_code >= 400:
print("FORMATTING ERROR")
error_msg = f"{str(exc)}\n"
error_msg += "".join(traceback.format_tb(exc.__traceback__))
logger.error(error_msg)