...

Source file src/github.com/launchdarkly/go-server-sdk/v6/interfaces/data_store_status_provider.go

Documentation: github.com/launchdarkly/go-server-sdk/v6/interfaces

     1  package interfaces
     2  
     3  // DataStoreStatusProvider is an interface for querying the status of a persistent data store.
     4  //
     5  // An implementation of this interface is returned by
     6  // [github.com/launchdarkly/go-server-sdk/v6.LDClient.GetDataStoreStatusProvider]. Application code
     7  // should not implement this interface.
     8  //
     9  // There are two ways to interact with the data store status. One is to simply get the current status; if
    10  // its Available property is true, then the store is working normally.
    11  //
    12  //	status := client.GetDataStoreStatusProvider().GetStatus()
    13  //	isValid = status.Available
    14  //
    15  // Second, you can use AddStatusListener to get a channel that provides a status update whenever the
    16  // data store has an error or starts working again.
    17  //
    18  //	statusCh := client.GetDataStoreStatusProvider().AddStatusListener()
    19  //	go func() {
    20  //	    for newStatus := range statusCh {
    21  //	        log.Printf("data store Available is %t", newStatus.Available)
    22  //	    }
    23  //	}()
    24  type DataStoreStatusProvider interface {
    25  	// GetStatus returns the current status of the store.
    26  	//
    27  	// This is only meaningful for persistent stores, or any other DataStore implementation that makes use of
    28  	// the reporting mechanism that is provided by DataStoreUpdateSink. For the default in-memory store, the
    29  	// status will always be reported as "available".
    30  	GetStatus() DataStoreStatus
    31  
    32  	// Indicates whether the current data store implementation supports status monitoring.
    33  	//
    34  	// This is normally true for all persistent data stores, and false for the default in-memory store. A true
    35  	// value means that any listeners added with AddStatusListener() can expect to be notified if there is
    36  	// there is any error in storing data, and then notified again when the error condition is resolved. A
    37  	// false value means that the status is not meaningful and listeners should not expect to be notified.
    38  	IsStatusMonitoringEnabled() bool
    39  
    40  	// AddStatusListener subscribes for notifications of status changes. The returned channel will receive a
    41  	// new DataStoreStatus value for any change in status.
    42  	//
    43  	// Applications may wish to know if there is an outage in a persistent data store, since that could mean
    44  	// that flag evaluations are unable to get the flag data from the store (unless it is currently cached) and
    45  	// therefore might return default values.
    46  	//
    47  	// If the SDK receives an exception while trying to query or update the data store, then it publishes a
    48  	// DataStoreStatus where Available is false, to indicate that the store appears to be offline, and begins
    49  	// polling the store at intervals until a query succeeds. Once it succeeds, it publishes a new status where
    50  	// Available is true.
    51  	//
    52  	// If the data store implementation does not support status tracking, such as if you are using the default
    53  	// in-memory store rather than a persistent store, it will return a channel that never receives values.
    54  	//
    55  	// It is the caller's responsibility to consume values from the channel. Allowing values to accumulate in
    56  	// the channel can cause an SDK goroutine to be blocked. If you no longer need the channel, call
    57  	// RemoveStatusListener.
    58  	AddStatusListener() <-chan DataStoreStatus
    59  
    60  	// RemoveStatusListener unsubscribes from notifications of status changes. The specified channel must be
    61  	// one that was previously returned by AddStatusListener(); otherwise, the method has no effect.
    62  	RemoveStatusListener(<-chan DataStoreStatus)
    63  }
    64  
    65  // DataStoreStatus contains information about the status of a data store, provided by [DataStoreStatusProvider].
    66  type DataStoreStatus struct {
    67  	// Available is true if the SDK believes the data store is now available.
    68  	//
    69  	// This property is normally true. If the SDK receives an exception while trying to query or update the
    70  	// data store, then it sets this property to false (notifying listeners, if any) and polls the store at
    71  	// intervals until a query succeeds. Once it succeeds, it sets the property back to true (again
    72  	// notifying listeners).
    73  	Available bool
    74  
    75  	// NeedsRefresh is true if the store may be out of date due to a previous outage, so the SDK should
    76  	// attempt to refresh all feature flag data and rewrite it to the store.
    77  	//
    78  	// This property is not meaningful to application code.
    79  	NeedsRefresh bool
    80  }
    81  

View as plain text