Skip to content
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

refactor: Implement sync client without event loop #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nemeckova-s
Copy link

Outcome of our Xmax hackathon 2024

Copy link
Collaborator

@asgeirrr asgeirrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of thoughts from seeing the whole picture together. Looks great 😍

)
"""https://elis.rossum.ai/api/docs/#search-for-annotations."""
validate_search_params(query, query_string)
json_payload = build_search_params(query, query_string)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I would rename this variable to search_params

return self._run_coroutine(
self.elis_api_client.poll_annotation_until_imported(annotation_id, **poll_kwargs)
)
return self.poll_task(task_id, lambda a: a.status == TaskStatus.SUCCEEDED, sleep_s)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would be worth extracting this lambda to a function in domain logic like we did with is_annotation_imported


def delete_annotation(self, annotation_id: int) -> None:
"""https://elis.rossum.ai/api/docs/#switch-to-deleted"""
return self._run_coroutine(self.elis_api_client.delete_annotation(annotation_id))
self.internal_client.request(
"POST", url=f"{Resource.Annotation.value}/{annotation_id}/delete"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create little functions for all these URLs in domain_logic.urls for re-usability. They're kind of dumb but it's imho worth it.

raise AlwaysRetry()
self._raise_for_status(response)
for chunk in response.iter_bytes():
yield chunk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: We're not in async anymore, we can do yield from response.iter_bytes() or probably even return response.iter_bytes()

json,
**filters,
):
yield result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: return self.fetch_resources_by_url(... should work.

) -> Iterator[dict[str, Any]]:
query_params = build_pagination_params(ordering)
query_params.update(build_sideload_params(sideloads, content_schema_ids))
query_params.update(**filters)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion but we could create a higher level function build_fetch_resources_params(ordering, sideloads, content_schema_ids)


if sideloads:
self.internal_client.sideload(annotation_response, sideloads)
return self._deserializer(resource, annotation_response)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember we were not happy about this part during the hackaton. I think we could simplify this at the expense of 1 extra API call at the end (fetching the annotation once more instead of just the sideloads).

        annotation = self.retrieve_annotation(annotation_id)

        while not predicate(annotation):
            time.sleep(sleep_s)
            annotation = self.retrieve_annotation(annotation_id)

        return self.retrieve_annotation(annotation_id, sideloads)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants