Support not pausing connectors on initialization failure

This commit is contained in:
Weves 2025-02-04 17:44:59 -08:00 committed by Chris Weaver
parent 1c12ab31f9
commit 8eb4320f76
2 changed files with 23 additions and 11 deletions

View File

@ -11,6 +11,7 @@ from onyx.background.indexing.checkpointing import get_time_windows_for_index_at
from onyx.background.indexing.tracer import OnyxTracer from onyx.background.indexing.tracer import OnyxTracer
from onyx.configs.app_configs import INDEXING_SIZE_WARNING_THRESHOLD from onyx.configs.app_configs import INDEXING_SIZE_WARNING_THRESHOLD
from onyx.configs.app_configs import INDEXING_TRACER_INTERVAL from onyx.configs.app_configs import INDEXING_TRACER_INTERVAL
from onyx.configs.app_configs import LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE
from onyx.configs.app_configs import POLL_CONNECTOR_OFFSET from onyx.configs.app_configs import POLL_CONNECTOR_OFFSET
from onyx.configs.constants import DocumentSource from onyx.configs.constants import DocumentSource
from onyx.configs.constants import MilestoneRecordType from onyx.configs.constants import MilestoneRecordType
@ -55,6 +56,7 @@ def _get_connector_runner(
start_time: datetime, start_time: datetime,
end_time: datetime, end_time: datetime,
tenant_id: str | None, tenant_id: str | None,
leave_connector_active: bool = LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE,
) -> ConnectorRunner: ) -> ConnectorRunner:
""" """
NOTE: `start_time` and `end_time` are only used for poll connectors NOTE: `start_time` and `end_time` are only used for poll connectors
@ -76,20 +78,25 @@ def _get_connector_runner(
) )
except Exception as e: except Exception as e:
logger.exception(f"Unable to instantiate connector due to {e}") logger.exception(f"Unable to instantiate connector due to {e}")
# since we failed to even instantiate the connector, we pause the CCPair since
# it will never succeed
cc_pair = get_connector_credential_pair_from_id( # since we failed to even instantiate the connector, we pause the CCPair since
db_session=db_session, # it will never succeed. Sometimes there are cases where the connector will
cc_pair_id=attempt.connector_credential_pair.id, # intermittently fail to initialize in which case we should pass in
) # leave_connector_active=True to allow it to continue.
if cc_pair and cc_pair.status == ConnectorCredentialPairStatus.ACTIVE: # For example, if there is nightly maintenance on a Confluence Server instance,
update_connector_credential_pair( # the connector will fail to initialize every night.
if not leave_connector_active:
cc_pair = get_connector_credential_pair_from_id(
db_session=db_session, db_session=db_session,
connector_id=attempt.connector_credential_pair.connector.id, cc_pair_id=attempt.connector_credential_pair.id,
credential_id=attempt.connector_credential_pair.credential.id,
status=ConnectorCredentialPairStatus.PAUSED,
) )
if cc_pair and cc_pair.status == ConnectorCredentialPairStatus.ACTIVE:
update_connector_credential_pair(
db_session=db_session,
connector_id=attempt.connector_credential_pair.connector.id,
credential_id=attempt.connector_credential_pair.credential.id,
status=ConnectorCredentialPairStatus.PAUSED,
)
raise e raise e
return ConnectorRunner( return ConnectorRunner(

View File

@ -409,6 +409,11 @@ EXPERIMENTAL_CHECKPOINTING_ENABLED = (
os.environ.get("EXPERIMENTAL_CHECKPOINTING_ENABLED", "").lower() == "true" os.environ.get("EXPERIMENTAL_CHECKPOINTING_ENABLED", "").lower() == "true"
) )
LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE = (
os.environ.get("LEAVE_CONNECTOR_ACTIVE_ON_INITIALIZATION_FAILURE", "").lower()
== "true"
)
PRUNING_DISABLED = -1 PRUNING_DISABLED = -1
DEFAULT_PRUNING_FREQ = 60 * 60 * 24 # Once a day DEFAULT_PRUNING_FREQ = 60 * 60 * 24 # Once a day