Skip to content

Commit

Permalink
Feature: Added job namespace to context
Browse files Browse the repository at this point in the history
  • Loading branch information
runabol committed Nov 16, 2023
1 parent 9b120b5 commit c7f5c0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions input/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func (ji *Job) ToJob() *tork.Job {
j.CreatedAt = n
j.Context = tork.JobContext{}
j.Context.Inputs = ji.Inputs
j.Context.Job = map[string]string{
"id": j.ID,
"name": j.Name,
}
j.TaskCount = len(tasks)
j.Output = ji.Output
if ji.Defaults != nil {
Expand Down
3 changes: 3 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type JobSummary struct {
}

type JobContext struct {
Job map[string]string `json:"job,omitempty"`
Inputs map[string]string `json:"inputs,omitempty"`
Tasks map[string]string `json:"tasks,omitempty"`
}
Expand Down Expand Up @@ -107,13 +108,15 @@ func (c JobContext) Clone() JobContext {
return JobContext{
Inputs: maps.Clone(c.Inputs),
Tasks: maps.Clone(c.Tasks),
Job: maps.Clone(c.Job),
}
}

func (c JobContext) AsMap() map[string]any {
return map[string]any{
"inputs": c.Inputs,
"tasks": c.Tasks,
"job": c.Job,
}
}

Expand Down
5 changes: 5 additions & 0 deletions job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func TestClone(t *testing.T) {
Inputs: map[string]string{
"INPUT1": "VAL1",
},
Job: map[string]string{
"id": "some-id",
"name": "my job",
},
},
Tasks: []*tork.Task{
{
Expand All @@ -33,6 +37,7 @@ func TestClone(t *testing.T) {
j2 := j1.Clone()

assert.Equal(t, j1.Context.Inputs, j2.Context.Inputs)
assert.Equal(t, j1.Context.Job, j2.Context.Job)
assert.Equal(t, j1.Tasks[0].Env, j2.Tasks[0].Env)
assert.Equal(t, j1.Execution[0].Env, j2.Execution[0].Env)

Expand Down

0 comments on commit c7f5c0a

Please sign in to comment.