Title: Refactor MessageQueue · Issue #2139 · python-telegram-bot/python-telegram-bot · GitHub
Open Graph Title: Refactor MessageQueue · Issue #2139 · python-telegram-bot/python-telegram-bot
X Title: Refactor MessageQueue · Issue #2139 · python-telegram-bot/python-telegram-bot
Description: TL;DR: Known bugs are Defaults not working #2015 Hanging when using ctrl + c #2012 Context manager for opening file broken #2035 Shortcuts lost their *args and **kwargs #2392 Errors are being hidden #3201 Long version: Using MessageQueue...
Open Graph Description: TL;DR: Known bugs are Defaults not working #2015 Hanging when using ctrl + c #2012 Context manager for opening file broken #2035 Shortcuts lost their *args and **kwargs #2392 Errors are being hidde...
X Description: TL;DR: Known bugs are Defaults not working #2015 Hanging when using ctrl + c #2012 Context manager for opening file broken #2035 Shortcuts lost their *args and **kwargs #2392 Errors are being hidde...
Opengraph URL: https://github.com/python-telegram-bot/python-telegram-bot/issues/2139
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Refactor MessageQueue","articleBody":"# TL;DR:\r\n\r\nKnown bugs are \r\n\r\n- Defaults not working #2015\r\n- Hanging when using ctrl + c #2012 \r\n- Context manager for opening file broken #2035 \r\n- Shortcuts lost their *args and **kwargs #2392\r\n- Errors are being hidden #3201\r\n\r\n# Long version:\r\n\r\nUsing `MessageQueue` currently requires quite some manual work and there also the aformentioned bugs. Time to live up to the wikis statement\r\n\r\n> We plan to tightly couple it with telegram.Bot so that it could be used more conveniently (and even implicitly unless other specified).\r\n\r\nSo here is what my idea for a refactoring is. I'd be happy for feedback before getting started :)\r\n\r\n## Refactoring of `MessageQueue` and `DelayQueue`\r\n\r\n* `DQ.exc_route`: I'd like to rename to `error_handler` in accordance with `Dispatcher.add_error_handler`.\r\n* If a `Dispatcher` is used, it would make sense to have the execution of the promises to behave like the refactored `Dipsatcher._pooled`, which also includes proper error handling. That can be easily achieved by passing the `Dispatcher` to either the `Bot` or the `MessageQueue`. Not sure yet, what makes more sense …\r\n* I think I'd like to repace the `__call__` methods with `process` or whatever. That's more explicit and easier to read in the code.\r\n* Add `MQ.add/remove_delay_queue` so that users can add custom delay queues in addition to the default & the group one. One should be able to specify a parent (defaulting to the default DQ) for `new_dq`, such that everything going throguh `new_dq` will also go through the parent. `MQ.add_remove_delay_queue` sohuld also start/stop the `DQ` in case we're adding them at runtime. Edit: This will in fact close #1369 , as I just notice\r\n* Add constants for the default & the group DQ\r\n* Handle the stopping of `MQ` correctly, some hints are already given in #2012\r\n\r\n## Integration into Bot\r\n\r\nAdd a `MessageQueue` to `Bot` by default and rebuild all methods in the fashion\r\n\r\n```python\r\n\r\ndef badly_sketched_messagequeue_wrapper(func, *args, **kwargs):\r\n delay_queue = kwargs.pop('delay_queue')\r\n if delay_queue == self.message_queue.DEFAULT_DQ and int(kwargs.get('chat_id')) \u003c 0: \r\n return self.message_queue.process(func, self.message_queue.GROUP_DQ)\r\n elif delay_queue:\r\n return self.message_queue.process(func, delay_queue)\r\n return func(*args, **kwargs)\r\n\r\n@badly_sketched_messagequeue_wrapper\r\ndef send_message(…, delay_queue=None):\r\n ...\r\n```\r\n\r\nsuch that `delay_queue` allows to select the delay queue the method is passed through, replacing the current `queue` and `isgroup` kwargs\r\n\r\n* Together with the changes to `Bot.__new__` as in discussed #2015 , this should resolve #2015 \r\n* for cases where one only needs `Bot`, without `Dispatcher` or `Updater`, one could do something like\r\n\r\n```\r\ndef badly_sketched_messagequeue_wrapper(func, *args, **kwargs):\r\n if self.message_queue.is_running:\r\n # see above\r\n return func(*args, **kwargs)\r\n```\r\nso users can easily opt-into `MessageQueue` with `bot.mq.start/stop()`\r\n\r\n## Integration with `Defaults`\r\n\r\nAdd `Defaults.delay_queue` defaulting to `None` (I'm not in favor of implicitly always using the `MessageQueue`)\r\n\r\n## Handling context managers\r\n\r\nI think the approach detailed in #2035 is feasible (build `InputFiles` already in `Promise.__init__`). I can't think of any use case, where a context manager would be used for anything else that we'd to handle …\r\n\r\nEdit: Now I can. See #2160 \r\n\r\n## Backwards compatibility\r\n\r\nAll of above changes should be doable without breaking changes.\r\nHower, given that `MessageQueue` is essentially still in the same quite rough state as when introduced in #537 3.5 years ago, IMHO it would be okay to removethe current usage pattern (i.e. the `@queuedmessage` decorator) in the next major release (which probably will be mostly a \"delete all the stuff\" release anyway …)","author":{"url":"https://github.com/Bibo-Joshi","@type":"Person","name":"Bibo-Joshi"},"datePublished":"2020-10-12T17:27:04Z","url":"https://github.com/python-telegram-bot/python-telegram-bot/issues/2139"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:432acc32-b87f-cf6b-3277-ea4c5e27594c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B984:DB09F:48323A3:5BECFEF:6B025926 |
| html-safe-nonce | 7cf3f61fd3a773e141d7c6af222af00a59d585d27ba1e0aaeb4a8bc24037a524 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTg0OkRCMDlGOjQ4MzIzQTM6NUJFQ0ZFRjo2QjAyNTkyNiIsInZpc2l0b3JfaWQiOiI0MTA1MjMzNDM2NzA3NTQzMzM0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5445b057e7584fe7bd8278c9954cebbdfaeff3fa4e3bdc7b24669bb75d2a8209 |
| hovercard-subject-tag | issue:719540005 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python-telegram-bot/python-telegram-bot/2139/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e4488586dbe9440be62d400a3553bd1493810ae1b4c826b7eede4d66328f4e81/python-telegram-bot/python-telegram-bot/issues/2139 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e4488586dbe9440be62d400a3553bd1493810ae1b4c826b7eede4d66328f4e81/python-telegram-bot/python-telegram-bot/issues/2139 |
| og:image:alt | TL;DR: Known bugs are Defaults not working #2015 Hanging when using ctrl + c #2012 Context manager for opening file broken #2035 Shortcuts lost their *args and **kwargs #2392 Errors are being hidde... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Bibo-Joshi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python-telegram-bot/python-telegram-bot git https://github.com/python-telegram-bot/python-telegram-bot.git |
| octolytics-dimension-user_id | 16178365 |
| octolytics-dimension-user_login | python-telegram-bot |
| octolytics-dimension-repository_id | 38696925 |
| octolytics-dimension-repository_nwo | python-telegram-bot/python-telegram-bot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38696925 |
| octolytics-dimension-repository_network_root_nwo | python-telegram-bot/python-telegram-bot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width