-
Notifications
You must be signed in to change notification settings - Fork 145
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
[Connector APIs] Connector update last sync info, status, error #2641
base: main
Are you sure you want to change the base?
Changes from 4 commits
512b524
1ffa5db
3906645
a2475a0
0d8a65e
b27b415
2016ac1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -700,12 +700,17 @@ def next_sync(self, job_type, now): | |
return next_run(scheduling_property.get("interval"), now) | ||
|
||
async def _update_datetime(self, field, new_ts): | ||
await self.index.update( | ||
doc_id=self.id, | ||
doc={field: iso_utc(new_ts)}, | ||
if_seq_no=self._seq_no, | ||
if_primary_term=self._primary_term, | ||
) | ||
if self.index.feature_use_connectors_api: | ||
await self.index.api.connector_update_last_sync_info( | ||
connector_id=self.id, last_sync_info={field: iso_utc(new_ts)} | ||
) | ||
else: | ||
await self.index.update( | ||
doc_id=self.id, | ||
doc={field: iso_utc(new_ts)}, | ||
if_seq_no=self._seq_no, | ||
if_primary_term=self._primary_term, | ||
) | ||
|
||
async def update_last_sync_scheduled_at_by_job_type(self, job_type, new_ts): | ||
match job_type: | ||
|
@@ -738,24 +743,43 @@ async def sync_starts(self, job_type): | |
msg = f"Unknown job type: {job_type}" | ||
raise ValueError(msg) | ||
|
||
doc = { | ||
"status": Status.CONNECTED.value, | ||
"error": None, | ||
} | last_sync_information | ||
if self.index.feature_use_connectors_api: | ||
await self.index.api.connector_update_last_sync_info( | ||
connector_id=self.id, last_sync_info=last_sync_information | ||
) | ||
await self.index.api.connector_update_status( | ||
connector_id=self.id, status=Status.CONNECTED.value | ||
) | ||
await self.index.api.connector_update_error( | ||
connector_id=self.id, error=None | ||
) | ||
else: | ||
doc = { | ||
"status": Status.CONNECTED.value, | ||
"error": None, | ||
} | last_sync_information | ||
|
||
await self.index.update( | ||
doc_id=self.id, | ||
doc=doc, | ||
if_seq_no=self._seq_no, | ||
if_primary_term=self._primary_term, | ||
) | ||
await self.index.update( | ||
doc_id=self.id, | ||
doc=doc, | ||
if_seq_no=self._seq_no, | ||
if_primary_term=self._primary_term, | ||
) | ||
|
||
async def error(self, error): | ||
doc = { | ||
"status": Status.ERROR.value, | ||
"error": str(error), | ||
} | ||
await self.index.update(doc_id=self.id, doc=doc) | ||
if self.index.feature_use_connectors_api: | ||
await self.index.api.connector_update_error( | ||
connector_id=self.id, error=error | ||
) | ||
await self.index.api.connector_update_status( | ||
connector_id=self.id, status=Status.ERROR.value | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here - this is an atomic action "mark as error" that updates status and writes error, should it be single action? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that we could unify this in a following way:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be perfect IMO! |
||
else: | ||
doc = { | ||
"status": Status.ERROR.value, | ||
"error": str(error), | ||
} | ||
await self.index.update(doc_id=self.id, doc=doc) | ||
|
||
async def sync_done(self, job, cursor=None): | ||
job_status = JobStatus.ERROR if job is None else job.status | ||
|
@@ -794,8 +818,6 @@ async def sync_done(self, job, cursor=None): | |
|
||
doc = { | ||
"last_synced": iso_utc(), | ||
"status": connector_status.value, | ||
"error": job_error, | ||
} | last_sync_information | ||
|
||
# only update sync cursor after a successful content sync job | ||
|
@@ -806,7 +828,19 @@ async def sync_done(self, job, cursor=None): | |
doc["last_indexed_document_count"] = job.indexed_document_count | ||
doc["last_deleted_document_count"] = job.deleted_document_count | ||
|
||
await self.index.update(doc_id=self.id, doc=doc) | ||
if self.index.feature_use_connectors_api: | ||
await self.index.api.connector_update_status( | ||
connector_id=self.id, status=connector_status.value | ||
) | ||
await self.index.api.connector_update_error( | ||
connector_id=self.id, error=job_error | ||
) | ||
await self.index.api.connector_update_last_sync_info( | ||
connector_id=self.id, last_sync_info=last_sync_information | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And same thing here - is there any chance we unite these three into one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See answer above about other 3 calls |
||
else: | ||
doc = doc | {"status": connector_status.value, "error": job_error} | ||
await self.index.update(doc_id=self.id, doc=doc) | ||
|
||
@with_concurrency_control() | ||
async def prepare(self, config, sources): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a little concerning - we do 3 calls to do single thing? Should we merge them into one call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could unify error and status endpoint in a single call (requires small ES adjustment). Set
status
as a function of error being null or non-null.However, I think we should maintain the _last_sync as a separate call. Integrating them would require expanding the last_sync_info endpoint with even more values in the request body (e.g. it would need to take error) - doable but then we are converging to
_update
like functionality.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, uniting status update + error update in one endpoint and leaving
update_last_sync_info
endpoint separately is a good way forward