Skip to content

Conversation

@bartmoorman
Copy link
Contributor

This PR resolves 2 issues:

  1. Increase _revalidate_all's expires_in check from 300 seconds to 3600 seconds (added a 5 minute buffer) since the time between token validations is 55 minutes.
  2. Add an expires_in check to add_token. If the token will expire before the next validation (55 minutes + 5 minute buffer), refresh the token before adding it.

Logs showing changes are working as intended:

2025-03-03 17:16:04,446 DEBUG    twitchio.authentication.tokens Started the token validation loop on ManagedHTTPClient.
2025-03-03 17:16:04,446 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
2025-03-03 17:16:04,605 DEBUG    twitchio.authentication.tokens Token expires in 1665 seconds. Attempting to refresh.
2025-03-03 17:16:04,851 INFO     twitchio.authentication.tokens Token successfully added to TokenManager after refresh: "[bot]"
2025-03-03 17:16:04,894 DEBUG    twitchio.authentication.tokens Token successfully added to TokenManager: "[owner]"
2025-03-03 17:17:04,448 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
...
2025-03-03 20:02:05,313 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
2025-03-03 20:02:05,547 DEBUG    twitchio.authentication.tokens Token for "[owner]" expires in 2033 seconds. Attempting to refresh token.
2025-03-03 20:02:05,757 DEBUG    twitchio.authentication.tokens Token for "[owner]" was successfully refreshed.
2025-03-03 20:03:05,758 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
...
2025-03-03 20:57:05,841 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
2025-03-03 20:57:06,063 DEBUG    twitchio.authentication.tokens Token for "[bot]" expires in 1746 seconds. Attempting to refresh token.
2025-03-03 20:57:06,266 DEBUG    twitchio.authentication.tokens Token for "[bot]" was successfully refreshed.
2025-03-03 20:58:06,314 DEBUG    twitchio.authentication.tokens Attempting to revalidate all tokens that have passed the timeout on ManagedHTTPClient.
...

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
    • I have updated the changelog with a quick recap of my changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)
  • I have read and agree to the Developer Certificate of Origin for this contribution

@EvieePy
Copy link
Member

EvieePy commented Mar 22, 2025

I've added some additional logic to the tokens.py file, you will have to validate there is no conflicts with your logic.

@bartmoorman
Copy link
Contributor Author

I've added some additional logic to the tokens.py file, you will have to validate there is no conflicts with your logic.

Thank you for the heads up. I don't see any logic conflicts between the changes.

@EvieePy EvieePy merged commit 72fa2df into PythonistaGuild:main Mar 22, 2025
8 checks passed
@EvieePy
Copy link
Member

EvieePy commented Mar 22, 2025

👍

@bartmoorman bartmoorman deleted the refresh-token-if-expires-before-next-validation branch March 22, 2025 23:39
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

Successfully merging this pull request may close these issues.

2 participants