Skip to content
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

Updater improvements #1018

Merged
merged 8 commits into from
Mar 2, 2018
Merged

Updater improvements #1018

merged 8 commits into from
Mar 2, 2018

Conversation

tsnoam
Copy link
Member

@tsnoam tsnoam commented Feb 22, 2018

  • Refactor bootstrap phase to be resilient for network errors
  • Improved unitests for polling updater

fixes #605

@tsnoam tsnoam requested a review from Eldinnie February 22, 2018 12:14
while 1:
def _bootstrap(self, max_retries, clean, webhook_url, allowed_updates, cert=None,
bootstrap_interval=5):
retries = [0]
Copy link
Member

Choose a reason for hiding this comment

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

Why did you make this a list? It's still only used for one int value

Copy link
Member Author

Choose a reason for hiding this comment

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

Because otherwise it will overridden as a local variable of the inner function.
A different workaround would be to do:

global retries
retries = 0

But I don't like global inside such an inner code.
Of course we can do it a class method or something more "generic" but then we'll lose code locality.
If you can think of something else, I'll be happy for a more elegant solution.

return False

def bootstrap_clean_updates():
self._clean_updates()
Copy link
Member

Choose a reason for hiding this comment

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

The _clean_updates() method is only ever called once here. I suggest the code is added in this place.

Copy link
Member Author

Choose a reason for hiding this comment

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

mmm... I tried not to touch _clean_updates() (move less code if possible)
but I guess you're right, code locality is preferred here.

sleep(1)

self._network_loop_retry(bootstrap_set_webhook, bootstrap_onerr_cb,
Copy link
Member

Choose a reason for hiding this comment

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

If I read it right, this means a webhook is set when Updater.start_polling is called, but with an empty url. This is an unnecessary API call to a method that is prone to flood actions. I would like to prevent it.
Also see the comment on delete webhook

Copy link
Member Author

@tsnoam tsnoam Mar 1, 2018

Choose a reason for hiding this comment

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

This call was "written in blood".
If user had messed around with webhooks and now he wants a polling server, we make sure that Telegram servers are properly configured for it.
@jh0ker Maybe you remember the origin of this better?

else:
self.logger.exception(msg)
raise
def bootstrap_del_webhook():
Copy link
Member

Choose a reason for hiding this comment

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

This is also called when Updater.start_webhook() is called, but this is not necessary. However the set/delete_webhook methods are prone to flood limits. I would like to prevent that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.
@jh0ker ?

raise
self.logger.debug('{0} - ended'.format(thr_name))

def start_polling(self,
poll_interval=0.0,
timeout=10,
clean=False,
bootstrap_retries=0,
bootstrap_retries=-1,
Copy link
Member

Choose a reason for hiding this comment

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

The docstring doesn;t reflect this change to the default value

Copy link
Member Author

Choose a reason for hiding this comment

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

will fix

@Eldinnie
Copy link
Member

Eldinnie commented Mar 1, 2018

I just left some review comments.
Some small, but regarding the _bootstrap() method I would really like to avoid unnecessary API calls regarding the webhook methods if possible. You see a way to change that?

@Eldinnie
Copy link
Member

Eldinnie commented Mar 2, 2018

Yes good!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

During updater bootstrap phase, retry on network errors
2 participants