Coder Social home page Coder Social logo

Retry mechanism about fuels-ts HOT 5 CLOSED

digorithm avatar digorithm commented on May 27, 2024 2
Retry mechanism

from fuels-ts.

Comments (5)

arboleya avatar arboleya commented on May 27, 2024 3

Great idea; transient failures should indeed be accounted for. We could have a simple option like this (below) and have an internal retry pattern strategy with exponential back-off.

// if nothing is specified, we could have a default maxRetries=5
contract.functions.xyz(params).call({ maxRetries: 5 });

@digorithm Is there something like this on the Rust SDK already?

from fuels-ts.

digorithm avatar digorithm commented on May 27, 2024 2

That's a lot of complexity for very little gain. The JS ecosystem already suffers from way too many config files, I'd rather not contribute to that, haha.

And by very little gain I mean: gas price and many other transaction related configurations are mostly configured per call, usually being dynamically changed very quickly; often gas price being queried from external sources before a call happens. It isn't something that's set one time and the user rarely touches it. Retries does fit in this behaviour, though. But adding a whole new config file for just this value isn't justifiable.

from fuels-ts.

digorithm avatar digorithm commented on May 27, 2024 1

Nope, not yet. This API looks good to me!

from fuels-ts.

nedsalk avatar nedsalk commented on May 27, 2024

What about a global fuels.config.ts file in addition to @arboleya's proposal? The user then wouldn't have to set it on every .call() but could still use @arboleya's solution to override the defaults they set in fuels.config.

{
 maxRetries: 5,
 txParams: {
  gasPrice: 2
 },
 contracts: {
  maxRetries: 2,
  txParams: {
   gasPrice: 1
  }
 }
}

Or if we don't go down this route, we could put an optional options = {...theAbove...} parameter in all of our program constructors. We could even provide all three ways of setting configurations:

  1. global via fuels.config.ts,
  2. program-specific via constructors / property setters,
  3. call-specific via @arboleya's proposal

from fuels-ts.

nedsalk avatar nedsalk commented on May 27, 2024

Haha, yeah, makes sense. However, having to specify retries on a per-call basis might be cumbersome. A per-program config object passed via the constructor would alleviate some of that pain, so I think it's worth considering.

const myContract = new Contract(theAbi, ...whateverElse...,
 {
 maxRetries: 5, 
 retryStrategyCallback: (retryNumber, isLastRetry) => ({callAgain: true}),
 onCallFail: async () => await notifyTheWhiteHouse()
 })

The retryStrategyCallback and onCallFail are just examples of how easily extendable this config object would be. Functionality such as this would permit us to define sane defaults and also give the user the ability to override them if they choose to.

It could also be modified like below, although I'm not a fan because it's one more way for bugs to creep up:

myContract.configs.maxRetries = -1; // if negative, retry to infinity, etc.

from fuels-ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.