Skip to content

feat: add the ability to build policies from a map with a :type#2

Merged
k13gomez merged 1 commit intomainfrom
build-policy-map
Oct 22, 2025
Merged

feat: add the ability to build policies from a map with a :type#2
k13gomez merged 1 commit intomainfrom
build-policy-map

Conversation

@k13gomez
Copy link
Member

This PR introduces map-based policy building, allowing policies to be defined using plain Clojure maps with a :type key (e.g., {:type :retry :max-retries 3}). All six policy types (:retry, :circuit-breaker, :fallback, :timeout, :rate-limiter, :bulkhead) are supported and can be used directly with execute, execute-async, and executor functions. This enables configuration-driven setups where policies can be loaded from config files, environment variables, or other data sources.

Additionally, a new policies function is provided for explicitly creating reusable policy lists from regular policies, map-based policies, or mixed combinations. The implementation moves policy logic to failsage.impl (maintaining API compatibility via potemkin/import-vars) and extends the IPolicyBuilder protocol to support the Map interface. Comprehensive tests, documentation, and examples have been added for both features.

@gemini-code-assist
Copy link

Summary of Changes

Hello @k13gomez, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the flexibility and configurability of Failsage by introducing data-driven policy definitions. Users can now define resilience policies using simple Clojure maps, making it easier to manage policies from external configuration sources. This change streamlines policy creation and composition, supporting all existing policy types and integrating smoothly with current execution mechanisms, while maintaining API stability through internal refactoring.

Highlights

  • Map-based Policy Building: Introduced the ability to define all six Failsafe policy types (:retry, :circuit-breaker, :fallback, :timeout, :rate-limiter, :bulkhead) using plain Clojure maps with a :type key. This enables configuration-driven policy setups and easier serialization/deserialization.
  • Seamless Integration: Map-based policies can be used directly with execute, execute-async, and executor functions, and can be mixed with traditional function-based policies for flexible composition.
  • New policies Function: Added a policies function to explicitly create reusable policy lists from any combination of regular policies and map-based policies.
  • Internal Refactoring: Moved policy implementation functions from failsage.core to a new failsage.impl namespace. Public API compatibility is maintained using potemkin/import-vars.
  • IPolicyBuilder Extension: The IPolicyBuilder protocol has been extended to support IPersistentMap, allowing for automatic policy construction from map definitions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that introduces a valuable feature for defining policies from data maps. The implementation is clean, the refactoring of policy logic into failsage.impl improves code organization, and the use of potemkin/import-vars correctly maintains API compatibility. The new policies function is a thoughtful addition for creating reusable policy lists. The documentation and tests are comprehensive and of high quality. I've identified two minor areas for improvement: one to clarify a docstring and another to make the map-based policy building more robust and idiomatic. Overall, great work.

@k13gomez k13gomez requested review from bigodel and hiredman October 22, 2025 17:21
@k13gomez k13gomez force-pushed the build-policy-map branch 3 times, most recently from 58507ee to d3e0b91 Compare October 22, 2025 19:38
@k13gomez k13gomez merged commit b0c940b into main Oct 22, 2025
7 checks passed
@k13gomez k13gomez deleted the build-policy-map branch October 22, 2025 21:38
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