Skip to content

Commit 4d6d981

Browse files
authored
Merge pull request #162 from allaouiamine/adding-job-owner-key
Adding a new context key JobOwnerID
2 parents 2831239 + 88c5d0a commit 4d6d981

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

pkg/types/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ type JobID uint64
1717
// RunID represents the id of a run within the Job
1818
type RunID uint64
1919

20+
// JobOwnerID represents a unique owner identifier of a given job
21+
type JobOwnerID uint64
22+
2023
func (v JobID) String() string {
2124
return strconv.FormatUint(uint64(v), 10)
2225
}
@@ -25,11 +28,16 @@ func (v RunID) String() string {
2528
return strconv.FormatUint(uint64(v), 10)
2629
}
2730

31+
func (v JobOwnerID) String() string {
32+
return strconv.FormatUint(uint64(v), 10)
33+
}
34+
2835
type key string
2936

3037
const (
3138
KeyJobID = key("job_id")
3239
KeyRunID = key("run_id")
40+
KeyJobOwnerID = key("job_owner_id")
3341
)
3442

3543
// JobIDFromContext is a helper to get the JobID, this is useful
@@ -48,3 +56,11 @@ func RunIDFromContext(ctx xcontext.Context) (RunID, bool) {
4856
v, ok := ctx.Value(KeyRunID).(RunID)
4957
return v, ok
5058
}
59+
60+
// JobOwnerIDFromContext is a helper to get the JobOwnerID.
61+
// Not all context object everywhere have this set, but this is
62+
// guaranteed to work in TargetManagers, TestSteps and RunReporters
63+
func JobOwnerIDFromContext(ctx xcontext.Context) (JobOwnerID, bool) {
64+
v, ok := ctx.Value(KeyJobOwnerID).(JobOwnerID)
65+
return v, ok
66+
}

0 commit comments

Comments
 (0)