Skip to content

Commit

Permalink
Merge pull request #162 from allaouiamine/adding-job-owner-key
Browse files Browse the repository at this point in the history
Adding a new context key JobOwnerID
  • Loading branch information
mimir-d committed May 15, 2023
2 parents 2831239 + 88c5d0a commit 4d6d981
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type JobID uint64
// RunID represents the id of a run within the Job
type RunID uint64

// JobOwnerID represents a unique owner identifier of a given job
type JobOwnerID uint64

func (v JobID) String() string {
return strconv.FormatUint(uint64(v), 10)
}
Expand All @@ -25,11 +28,16 @@ func (v RunID) String() string {
return strconv.FormatUint(uint64(v), 10)
}

func (v JobOwnerID) String() string {
return strconv.FormatUint(uint64(v), 10)
}

type key string

const (
KeyJobID = key("job_id")
KeyRunID = key("run_id")
KeyJobOwnerID = key("job_owner_id")
)

// JobIDFromContext is a helper to get the JobID, this is useful
Expand All @@ -48,3 +56,11 @@ func RunIDFromContext(ctx xcontext.Context) (RunID, bool) {
v, ok := ctx.Value(KeyRunID).(RunID)
return v, ok
}

// JobOwnerIDFromContext is a helper to get the JobOwnerID.
// Not all context object everywhere have this set, but this is
// guaranteed to work in TargetManagers, TestSteps and RunReporters
func JobOwnerIDFromContext(ctx xcontext.Context) (JobOwnerID, bool) {
v, ok := ctx.Value(KeyJobOwnerID).(JobOwnerID)
return v, ok
}

0 comments on commit 4d6d981

Please sign in to comment.