github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/compute/sensors/running_info.go (about)

     1  package sensors
     2  
     3  import (
     4  	"github.com/filecoin-project/bacalhau/pkg/compute"
     5  	"github.com/filecoin-project/bacalhau/pkg/compute/store"
     6  	"github.com/filecoin-project/bacalhau/pkg/model"
     7  )
     8  
     9  type RunningExecutionsInfoProviderParams struct {
    10  	Name          string
    11  	BackendBuffer *compute.ExecutorBuffer
    12  }
    13  
    14  // RunningExecutionsInfoProvider provides DebugInfo about the currently running executions.
    15  // The info can be used for logging, metric, or to handle /debug API implementation.
    16  type RunningExecutionsInfoProvider struct {
    17  	name          string
    18  	backendBuffer *compute.ExecutorBuffer
    19  }
    20  
    21  func NewRunningExecutionsInfoProvider(params RunningExecutionsInfoProviderParams) *RunningExecutionsInfoProvider {
    22  	return &RunningExecutionsInfoProvider{
    23  		name:          params.Name,
    24  		backendBuffer: params.BackendBuffer,
    25  	}
    26  }
    27  
    28  func (r RunningExecutionsInfoProvider) GetDebugInfo() (model.DebugInfo, error) {
    29  	executions := r.backendBuffer.RunningExecutions()
    30  	summaries := make([]store.ExecutionSummary, 0, len(executions))
    31  	for _, execution := range executions {
    32  		summaries = append(summaries, store.NewExecutionSummary(execution))
    33  	}
    34  
    35  	return model.DebugInfo{
    36  		Component: r.name,
    37  		Info:      summaries,
    38  	}, nil
    39  }
    40  
    41  // compile-time check that we implement the interface
    42  var _ model.DebugInfoProvider = (*RunningExecutionsInfoProvider)(nil)