go.mercari.io/datastore@v1.8.2/dsmiddleware/rpcretry/example_test.go (about)

     1  package rpcretry_test
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"go.mercari.io/datastore/clouddatastore"
     8  	"go.mercari.io/datastore/dsmiddleware/rpcretry"
     9  	"go.mercari.io/datastore/internal/testutils"
    10  )
    11  
    12  func Example_howToUse() {
    13  	ctx := context.Background()
    14  	client, err := clouddatastore.FromContext(ctx)
    15  	if err != nil {
    16  		panic(err)
    17  	}
    18  	defer client.Close()
    19  	defer testutils.CleanUpAllEntities(ctx, client)
    20  
    21  	mw := rpcretry.New(
    22  		rpcretry.WithRetryLimit(5),
    23  		rpcretry.WithMinBackoffDuration(10*time.Millisecond),
    24  		rpcretry.WithMaxBackoffDuration(150*time.Microsecond),
    25  		// rpcretry.WithMaxDoublings(2),
    26  	)
    27  	client.AppendMiddleware(mw)
    28  }