api: Added `NewSystemJob` job creation helper function.

This commit is contained in:
James Rasell 2021-07-07 11:03:20 +02:00
parent 94913d2ad6
commit 381741baad
No known key found for this signature in database
GPG Key ID: AA7D460F5C8377AA
3 changed files with 29 additions and 0 deletions

View File

@ -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{

View File

@ -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}

View File

@ -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{