Git Product home page Git Product logo

backoffcli's Introduction

Backoff CLI

Lisense Release GoReport

~# go run .\cmd\backoff\ -h                      
usage: backoff [<flags>] <path>

A command-line tool designed to implement and manage customizable backoff
strategies for retrying failed operations efficiently..


Flags:
  -h, --[no-]help              Show context-sensitive help (also try --help-long
                               and --help-man).
      --duration.initial=0s    initial wait seconds
      --duration.max=5m        max wait seconds
      --retry.max=0            max retry, 0 means unlimited
      --factor.exponent=1      exponent factor
      --factor.const.inter=0s  inter const factor
      --factor.const.outer=0s  outer const factor
      --name=NAME              pipe name for singleton, default generate by path
      --[no-]singleton         run with singleton parton with unique name

Args:
  <path>  program to run

Backoff Wait Time Calculating Logic

$Wait = duration.initial

for {
    if Fn_Succuess {
        quit
    }
    if HealthCheckExist && HealthCheckSuccess {
        $Wait = duration.initial
    } else {
        $Wait = ($Wait + factor.const.inter) * (2 ^ factor.exponent) + factor.const.outer
        $Wait = min($Wait, duration.max)
    }
    
    sleep($Wait)
}

Use as go library

go get github.com/Mmx233/BackoffCli/backoff
package main

import (
	"context"
	"github.com/Mmx233/BackoffCli/backoff"
	"time"
)

func main() {
	instance := backoff.New(func(ctx context.Context) error {
		// put logic here
		return nil
	}, backoff.Conf{
		Logger:           nil, // logrus logger
		DisableRecovery:  false,
		HealthChecker:    func(ctx context.Context) <-chan error {
			// health check logic
		},
		InitialDuration:  time.Second,
		MaxDuration:      time.Second*10,
		MaxRetry:         10,
		ExponentFactor:   1,
		InterConstFactor: time.Second,
		OuterConstFactor: time.Second,
	})

	if err := instance.Run(context.Background()); err != nil {
		panic(err)
	}
}

backoffcli's People

Contributors

mmx233 avatar

Watchers

 avatar

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.