/
comprehend_targeted_sentiment_detection_job.go
72 lines (59 loc) · 2.1 KB
/
comprehend_targeted_sentiment_detection_job.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/comprehend"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)
func init() {
register("ComprehendTargetedSentimentDetectionJob", ListComprehendTargetedSentimentDetectionJobs)
}
func ListComprehendTargetedSentimentDetectionJobs(sess *session.Session) ([]Resource, error) {
svc := comprehend.New(sess)
params := &comprehend.ListTargetedSentimentDetectionJobsInput{}
resources := make([]Resource, 0)
for {
resp, err := svc.ListTargetedSentimentDetectionJobs(params)
if err != nil {
return nil, err
}
for _, targetedSentimentDetectionJob := range resp.TargetedSentimentDetectionJobPropertiesList {
switch *targetedSentimentDetectionJob.JobStatus {
case "STOPPED", "FAILED", "COMPLETED":
// if the job has already been stopped, failed, or completed; do not try to stop it again
continue
}
resources = append(resources, &ComprehendTargetedSentimentDetectionJob{
svc: svc,
targetedSentimentDetectionJob: targetedSentimentDetectionJob,
})
}
if resp.NextToken == nil {
break
}
params.NextToken = resp.NextToken
}
return resources, nil
}
type ComprehendTargetedSentimentDetectionJob struct {
svc *comprehend.Comprehend
targetedSentimentDetectionJob *comprehend.TargetedSentimentDetectionJobProperties
}
func (ce *ComprehendTargetedSentimentDetectionJob) Remove() error {
_, err := ce.svc.StopTargetedSentimentDetectionJob(&comprehend.StopTargetedSentimentDetectionJobInput{
JobId: ce.targetedSentimentDetectionJob.JobId,
})
return err
}
func (ce *ComprehendTargetedSentimentDetectionJob) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("JobName", ce.targetedSentimentDetectionJob.JobName)
properties.Set("JobId", ce.targetedSentimentDetectionJob.JobId)
return properties
}
func (ce *ComprehendTargetedSentimentDetectionJob) String() string {
if ce.targetedSentimentDetectionJob.JobName == nil {
return "Unnamed job"
} else {
return *ce.targetedSentimentDetectionJob.JobName
}
}