diff --git a/.changelog/13359.txt b/.changelog/13359.txt new file mode 100644 index 000000000..d42c98f36 --- /dev/null +++ b/.changelog/13359.txt @@ -0,0 +1,3 @@ +```release-note:improvements +api: Added `NewSysbatchJob` helper function to create a base sysbatch job object +``` diff --git a/api/jobs.go b/api/jobs.go index e7e3a3be5..656b3c923 100644 --- a/api/jobs.go +++ b/api/jobs.go @@ -20,6 +20,10 @@ const ( // JobTypeSystem indicates a system process that should run on all clients JobTypeSystem = "system" + // JobTypeSysbatch indicates a short-lived system process that should run + // on all clients. + JobTypeSysbatch = "sysbatch" + // PeriodicSpecCron is used for a cron spec. PeriodicSpecCron = "cron" @@ -1085,6 +1089,13 @@ func NewSystemJob(id, name, region string, pri int) *Job { return newJob(id, name, region, JobTypeSystem, pri) } +// NewSysbatchJob creates and returns a new sysbatch-style job for short-lived +// processes designed to run on all clients, using the provided name and ID +// along with the relative job priority. +func NewSysbatchJob(id, name, region string, pri int) *Job { + return newJob(id, name, region, JobTypeSysbatch, 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 1dcb872a4..6cc8b3abf 100644 --- a/api/jobs_test.go +++ b/api/jobs_test.go @@ -1993,6 +1993,19 @@ func TestJobs_NewSystemJob(t *testing.T) { } } +func TestJobs_NewSysbatchJob(t *testing.T) { + testutil.Parallel(t) + job := NewSysbatchJob("job1", "myjob", "global", 5) + expect := &Job{ + Region: stringToPtr("global"), + ID: stringToPtr("job1"), + Name: stringToPtr("myjob"), + Type: stringToPtr(JobTypeSysbatch), + Priority: intToPtr(5), + } + require.Equal(t, expect, job) +} + func TestJobs_SetMeta(t *testing.T) { testutil.Parallel(t) job := &Job{Meta: nil}