Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public set methods for data bag #6

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions data_bag.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ type DataBag struct {
bag sync.Map
}

// GetJobData allows to fetch the job data from bag using step name.
// GetJobData allows to fetch the job data from data bag using step name.
// If ok is false, it means that no data was stored.
func (d *DataBag) GetJobData(name string) (interface{}, bool) {
return d.getData(name + jobDataPostfix)
}

// GetPreCheckData allows to fetch the job data from bag using step name.
// GetPreCheckData allows to fetch the pre-check data from data bag using step name.
// If ok is false, it means that no data was stored.
func (d *DataBag) GetPreCheckData(name string) (interface{}, bool) {
return d.getData(name + preCheckDataPostfix)
Expand All @@ -50,11 +50,13 @@ func (d *DataBag) setData(name string, data interface{}) {
d.bag.Store(d.getKeyName(name), data)
}

func (d *DataBag) setJobData(name string, data interface{}) {
// SetJobData allows to set the job data from data bag using step name.
func (d *DataBag) SetJobData(name string, data interface{}) {
d.setData(name+jobDataPostfix, data)
}

func (d *DataBag) setPreCheckData(name string, data interface{}) {
// SetPreCheckData allows to set the pre-check data to data bag using step name.
func (d *DataBag) SetPreCheckData(name string, data interface{}) {
d.setData(name+preCheckDataPostfix, data)
}

Expand Down
4 changes: 2 additions & 2 deletions data_bag_inner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestDataBag_GetJobData(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
d := new(DataBag)

d.setJobData(tt.args.keyName, tt.args.storeVal)
d.SetJobData(tt.args.keyName, tt.args.storeVal)

got, exists := d.GetJobData(tt.getKeyName)

Expand All @@ -52,7 +52,7 @@ func TestDataBag_GetPreCheckData(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
d := new(DataBag)

d.setPreCheckData(tt.args.keyName, tt.args.storeVal)
d.SetPreCheckData(tt.args.keyName, tt.args.storeVal)

got, exists := d.GetPreCheckData(tt.getKeyName)

Expand Down
4 changes: 2 additions & 2 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (w *worker) executeStep(ctx context.Context, stepIdx int, input interface{}

if output, ok := isReturnOutput(preCheckResp); ok {
if db, ok := ctx.Value(DataBagContextKey).(*DataBag); ok {
db.setPreCheckData(w.steps.StepName(stepIdx), output)
db.SetPreCheckData(w.steps.StepName(stepIdx), output)
}
}

Expand Down Expand Up @@ -110,7 +110,7 @@ func (w *worker) executeStep(ctx context.Context, stepIdx int, input interface{}

if output, ok := isReturnOutput(jobResp); ok {
if db, ok := ctx.Value(DataBagContextKey).(*DataBag); ok {
db.setJobData(w.steps.StepName(stepIdx), output)
db.SetJobData(w.steps.StepName(stepIdx), output)
}
}

Expand Down
Loading