Skip to content

Commit

Permalink
Merge pull request #9 from iwashi623/feature/set_const
Browse files Browse the repository at this point in the history
Feature/set const
  • Loading branch information
iwashi623 authored Feb 3, 2023
2 parents 0c600f4 + 67dff51 commit 3400d9d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[AWS Glue](https://aws.amazon.com/jp/glue/)をコンソール上からポチポチ変更していると、コミット履歴や設定変更の履歴が残らず、辛いと思うことが多々あったので作りました。

Glue Job にのみ関心を持つツールで、Glue のスクリプトや設定ファイルを一つのリポジトリでまとめて管理したいときに欲しいと思われるAPIをCLI上で実行できます
Glue Job にのみ関心を持つツールで、Glue のスクリプトや設定ファイルを一つのリポジトリでまとめて管理したいときに欲しいと思われるAPIをコマンドライン上で実行できます

## Use gjobctl

Expand Down Expand Up @@ -107,7 +107,9 @@ json形式のJobの設定ファイルは"-f"オプションで任意の値を渡
```

### Run
Glue Jobを実行するコマンドです。実行時のオプション引数はまだ対応していません。
Glue Jobを実行するコマンドです。

※ 実行時のオプション引数はまだ対応していません。

```bash
$ gjobctl run <job-name>
Expand Down
11 changes: 8 additions & 3 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import (
"github.com/alecthomas/kong"
)

const (
ExitCodeOK = 0
ExitCodeError = 1
)

func cli(ctx context.Context, sub string, opts *CLIOptions, usage func()) error {
app, err := New()
if err != nil {
Expand Down Expand Up @@ -47,14 +52,14 @@ type CLIOptions struct {
func CLI(ctx context.Context, parseArgs CLIParseFunc) (int, error) {
sub, opts, usage, err := parseArgs(os.Args[1:])
if err != nil {
return 1, err
return ExitCodeError, err
}

err = cli(ctx, sub, opts, usage)
if err != nil {
return 1, err
return ExitCodeError, err
}
return 0, nil
return ExitCodeOK, nil
}

func ParseArgs(args []string) (string, *CLIOptions, func(), error) {
Expand Down
7 changes: 4 additions & 3 deletions create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import (
"github.com/aws/aws-sdk-go/service/glue"
)

type BaseOption interface {
}
const (
TimeoutForCreate = 5 * time.Second
)

type CreateOption struct {
JobSettingFile *string `name:"job-setting-file" short:"f" description:"job setting file in json"`
}

func (app *App) Create(ctx context.Context, opt *CreateOption) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForCreate)
defer cancel()

var fn string
Expand Down
6 changes: 5 additions & 1 deletion get.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
"github.com/aws/aws-sdk-go/service/glue"
)

const (
TimeoutForGet = 5 * time.Second
)

type GetOption struct {
JobName *string `arg:"" name:"jobname" help:"enter the name of the Glue Job to be getted"`
}

func (app *App) Get(ctx context.Context, opt *GetOption) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForGet)
defer cancel()

// AWSのセッションを作成
Expand Down
3 changes: 1 addition & 2 deletions gjobctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ func (app *App) setup() error {

// Config構造体にデシリアライズ
var conf AppConfig
decoder := yaml.NewDecoder(f)
if err := decoder.Decode(&conf); err != nil {
if err := yaml.NewDecoder(f).Decode(&conf); err != nil {
return fmt.Errorf("failed to decode config file: %w", err)
}

Expand Down
11 changes: 8 additions & 3 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ import (
"fmt"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/glue"
)

const (
TimeoutForList = 5 * time.Second
MaxListCount int64 = 1000
)

type ListOption struct {
}

func (app *App) List(ctx context.Context, opt *ListOption) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForList)
defer cancel()

// AWSのセッションを作成
Expand All @@ -23,9 +27,10 @@ func (app *App) List(ctx context.Context, opt *ListOption) error {
}
sv := glue.New(sess)

max := MaxListCount
// Glue Jobの一覧を取得
result, err := sv.GetJobsWithContext(ctx, &glue.GetJobsInput{
MaxResults: aws.Int64(1000),
MaxResults: &max,
})
if err != nil {
return fmt.Errorf("failed to get job list: %w", err)
Expand Down
6 changes: 5 additions & 1 deletion run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ import (
"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, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForRun)
defer cancel()

// AWSのセッションを作成
Expand Down
6 changes: 5 additions & 1 deletion script_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ import (
"github.com/aws/aws-sdk-go/service/s3"
)

const (
TimeoutForScriptDeploy = 5 * time.Second
)

type ScriptDeployOption struct {
JobSettingFile *string `name:"job-setting-file" short:"f" description:"job setting file in json"`
ScriptLocalPath *string `arg:"" name:"script-local-path" short:"s" description:"script local path"`
}

func (app *App) ScriptDeploy(ctx context.Context, opt *ScriptDeployOption) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForScriptDeploy)
defer cancel()

// JSONファイルからGlue Jobの設定を読み込む
Expand Down
6 changes: 5 additions & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ import (
"github.com/aws/aws-sdk-go/service/glue"
)

const (
TimeoutForUpdate = 5 * time.Second
)

type UpdateOption struct {
JobSettingFile *string `name:"job-setting-file" short:"f" description:"job setting file in json"`
}

func (app *App) Update(ctx context.Context, opt *UpdateOption) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
ctx, cancel := context.WithTimeout(ctx, TimeoutForUpdate)
defer cancel()

// JSONファイルからGlue Jobの設定を読み込む
Expand Down

0 comments on commit 3400d9d

Please sign in to comment.