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

api: Added NewSystemJob job creation helper function. #10861

Merged
merged 2 commits into from
Jul 7, 2021
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
3 changes: 3 additions & 0 deletions .changelog/10861.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
api: Added `NewSystemJob` helper function to create base system job object.
```
7 changes: 7 additions & 0 deletions api/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,13 @@ func NewBatchJob(id, name, region string, pri int) *Job {
return newJob(id, name, region, JobTypeBatch, pri)
}

// NewSystemJob creates and returns a new system-style job for processes
// designed to run on all clients, using the provided name and ID along with
// the relative job priority.
func NewSystemJob(id, name, region string, pri int) *Job {
return newJob(id, name, region, JobTypeSystem, pri)
}

// newJob is used to create a new Job struct.
func newJob(id, name, region, typ string, pri int) *Job {
return &Job{
Expand Down
15 changes: 15 additions & 0 deletions api/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1861,6 +1861,21 @@ func TestJobs_NewServiceJob(t *testing.T) {
}
}

func TestJobs_NewSystemJob(t *testing.T) {
t.Parallel()
job := NewSystemJob("job1", "myjob", "global", 5)
expect := &Job{
Region: stringToPtr("global"),
ID: stringToPtr("job1"),
Name: stringToPtr("myjob"),
Type: stringToPtr(JobTypeSystem),
Priority: intToPtr(5),
}
if !reflect.DeepEqual(job, expect) {
t.Fatalf("expect: %#v, got: %#v", expect, job)
}
}

func TestJobs_SetMeta(t *testing.T) {
t.Parallel()
job := &Job{Meta: nil}
Expand Down
7 changes: 7 additions & 0 deletions vendor/github.com/hashicorp/nomad/api/jobs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.