Skip to content

Commit

Permalink
Start extracting service policy boilerplate to common function (#5141)
Browse files Browse the repository at this point in the history
We would like to use the Cockatiel library in our service classes to
ensure that requests are retried using the circuit breaker pattern. Some
of our service classes do this already, but we are copying and pasting
the code around.

This commit extracts some of the boilerplate code to a new function in
the `@metamask/controller-utils` package, `createServicePolicy`, so that
we no longer have to do this. Because it would require an enormous
amount of tests, this commit does not include a complete version of
`createServicePolicy`, omitting options such as `maxRetries` as well as
an `onDegraded` callback so consumers can handle slow requests. Those
will be added later.
  • Loading branch information
mcmire authored Jan 14, 2025
1 parent 4612b82 commit 6fdfbd7
Show file tree
Hide file tree
Showing 8 changed files with 802 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/controller-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `createServicePolicy` function to assist with reducing boilerplate for service classes ([#5053](https://github.com/MetaMask/core/pull/5053))

## [11.4.5]

### Changed
Expand Down
2 changes: 1 addition & 1 deletion packages/controller-utils/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 78.12,
functions: 85.41,
functions: 84.61,
lines: 87.3,
statements: 86.5,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/controller-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@types/bn.js": "^5.1.5",
"bignumber.js": "^9.1.2",
"bn.js": "^5.2.1",
"cockatiel": "^3.1.2",
"eth-ens-namehash": "^2.0.8",
"fast-deep-equal": "^3.1.3"
},
Expand All @@ -65,6 +66,7 @@
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"nock": "^13.3.1",
"sinon": "^9.2.4",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
Expand Down
Loading

0 comments on commit 6fdfbd7

Please sign in to comment.