rveachkc / pymsteams

Format messages and post to Microsoft Teams.
https://pypi.org/project/pymsteams/
Apache License 2.0
422 stars 78 forks source link

'Promisify' the message shipment #71

Closed elChapoSing closed 2 years ago

elChapoSing commented 4 years ago

I am using MS Teams as my repository for some logging.

As you know, sending a message in a channel is quite slow and I don't really care about seeing it live as long as the info makes its way to the channel eventually.

So a perfect solution would be to promisify the actual message sending so I could basically continue my script while the message is being sent and decide (or not in that case) to do something about it once it is sent without waiting for the message to be sent before continuing.

Maybe this is already possible with existing tools in which case I'm very happy to get some pointers and work on it.

rveachkc commented 4 years ago

This isn't something I have a ton of time to play with at this point in time, but I would entertain a pull request.

A good fit for implementing a background thread would be ThreadPoolExecutor: Official Documentation: https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor Another Tutorial: https://www.digitalocean.com/community/tutorials/how-to-use-threadpoolexecutor-in-python-3

Unfortunately, using ThreadPoolExecutor would force writing either python3 compatible python2.7 code or dropping python 2 support. (but maybe it's time to do that anyway?) This could also be done using the threading library, but I'm not sure the effort is worth it.

Of course, this whole thing could be implemented directly in your own script directly without updating the library.

elChapoSing commented 4 years ago

Fair enough. I was thinking it would have been elegant if this was already built in the library. Unfortunately above my level to do it myself. As you said, I ended up threading it in my code directly (in case this is of interest to someone else : the SO question And about python2.x support : do get rid of it if it makes your life as a maintainer easier ! Thanks for the great work on this it's extremely useful to me.

rveachkc commented 2 years ago

Async sending was implemented with #105, and released in version 0.2.0.