# Surprise Async ! (in python)
9pm and I am finished with my work.
This is fine, they think i'm old and slow. I think I make
way less errors especially the first time.
I'm not complaining (well obviously i am :P, but i don't
expect better i guess i mean).
Today's slow down was "surprise all that python you wrote needed
to be async" :)
We should be using golang here. I mean that practically given the
programmers we have. Actually idk ... I just assume golang
will work well on Azure stuff (mostly Azure Functions).
That's where the surprise async comes from. I'm still getting
a feel for regular sync vs. async. I'm more comfortable with it
now, meaning I have a decent idea when to use it. Usually for
me that means following whoever made that decision before me.
I think that's where the "async is a virus" idea comes from.
Once you are using it in a section, it all has to be async.
Which can not always be obvious in shared code.
I had to duplicate some elasticsearch_dsl code to work
in both sync and async. I really tried to use multiple inheritance
to not have to duplicate a Document class's field definitions.
But 1. I don't really ever want to use multiple inheritance and 2.
it wasn't working anyways.
If I knew this was going to happen I would have used regular
long form elasticsearch code, because it's driven by just dictionaries
and those could definitely have been shared commonly between
the sync and async bits. But I was too far down this path [0] so
I went with duplicating one of the table/index classes with
some comments saying they need to stay in sync.
If you are following this far ... well wow, I think that's awesome.
Thanks. The sync class is just to initialize an elasticsearch index
once. Like it will run once in each environment and then proceed
to be a no-op for the rest of eternity. Otherwise it's all async and
await funny business.
[0] Too far down the path of using the higher level elasticsearch_dsl
python library. Which wraps the otherwise normal http(s) requests
in python code with DSL like search stuff. The regular elasticsearch
python (non _dsl) is just a thinner layer over REST style GET/POST
JSON calls. So it's more verbose, but also kinda nice because you
can see you are just making REST calls.
#techpost #python #async #elasticsearch #azure