-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add stepGroupName to process.Context
Signed-off-by: yangsoon <songyang.song@alibaba-inc.com>
- Loading branch information
yangsoon
committed
Apr 6, 2023
1 parent
c730c05
commit ec56b2a
Showing
8 changed files
with
153 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package process | ||
|
||
import "github.com/kubevela/workflow/pkg/cue/model" | ||
|
||
type DataManager interface { | ||
Fill(ctx Context) | ||
Remove(ctx Context, opts ...StepMetaBuilder) | ||
} | ||
|
||
type Tracing struct { | ||
SpanID string | ||
} | ||
|
||
type StepRunTimeMeta struct { | ||
Data map[string]interface{} | ||
} | ||
|
||
type StepMetaKV struct { | ||
Key string | ||
Value interface{} | ||
} | ||
|
||
type StepMetaBuilder func() StepMetaKV | ||
|
||
func WithSessionID(id string) StepMetaBuilder { | ||
return func() StepMetaKV { return StepMetaKV{Key: model.ContextStepSessionID, Value: id} } | ||
} | ||
|
||
func WithName(name string) StepMetaBuilder { | ||
return func() StepMetaKV { return StepMetaKV{Key: model.ContextStepName, Value: name} } | ||
} | ||
|
||
func WithGroupName(name string) StepMetaBuilder { | ||
return func() StepMetaKV { return StepMetaKV{Key: model.ContextStepGroupName, Value: name} } | ||
} | ||
|
||
func WithSpanID(id string) StepMetaBuilder { | ||
return func() StepMetaKV { return StepMetaKV{Key: model.ContextSpanID, Value: id} } | ||
} | ||
|
||
func NewStepRunTimeMeta(builders ...StepMetaBuilder) DataManager { | ||
meta := &StepRunTimeMeta{ | ||
Data: make(map[string]interface{}), | ||
} | ||
for _, b := range builders { | ||
metaKV := b() | ||
meta.Data[metaKV.Key] = metaKV.Value | ||
} | ||
return meta | ||
} | ||
|
||
func (s *StepRunTimeMeta) Fill(ctx Context) { | ||
for k := range s.Data { | ||
ctx.PushData(k, s.Data[k]) | ||
} | ||
} | ||
|
||
func (s *StepRunTimeMeta) Remove(ctx Context, builders ...StepMetaBuilder) { | ||
for _, b := range builders { | ||
metaKV := b() | ||
delete(s.Data, metaKV.Key) | ||
ctx.RemoveData(metaKV.Key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters