chore: make the structs internal
They don't need to be exported as they are only used within this plugin.
This commit is contained in:
1 parent
90feb8dc96
commit
574304486a
1 file changed
+15
-15
+15
-15
@@ -6,20 +6,20 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParallelCommand is a type that declares functions
|
// parallelCommand is a type that declares functions
|
||||||
// the ps plugins can execute in parallel
|
// the ps plugins can execute in parallel
|
||||||
type ParallelCommand func(string) error
|
type parallelCommand func(string) error
|
||||||
|
|
||||||
// ParallelCommandResult is the result of a parallel
|
// parallelCommandResult is the result of a parallel
|
||||||
// command run
|
// command run
|
||||||
type ParallelCommandResult struct {
|
type parallelCommandResult struct {
|
||||||
Name string
|
Name string
|
||||||
CommandName string
|
CommandName string
|
||||||
Error error
|
Error error
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCommandAgainstAllApps runs a given ParallelCommand against all apps
|
// RunCommandAgainstAllApps runs a given parallelCommand against all apps
|
||||||
func RunCommandAgainstAllApps(command ParallelCommand, commandName string, parallelCount int) error {
|
func RunCommandAgainstAllApps(command parallelCommand, commandName string, parallelCount int) error {
|
||||||
runInSerial := false
|
runInSerial := false
|
||||||
|
|
||||||
if parallelCount < -1 {
|
if parallelCount < -1 {
|
||||||
@@ -44,8 +44,8 @@ func RunCommandAgainstAllApps(command ParallelCommand, commandName string, paral
|
|||||||
return RunCommandAgainstAllAppsInParallel(command, commandName, parallelCount)
|
return RunCommandAgainstAllAppsInParallel(command, commandName, parallelCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCommandAgainstAllAppsInParallel runs a given ParallelCommand against all apps in parallel
|
// RunCommandAgainstAllAppsInParallel runs a given parallelCommand against all apps in parallel
|
||||||
func RunCommandAgainstAllAppsInParallel(command ParallelCommand, commandName string, parallelCount int) error {
|
func RunCommandAgainstAllAppsInParallel(command parallelCommand, commandName string, parallelCount int) error {
|
||||||
apps, err := DokkuApps()
|
apps, err := DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogWarn(err.Error())
|
LogWarn(err.Error())
|
||||||
@@ -53,7 +53,7 @@ func RunCommandAgainstAllAppsInParallel(command ParallelCommand, commandName str
|
|||||||
}
|
}
|
||||||
|
|
||||||
jobs := make(chan string, parallelCount)
|
jobs := make(chan string, parallelCount)
|
||||||
results := make(chan ParallelCommandResult, len(apps))
|
results := make(chan parallelCommandResult, len(apps))
|
||||||
|
|
||||||
go allocateJobs(apps, jobs)
|
go allocateJobs(apps, jobs)
|
||||||
done := make(chan error)
|
done := make(chan error)
|
||||||
@@ -64,8 +64,8 @@ func RunCommandAgainstAllAppsInParallel(command ParallelCommand, commandName str
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunCommandAgainstAllAppsSerially runs a given ParallelCommand against all apps serially
|
// RunCommandAgainstAllAppsSerially runs a given parallelCommand against all apps serially
|
||||||
func RunCommandAgainstAllAppsSerially(command ParallelCommand, commandName string) error {
|
func RunCommandAgainstAllAppsSerially(command parallelCommand, commandName string) error {
|
||||||
apps, err := DokkuApps()
|
apps, err := DokkuApps()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogWarn(err.Error())
|
LogWarn(err.Error())
|
||||||
@@ -95,7 +95,7 @@ func allocateJobs(input []string, jobs chan string) {
|
|||||||
close(jobs)
|
close(jobs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func aggregateResults(results chan ParallelCommandResult, done chan error) {
|
func aggregateResults(results chan parallelCommandResult, done chan error) {
|
||||||
var parallelError error
|
var parallelError error
|
||||||
errorCount := 0
|
errorCount := 0
|
||||||
for result := range results {
|
for result := range results {
|
||||||
@@ -110,10 +110,10 @@ func aggregateResults(results chan ParallelCommandResult, done chan error) {
|
|||||||
done <- parallelError
|
done <- parallelError
|
||||||
}
|
}
|
||||||
|
|
||||||
func createParallelWorker(jobs chan string, results chan ParallelCommandResult, command ParallelCommand, commandName string, wg *sync.WaitGroup, workerID int) {
|
func createParallelWorker(jobs chan string, results chan parallelCommandResult, command parallelCommand, commandName string, wg *sync.WaitGroup, workerID int) {
|
||||||
for job := range jobs {
|
for job := range jobs {
|
||||||
LogInfo1(fmt.Sprintf("Running command against %s", job))
|
LogInfo1(fmt.Sprintf("Running command against %s", job))
|
||||||
output := ParallelCommandResult{
|
output := parallelCommandResult{
|
||||||
Name: job,
|
Name: job,
|
||||||
CommandName: commandName,
|
CommandName: commandName,
|
||||||
Error: command(job),
|
Error: command(job),
|
||||||
@@ -123,7 +123,7 @@ func createParallelWorker(jobs chan string, results chan ParallelCommandResult,
|
|||||||
wg.Done()
|
wg.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func createParallelWorkerPool(jobs chan string, results chan ParallelCommandResult, command ParallelCommand, commandName string, numberOfWorkers int) {
|
func createParallelWorkerPool(jobs chan string, results chan parallelCommandResult, command parallelCommand, commandName string, numberOfWorkers int) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < numberOfWorkers; i++ {
|
for i := 0; i < numberOfWorkers; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
|||||||
Reference in new issue
Block a user