github.com/blend/go-sdk@v1.20220411.3/status/tracked_action_config.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package status
     9  
    10  import (
    11  	"context"
    12  	"time"
    13  
    14  	"github.com/blend/go-sdk/configutil"
    15  )
    16  
    17  // TrackedActionConfig is the configuration for the tracker.
    18  type TrackedActionConfig struct {
    19  	YellowRequestCount      int
    20  	YellowRequestPercentage float64
    21  	RedRequestCount         int
    22  	RedRequestPercentage    float64
    23  	Expiration              time.Duration
    24  }
    25  
    26  // Resolve resolves the config.
    27  func (tc *TrackedActionConfig) Resolve(ctx context.Context) error {
    28  	return configutil.Resolve(ctx,
    29  		configutil.SetInt(&tc.YellowRequestCount,
    30  			configutil.Int(tc.YellowRequestCount),
    31  			configutil.Int(DefaultYellowRequestCount),
    32  		),
    33  		configutil.SetFloat64(&tc.YellowRequestPercentage,
    34  			configutil.Float64(tc.YellowRequestPercentage),
    35  			configutil.Float64(DefaultYellowRequestPercentage),
    36  		),
    37  		configutil.SetInt(&tc.RedRequestCount,
    38  			configutil.Int(tc.RedRequestCount),
    39  			configutil.Int(DefaultRedRequestCount),
    40  		),
    41  		configutil.SetFloat64(&tc.RedRequestPercentage,
    42  			configutil.Float64(tc.RedRequestPercentage),
    43  			configutil.Float64(DefaultRedRequestPercentage),
    44  		),
    45  		configutil.SetDuration(&tc.Expiration,
    46  			configutil.Duration(tc.Expiration),
    47  			configutil.Duration(DefaultTrackedActionExpiration),
    48  		),
    49  	)
    50  }
    51  
    52  // ExpirationOrDefault returns an expiration or a default.
    53  func (tc TrackedActionConfig) ExpirationOrDefault() time.Duration {
    54  	if tc.Expiration > 0 {
    55  		return tc.Expiration
    56  	}
    57  	return DefaultTrackedActionExpiration
    58  }