From dbc1ae112070546db1159aedbb32ed82c92dc12c Mon Sep 17 00:00:00 2001 From: jano3 <jano@bob.co.za> Date: Tue, 31 Oct 2023 11:31:56 +0200 Subject: [PATCH] Extract function parameters to a struct --- batch/batch.go | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/batch/batch.go b/batch/batch.go index 4cc9c30..7900cfa 100644 --- a/batch/batch.go +++ b/batch/batch.go @@ -32,11 +32,20 @@ const ( BatchJobMessageTypeS3 BatchJobMessageType = "s3" ) -func SubmitJob(name *string, job any, fullJobDefinition string, fullJobQueue string, messagesBucketName string, isDebug bool) error { - if isDebug { +type BatchJob struct { + Name *string + Job any + FullJobDefinition string + FullJobQueue string + MessagesBucketName string + IsDebug bool +} + +func SubmitJob(batchJob BatchJob) error { + if batchJob.IsDebug { go func() { resty.New().R(). - SetBody(job). + SetBody(batchJob.Job). Post("http://127.0.0.1:3000/batch/") }() time.Sleep(time.Second * 1) @@ -52,20 +61,20 @@ func SubmitJob(name *string, job any, fullJobDefinition string, fullJobQueue str batchClient := batch.New(sess) - if name == nil { + if batchJob.Name == nil { id := uuid.New() jobID := "job" + id.String() - name = utils.ValueToPointer(jobID) + batchJob.Name = utils.ValueToPointer(jobID) } - err = uploadMessageToS3(*name, job, messagesBucketName, isDebug) + err = uploadMessageToS3(batchJob) if err != nil { return err } command := []*string{ utils.ValueToPointer(binaryPath), - name, + batchJob.Name, } environmentOverwrite := []*batch.KeyValuePair{{ @@ -75,9 +84,9 @@ func SubmitJob(name *string, job any, fullJobDefinition string, fullJobQueue str } input := &batch.SubmitJobInput{ - JobDefinition: utils.ValueToPointer(fullJobDefinition), - JobName: name, - JobQueue: utils.ValueToPointer(fullJobQueue), + JobDefinition: utils.ValueToPointer(batchJob.FullJobDefinition), + JobName: batchJob.Name, + JobQueue: utils.ValueToPointer(batchJob.FullJobQueue), ContainerOverrides: &batch.ContainerOverrides{ Command: command, Environment: environmentOverwrite, @@ -90,15 +99,15 @@ func SubmitJob(name *string, job any, fullJobDefinition string, fullJobQueue str return nil } -func uploadMessageToS3(name string, job any, bucketName string, isDebug bool) error { - jobBytes, err := json.Marshal(job) +func uploadMessageToS3(batchJob BatchJob) error { + jobBytes, err := json.Marshal(batchJob.Job) if err != nil { return err } // Upload message - _, err = s3.GetSession(isDebug).UploadWithSettingsRevised(jobBytes, bucketName, s3.S3UploadSettings{ - FileName: name, + _, err = s3.GetSession(batchJob.IsDebug).UploadWithSettingsRevised(jobBytes, batchJob.MessagesBucketName, s3.S3UploadSettings{ + FileName: utils.PointerToValue(batchJob.Name), }) if err != nil { return err -- GitLab