diff --git a/.changelog/10861.txt b/.changelog/10861.txt new file mode 100644 index 000000000000..f55d0bfa806e --- /dev/null +++ b/.changelog/10861.txt @@ -0,0 +1,3 @@ +```release-note:improvement +api: Added `NewSystemJob` helper function to create base system job object. +``` diff --git a/api/jobs.go b/api/jobs.go index 1fed52c7ca38..416fce1fa579 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -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{ diff --git a/api/jobs_test.go b/api/jobs_test.go index 250f33717d50..56ecaa20fbee 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -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} diff --git a/vendor/github.com/hashicorp/nomad/api/jobs.go b/vendor/github.com/hashicorp/nomad/api/jobs.go index 1fed52c7ca38..416fce1fa579 100644 --- a/vendor/github.com/hashicorp/nomad/api/jobs.go +++ b/vendor/github.com/hashicorp/nomad/api/jobs.go @@ -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{