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

How to detect that reconnect_retries has been exceeded? #72

Closed
stefangotz opened this issue Nov 17, 2019 · 4 comments
Closed

How to detect that reconnect_retries has been exceeded? #72

stefangotz opened this issue Nov 17, 2019 · 4 comments

Comments

@stefangotz
Copy link

stefangotz commented Nov 17, 2019

When I set reconnect_retries to some value as documented in the README and I want my application to react to the fact that gmqtt has exceeded that number of retries and given up on reconnecting (e.g., to exit the application or to reconnect at a much later stage), how would I do that?

@Lenka42
Copy link
Collaborator

Lenka42 commented Nov 20, 2019

Hi @stefangotz
There is no special callback for the moment when client stops reconnecting
But the possible solution would be to check client.reconnect_retries property in on_disconnect callback

@stefangotz
Copy link
Author

Hi @Lenka42 !
How would that work?
When I register an on_disconnect call-back function, it is called once when the client transitions from connected to disconnected. The gmqtt client then makes 4 attempts to reconnect and then stops without calling my on_disconnect callback again. So I'm still not sure how my application can be notified and react when gmqtt has given up reconnecting?

@Lenka42
Copy link
Collaborator

Lenka42 commented Dec 2, 2019

@stefangotz sorry, my bad. Please try upgrade to gmqtt==0.5.0 and check the following:

def on_disconnect(client, packet, exc=None):
    if client. failed_connections > client.reconnect_retries:
        # app.on_client_disconnected_absolutely() 

I checked, and in your in case with reconnect_retries=4 last time on_disconnect was called with client.failed_connections=5
Let me know, if it works now.

@stefangotz
Copy link
Author

Hi @Lenka42 !

Thanks a lot for pointing that out! With v0.5, I do indeed no longer observe this issue. Resolved as far as I am concerned.

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

No branches or pull requests

2 participants