Skip to content

feat: added switcher throttling capability#31

Merged
petruki merged 1 commit intomasterfrom
staging
Feb 15, 2026
Merged

feat: added switcher throttling capability#31
petruki merged 1 commit intomasterfrom
staging

Conversation

@petruki
Copy link
Member

@petruki petruki commented Feb 15, 2026

This pull request introduces and implements a throttling mechanism for remote API feature checks in the Switcher client, along with related configuration options and tests. The throttling feature caches recent results to avoid excessive API calls within a configurable period and adds support for background refresh using worker threads. Additionally, a utility method for serializing result details is added, and relevant documentation and tests are updated.

Throttling Feature Implementation:

  • Added a throttling mechanism to cache and reuse recent API check results within a specified period, reducing redundant remote calls. Throttling is enabled via the new throttle(period) method on Switcher, and background refresh is managed with a thread pool executor. (switcher_client/switcher.py [1] [2] [3] [4] [5]; switcher_client/switcher_data.py [6] [7]

  • Introduced the throttle_max_workers option in ContextOptions to control the maximum number of worker threads for background refresh tasks. (switcher_client/lib/globals/global_context.py [1]; README.md [2] [3]

API and Utility Enhancements:

  • Added a to_dict() method to the ResultDetail class for easier serialization of result details, improving integration with logging and test output. (switcher_client/lib/types.py switcher_client/lib/types.pyR21-R27)

Documentation Updates:

  • Updated the README.md to document the new throttling feature and configuration options, including usage examples and parameter descriptions. (README.md [1] [2] [3]

Testing Improvements:

  • Added and updated tests to verify throttling behavior, including caching, background refresh, and correct handling of throttle periods. Tests now also check the serialization of results and proper use of the new configuration options. (tests/test_switcher_throttle.py [1] [2] [3] [4]; tests/playground/index.py [5]; tests/playground/util.py [6]; tests/test_switcher_remote.py [7]

Minor Refactoring:

  • Cleaned up imports and removed the unused build target from the Makefile. (Makefile [1] [2]; switcher_client/lib/utils/__init__.py [3]

@petruki petruki self-assigned this Feb 15, 2026
@sonarqubecloud
Copy link

@petruki petruki merged commit 4d03299 into master Feb 15, 2026
15 checks passed
@petruki petruki deleted the staging branch February 15, 2026 23:06
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.

1 participant