-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.go
45 lines (34 loc) · 877 Bytes
/
run.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
package gjobctl
import (
"context"
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go/service/glue"
)
const (
TimeoutForRun = 5 * time.Second
)
type RunOption struct {
JobName *string `arg:"" name:"jobname" help:"enter the name of the Glue Job to run"`
}
func (app *App) Run(ctx context.Context, opt *RunOption) error {
ctx, cancel := context.WithTimeout(ctx, TimeoutForRun)
defer cancel()
// AWSのセッションを作成
sess, err := app.createAWSSession()
if err != nil {
return err
}
// Glueのクライアントを作成
sv := glue.New(sess)
input := &glue.StartJobRunInput{
JobName: opt.JobName,
}
result, err := sv.StartJobRunWithContext(ctx, input)
if err != nil {
return fmt.Errorf("failed to start job: %w", err)
}
log.Printf("Successfully Started Glue Job. job-name: %s job-run-id:%s", *opt.JobName, *result.JobRunId)
return nil
}