Skip to content

WIP: Refactor MQ #2160

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

Closed
wants to merge 20 commits into from
Closed

WIP: Refactor MQ #2160

wants to merge 20 commits into from

Conversation

Bibo-Joshi
Copy link
Member

@Bibo-Joshi Bibo-Joshi commented Oct 25, 2020

Got started on close #2139

Still missing:

  • some docs
  • tests
  • MQ.add/remove_delay_queue
  • error handling
  • handle stopping of the MQ
  • use telegram.constants instead of hardcoding the defaults for max messages per interval
  • Add tests for ensuring MQ works with defaults and also explicitly test for Defaults.delay_queue(_per_method). Forgot about those before marking as ready for review …
  • Use the new versioning directives

Just for automatic issue closing:

closes #2015 closes #2012 closes #2035 closes #1369

@Bibo-Joshi Bibo-Joshi marked this pull request as ready for review November 26, 2020 18:21
@Bibo-Joshi
Copy link
Member Author

I just realized that the handling of streams this PR introduces is immature. It

  • makes Promise assume that every stream is supposed to be converted into in InputFile, isn't necessarily the case for running custom functions through Dispatcher.run_async. Then again, using Dispatcher.run_async with context managers for reading files into custom functions will not work in either case …
  • doesn't pass additional arguments to InputFile (or parse_file_input, which will be used after API 5.0 WP4.3: Handling of files in local mode #2223)

Possible ways I see:

  1. Just don't handle it. opening files is the only context manager situation we can control in the first place, so it may not be worth making an effort for it. We just document that context managers don't work with promises in general.

  2. Try to handle at least file-context managers for bot methods. Sketch of an idea:

    @mq(input_file_args={'media': {'filename': 'filename', attach=True, 'tg_type': Audio}})
    def bot_method(media, filename, *args):
        …

    so that the @mq decorator can do the handling of file input for the specified arguments, looking up values for parse_file_input in the other arguments. Ofc. this leads to some code duplication and is rather hacky.

For the moment I think I'd be fine with 1., i.e. just not handling it.

# Conflicts:
#	telegram/bot.py
#	telegram/ext/defaults.py
#	tests/test_bot.py
@Bibo-Joshi
Copy link
Member Author

Bibo-Joshi commented Dec 3, 2020

In fact just not supporting context managers will not lead to any major issues for users once #2230 is implemented as

with open('file', 'rb): as file:
    bot.send_document(chat_id, file)

can then be replaced by

with open('file', 'rb): as file:
    bot.send_document(chat_id, file.read())

Edit: Went for it. The wiki page needs to be updated anyway, so we can just put a note there.

@Bibo-Joshi Bibo-Joshi added this to the v13.2 milestone Dec 17, 2020
Copy link
Member Author

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Some more thoughts. Also we should think about #2265

Edit: strictly speaking switching DQ.queue to a delay queue would be breaking

Second Edit: IMO message queue is not well established enough to care about that. The PR currently brings it in a proper state while keeping backwards compatibility as much as possible.

@Poolitzer
Copy link
Member

ready for review now right? GitHub already complains about a merge confilct you might wanna solve that ;P

@Bibo-Joshi
Copy link
Member Author

Closing for now as we'll go a different route (see #2139 for further details). Might still be worth revisiting later.

@Bibo-Joshi Bibo-Joshi closed this Jan 2, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jan 3, 2021
@Bibo-Joshi Bibo-Joshi deleted the refactor-mq branch August 27, 2022 09:02
@Bibo-Joshi Bibo-Joshi added 🔌 bug pr description: bug 🔌 enhancement pr description: enhancement and removed bug 🐛 labels Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔌 bug pr description: bug 🔌 enhancement pr description: enhancement
Projects
None yet
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy