github.com/kubevela/workflow@v0.6.0/pkg/cue/process/datamanager.go (about)

     1  package process
     2  
     3  import "github.com/kubevela/workflow/pkg/cue/model"
     4  
     5  // DataManager is in charge of injecting and removing runtime context for ContextData
     6  type DataManager interface {
     7  	Fill(ctx Context, kvs []StepMetaKV)
     8  	Remove(ctx Context, keys []string)
     9  }
    10  
    11  // StepRunTimeMeta manage step runtime metadata
    12  type StepRunTimeMeta struct{}
    13  
    14  // StepMetaKV store the key and value of step runtime metadata
    15  type StepMetaKV struct {
    16  	Key   string
    17  	Value interface{}
    18  }
    19  
    20  // WithSessionID return stepSessionID of the step
    21  func WithSessionID(id string) StepMetaKV {
    22  	return StepMetaKV{
    23  		Key:   model.ContextStepSessionID,
    24  		Value: id,
    25  	}
    26  }
    27  
    28  // WithName return stepName of the step
    29  func WithName(name string) StepMetaKV {
    30  	return StepMetaKV{
    31  		Key:   model.ContextStepName,
    32  		Value: name,
    33  	}
    34  }
    35  
    36  // WithGroupName return stepGroupName of the step
    37  func WithGroupName(name string) StepMetaKV {
    38  	return StepMetaKV{
    39  		Key:   model.ContextStepGroupName,
    40  		Value: name,
    41  	}
    42  }
    43  
    44  // WithSpanID return spanID of the step
    45  func WithSpanID(id string) StepMetaKV {
    46  	return StepMetaKV{
    47  		Key:   model.ContextSpanID,
    48  		Value: id,
    49  	}
    50  }
    51  
    52  // NewStepRunTimeMeta create step runtime metadata manager
    53  func NewStepRunTimeMeta() DataManager {
    54  	return &StepRunTimeMeta{}
    55  }
    56  
    57  // Fill will fill step runtime metadata for ContextData
    58  func (s *StepRunTimeMeta) Fill(ctx Context, kvs []StepMetaKV) {
    59  	for _, kv := range kvs {
    60  		ctx.PushData(kv.Key, kv.Value)
    61  	}
    62  }
    63  
    64  // Remove remove step runtime metadata of ContextData
    65  func (s *StepRunTimeMeta) Remove(ctx Context, keys []string) {
    66  	for _, key := range keys {
    67  		ctx.RemoveData(key)
    68  	}
    69  }