-
Notifications
You must be signed in to change notification settings - Fork 8
Con 1896 jobs progress #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
az-smartling
wants to merge
19
commits into
master
Choose a base branch
from
CON-1896_jobs_progress
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
1400fbc
CON-1896 jobs progress
az-smartling 33a8474
go mod tidy
az-smartling a01e411
updated md docs
az-smartling 9385101
CR changes
az-smartling 041b889
tests
az-smartling 217a008
CR changes
az-smartling a5b6a01
added job test to Makefile
az-smartling e7d6c3c
CON-1896 Update command descriptions.
dimitrystd df90e7c
Enhanced CLAUDE.md. Updated Makefile for module vendoring and improve…
dimitrystd 8d3c4e3
Fix cmd_locates_test.
dimitrystd bf5a566
Add 'Run Tests' stage to Jenkins pipeline with JUnit reporting
dimitrystd 2b96749
used `go mod download`
az-smartling 6aa5283
updated do.mod
az-smartling 44ec26b
added ErrJobNotFound
az-smartling 313a0bf
updated go.sum
az-smartling cb48c06
updated docs
az-smartling 73b064f
Merge branch 'master' into CON-1896_jobs_progress
az-smartling 6eb57d0
updated go.mod
az-smartling 4736a1e
updated go.mod, renaming, retund error if job not found
az-smartling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package resolve | ||
|
|
||
| import ( | ||
| "github.com/Smartling/smartling-cli/output" | ||
| clierror "github.com/Smartling/smartling-cli/services/helpers/cli_error" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // OutputParams resolve OutputParams for subcommands | ||
| func OutputParams(cmd *cobra.Command, fileConfigMTFileFormat *string) (output.Params, error) { | ||
| const outputTemplateFlag = "format" | ||
| format, err := cmd.Parent().PersistentFlags().GetString("output") | ||
| if err != nil { | ||
| return output.Params{}, clierror.UIError{ | ||
| Operation: "get output", | ||
| Err: err, | ||
| Description: "unable to get output param", | ||
| } | ||
| } | ||
| template := FallbackString(cmd.Flags().Lookup(outputTemplateFlag), StringParam{ | ||
| FlagName: outputTemplateFlag, | ||
| Config: fileConfigMTFileFormat, | ||
| }) | ||
|
|
||
| mode, err := cmd.Parent().PersistentFlags().GetString("output-mode") | ||
| if err != nil { | ||
| return output.Params{}, clierror.UIError{ | ||
| Operation: "get output mode", | ||
| Err: err, | ||
| Description: "unable to get output mode param", | ||
| } | ||
| } | ||
| return output.Params{ | ||
| Mode: mode, | ||
| Format: format, | ||
| Template: template, | ||
| }, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package jobs | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const ( | ||
| outputFormatFlag = "output" | ||
| ) | ||
|
|
||
| var ( | ||
| outputFormat string | ||
| allowedOutputs = []string{ | ||
| "json", | ||
| "simple", | ||
| } | ||
| joinedAllowedOutputs = strings.Join(allowedOutputs, ", ") | ||
| ) | ||
|
|
||
| // NewJobsCmd returns new jobs command | ||
| func NewJobsCmd() *cobra.Command { | ||
| jobsCmd := &cobra.Command{ | ||
| Use: "jobs", | ||
| Short: "Handles job subcommands.", | ||
| Long: `Handles job subcommands. Subcommands are a high-level abstraction layer over the underlying Job APIs.`, | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| if !slices.Contains(allowedOutputs, outputFormat) { | ||
| return fmt.Errorf("invalid output: %s (allowed: %s)", outputFormat, joinedAllowedOutputs) | ||
| } | ||
| return nil | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) == 0 && cmd.Flags().NFlag() == 0 { | ||
| return cmd.Help() | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| jobsCmd.PersistentFlags().StringVar(&outputFormat, outputFormatFlag, "simple", "Output format: "+joinedAllowedOutputs) | ||
|
|
||
| return jobsCmd | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package progress | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| rootcmd "github.com/Smartling/smartling-cli/cmd" | ||
| "github.com/Smartling/smartling-cli/cmd/helpers/resolve" | ||
| jobscmd "github.com/Smartling/smartling-cli/cmd/jobs" | ||
| "github.com/Smartling/smartling-cli/output" | ||
| clierror "github.com/Smartling/smartling-cli/services/helpers/cli_error" | ||
| srv "github.com/Smartling/smartling-cli/services/jobs" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| const ( | ||
| outputFormatFlag = "output" | ||
| ) | ||
|
|
||
| var ( | ||
| outputFormat string | ||
| allowedOutputs = []string{ | ||
| "json", | ||
| "simple", | ||
| } | ||
| joinedAllowedOutputs = strings.Join(allowedOutputs, ", ") | ||
| ) | ||
|
|
||
| // NewProgressCmd returns new progress command | ||
| func NewProgressCmd(initializer jobscmd.SrvInitializer) *cobra.Command { | ||
| progressCmd := &cobra.Command{ | ||
| Use: "progress <translationJobUid|translationJobName>", | ||
| Short: "Get job progress by the translationJobUid or translationJobName.", | ||
| Long: `Get job progress by the translationJobUid or translationJobName.`, | ||
| Example: ` | ||
| # Get job progress | ||
|
|
||
| smartling-cli jobs progress aabbccdd | ||
|
|
||
| `, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) != 1 { | ||
| return clierror.UIError{ | ||
| Operation: "check args", | ||
| Err: errors.New("wrong argument quantity"), | ||
| Description: fmt.Sprintf("expected one argument, got: %d", len(args)), | ||
| } | ||
| } | ||
| var idOrName string | ||
| if len(args) == 1 { | ||
| idOrName = args[0] | ||
| } | ||
|
az-smartling marked this conversation as resolved.
Outdated
|
||
|
|
||
| ctx := cmd.Context() | ||
|
|
||
| cnf, err := rootcmd.Config() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| accountUID, err := resolve.FallbackAccount(cmd.Root().PersistentFlags().Lookup("account"), cnf.AccountID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| params := srv.ProgressParams{ | ||
| AccountUID: accountUID, | ||
| ProjectUID: cnf.ProjectID, | ||
| JobIDOrName: idOrName, | ||
| } | ||
| format, err := cmd.Parent().PersistentFlags().GetString("output") | ||
| if err != nil { | ||
| return err | ||
| } | ||
| outputParams := output.Params{Format: format} | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
az-smartling marked this conversation as resolved.
Outdated
|
||
| return run(ctx, initializer, params, outputParams) | ||
| }, | ||
| } | ||
|
|
||
| progressCmd.PersistentFlags().StringVar(&outputFormat, outputFormatFlag, "simple", "Output format: "+joinedAllowedOutputs) | ||
|
az-smartling marked this conversation as resolved.
Outdated
|
||
|
|
||
| return progressCmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package progress | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| jobscmd "github.com/Smartling/smartling-cli/cmd/jobs" | ||
| "github.com/Smartling/smartling-cli/output" | ||
| "github.com/Smartling/smartling-cli/output/jobs" | ||
| clierror "github.com/Smartling/smartling-cli/services/helpers/cli_error" | ||
| "github.com/Smartling/smartling-cli/services/helpers/rlog" | ||
| srv "github.com/Smartling/smartling-cli/services/jobs" | ||
| ) | ||
|
|
||
| func run(ctx context.Context, | ||
| initializer jobscmd.SrvInitializer, | ||
| params srv.ProgressParams, | ||
| outputParams output.Params, | ||
| ) error { | ||
| rlog.Debugf("running progress with params: %v", params) | ||
| jobSrv, err := initializer.InitJobSrv() | ||
| if err != nil { | ||
| return clierror.UIError{ | ||
| Operation: "init", | ||
| Err: err, | ||
| Description: "unable to initialize Jobs service", | ||
| } | ||
| } | ||
|
|
||
| progressOutput, err := jobSrv.RunProgress(ctx, params) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if progressOutput.TranslationJobUID == "" { | ||
| rlog.Infof("no jobs found for given translationJobUid or translationJobName: %s", params.JobIDOrName) | ||
| return nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the exit code that will be returned in this case? I believe it should be non-zero.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to return error |
||
| } | ||
|
|
||
| outputFormat := jobs.GetOutputFormat(outputParams.Format) | ||
| outputFormat.FormatAndRender(progressOutput) | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package jobs | ||
|
|
||
| import ( | ||
| rootcmd "github.com/Smartling/smartling-cli/cmd" | ||
| srv "github.com/Smartling/smartling-cli/services/jobs" | ||
|
|
||
| jobapi "github.com/Smartling/api-sdk-go/api/job" | ||
| ) | ||
|
|
||
| // SrvInitializer defines files service initializer | ||
| type SrvInitializer interface { | ||
| InitJobSrv() (srv.Service, error) | ||
| } | ||
|
|
||
| // NewSrvInitializer returns new SrvInitializer implementation | ||
| func NewSrvInitializer() SrvInitializer { | ||
| return srvInitializer{} | ||
| } | ||
|
|
||
| type srvInitializer struct{} | ||
|
|
||
| // InitJobSrv initializes `job` service with the client and configuration. | ||
| func (i srvInitializer) InitJobSrv() (srv.Service, error) { | ||
| client, err := rootcmd.Client() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| jobApi := jobapi.NewJob(client.Client) | ||
| jobSrv := srv.NewService(jobApi) | ||
| return jobSrv, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.