Skip to content

Commit

Permalink
Add optional threads arg to expand/run commands
Browse files Browse the repository at this point in the history
  • Loading branch information
praqma-thi committed Nov 15, 2023
1 parent 458097b commit f72b947
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ To enforce them, set up a humble cron job running the plugin.

- Options:
- --dry-run _do not delete artifacts [Default: **true**]_
- --recursive _recursively find FileSpecs files in the given dir [Default: false]_
- --recursive _recursively find FileSpecs files in the given dir [Default: false]_
- --threads _amount of worker threads [Default: 3]_

#### expand

Expand All @@ -45,6 +46,9 @@ To enforce them, set up a humble cron job running the plugin.
- config-path _(Path to the JSON config file)_
- output-path _(Path to output the generated FileSpecs)_

- Options:
- --threads _amount of worker threads [Default: 3]_

### running with verbose output

For verbose output to aid in debugging, set `JFROG_CLI_LOG_LEVEL=DEBUG`.
Expand Down
4 changes: 2 additions & 2 deletions commands/artifactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ func GetArtifactoryDetails(context *components.Context) (*config.ServerDetails,
return details, nil
}

func GetArtifactoryManager(context *components.Context, dryRun bool) (artifactory.ArtifactoryServicesManager, error) {
func GetArtifactoryManager(context *components.Context, dryRun bool, threads int) (artifactory.ArtifactoryServicesManager, error) {
artifactoryDetails, cfgErr := GetArtifactoryDetails(context)
if cfgErr != nil {
return nil, cfgErr
}

log.Info("Configuring Artifactory manager")
artifactoryManager, rtfErr := core_utils.CreateServiceManager(artifactoryDetails, 3, 5000, dryRun)
artifactoryManager, rtfErr := core_utils.CreateServiceManagerWithThreads(artifactoryDetails, dryRun, threads, 3, 5000)
if rtfErr != nil {
return nil, rtfErr
}
Expand Down
17 changes: 15 additions & 2 deletions commands/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
type ExpandConfiguration struct {
configFile string
outputPath string
threads int
}

type Policy struct {
Expand Down Expand Up @@ -90,7 +91,14 @@ func GetExpandArguments() []components.Argument {
}

func GetExpandFlags() []components.Flag {
return []components.Flag{}
return []components.Flag{
components.StringFlag{
Name: "threads",
Description: "Number of worker threads",
DefaultValue: "3",
Mandatory: false,
},
}
}

func GetExpandEnvVar() []components.EnvVar {
Expand Down Expand Up @@ -199,7 +207,7 @@ func ExpandCmd(context *components.Context) error {
return parseErr
}

artifactoryManager, rtfErr := GetArtifactoryManager(context, true)
artifactoryManager, rtfErr := GetArtifactoryManager(context, true, expandConfig.threads)
if rtfErr != nil {
return rtfErr
}
Expand Down Expand Up @@ -295,6 +303,11 @@ func ParseExpandConfig(context *components.Context) (*ExpandConfiguration, error
var expandConfig = new(ExpandConfiguration)
expandConfig.configFile = context.Arguments[0]
expandConfig.outputPath = context.Arguments[1]
threads, err := strconv.Atoi(context.GetStringFlagValue("threads"))
if err != nil {
return nil, err
}
expandConfig.threads = threads

return expandConfig, nil
}
14 changes: 13 additions & 1 deletion commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type RunConfiguration struct {
fileSpecsPath string
dryRun bool
recursive bool
threads int
}

func GetRunCommand() components.Command {
Expand Down Expand Up @@ -50,6 +51,12 @@ func GetRunFlags() []components.Flag {
Description: "recursively find filespecs files in the given dir",
DefaultValue: false,
},
components.StringFlag{
Name: "threads",
Description: "Number of worker threads",
DefaultValue: "3",
Mandatory: false,
},
}
}

Expand All @@ -69,7 +76,7 @@ func RunCmd(context *components.Context) error {
log.Debug(" recursive:", runConfig.recursive)

log.Info("Configuring Artifactory manager")
artifactoryManager, rtfErr := GetArtifactoryManager(context, runConfig.dryRun)
artifactoryManager, rtfErr := GetArtifactoryManager(context, runConfig.dryRun, runConfig.threads)
if rtfErr != nil {
return rtfErr
}
Expand Down Expand Up @@ -107,6 +114,11 @@ func ParseRunConfig(context *components.Context) (*RunConfiguration, error) {
runConfig.fileSpecsPath = context.Arguments[0]
runConfig.dryRun = context.GetBoolFlagValue("dry-run")
runConfig.recursive = context.GetBoolFlagValue("recursive")
threads, err := strconv.Atoi(context.GetStringFlagValue("threads"))
if err != nil {
return nil, err
}
runConfig.threads = threads

return runConfig, nil
}
Expand Down

0 comments on commit f72b947

Please sign in to comment.