-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch_operation.go
58 lines (49 loc) · 1.55 KB
/
batch_operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package awssdk
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/batch"
"log"
"github.com/hwangtaeseung/neptune-core/pkg/common"
)
func SubmitJob(region, jobDefinition, jobName, jobQueue string, envs []*batch.KeyValuePair,
arrayProperties *batch.ArrayProperties, dependOn []*batch.JobDependency) (*batch.SubmitJobOutput, error) {
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(region),
}))
input := &batch.SubmitJobInput{
DependsOn: dependOn,
JobDefinition: aws.String(jobDefinition),
JobName: aws.String(jobName),
JobQueue: aws.String(jobQueue),
ContainerOverrides: &batch.ContainerOverrides{
Environment: envs,
},
ArrayProperties: arrayProperties,
}
service := batch.New(sess)
if output, err := service.SubmitJob(input); err != nil {
log.Printf("job submit error : %v", err)
return nil, err
} else {
log.Printf("job submit ok : %v", common.ToJsonAsString(output))
return output, nil
}
}
func TerminateJob(region, jobId, reason string) (*batch.TerminateJobOutput, error) {
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(region),
}))
input := &batch.TerminateJobInput{
JobId: aws.String(jobId),
Reason: aws.String(reason),
}
service := batch.New(sess)
if output, err := service.TerminateJob(input); err != nil {
log.Printf("terminate job error : %v", err)
return nil, err
} else {
log.Printf("terminate job ok : %v", common.ToJsonAsString(output))
return output, nil
}
}