Skip to content

async client support#276

Open
bshakur8 wants to merge 1 commit intoRamiAwar:mainfrom
bshakur8:async
Open

async client support#276
bshakur8 wants to merge 1 commit intoRamiAwar:mainfrom
bshakur8:async

Conversation

@bshakur8
Copy link
Copy Markdown

@bshakur8 bshakur8 commented Mar 27, 2023

Description

Add AsyncElasticsearch support.

Related Issue

#35

Type of Change

  • 🚀 New feature (non-breaking change which adds functionality)

Checklist

  • I've read the CODE_OF_CONDUCT.md document.
  • I've read the CONTRIBUTING.md guide.
  • I've updated the code style using make codestyle.
  • I've written tests for all new methods and classes that I created.
  • I've written the docstring in Google format for all the methods and classes that I used.

Copy link
Copy Markdown
Author

@bshakur8 bshakur8 Mar 27, 2023

Choose a reason for hiding this comment

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

I know it's a duplicate code. My suggestion is to separate it to pre & post functions for each save, get and delete functions. Those pre&post function will be shared between ESModel and ESAsyncModel.
The only difference between them is that the later will use await in AsyncES client function.

For example:

def save(<args>)
    kwargs = pre_save(<args>)
    result = client.save(**kwargs)
    return post_save(result)
    
    
async def save(<args>)
    kwargs = pre_save(<args>)
    result = await client.save(**kwargs)
    return post_save(result)

@RamiAwar Do you agree with this approach or do you have a better one?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Sorryy totally missed this! Will check

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Okay, here are my thoughts @bshakur8:

  • The operation classes are a bit of an overkill - they make understanding the code much more complicated. Having a little bit of duplication is better if it makes maintenance and extendability easier. Maybe functions are a better alternative here. Maybe we can put the pre- and post- logic in functions that we'd then simply call in both clients.

  • We should have 2 clients - an async one and a sync one. I don't like the idea of supporting sync and async operations on the same client as it's complicating something that should be simple. Users will either use the sync client, or they will use the async client, never both. Also every other ORM I've seen uses this same idea, so we shouldn't stray from the standard.

  • The tests look amazing, the async logic looks solid. That's for that! We'll definitely merge that in as soon as we address the first two points.

What do you think? I'm willing to draft a more detailed suggestion if you want.

@bshakur8 bshakur8 force-pushed the async branch 3 times, most recently from d97b3c1 to 184a766 Compare April 2, 2023 13:43
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.

3 participants