Skip to content

Commit 7acfb63

Browse files
authored
only start worker pool when there's jobs to do (#603)
* only start worker pool when there's jobs to do
1 parent 9f79b76 commit 7acfb63

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

config/getappstructure.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,30 @@ func (settings *GetAppStructureSettings) Execute(sessionState *session.State, ac
7171
structure.logEntry = sessionState.LogEntry
7272
}
7373

74-
pool, err := helpers.NewWorkerPool(10, len(allInfos))
75-
if err != nil {
76-
actionState.AddErrors(errors.Wrap(err, "failed to start worker pool"))
77-
return
78-
}
74+
total := len(allInfos)
75+
if total > 0 { // Only start worker pool if we have work to do
76+
pool, err := helpers.NewWorkerPool(10, total)
77+
if err != nil {
78+
actionState.AddErrors(errors.Wrap(err, "failed to start worker pool"))
79+
return
80+
}
7981

80-
for _, info := range allInfos {
81-
if err := pool.AddTask(func() error {
82-
if info == nil {
83-
return nil
84-
}
82+
for _, info := range allInfos {
83+
if err := pool.AddTask(func() error {
84+
if info == nil {
85+
return nil
86+
}
8587

86-
return structure.getStructureForObjectSync(sessionState, actionState, app, info.Id, info.Type, settings.IncludeRaw)
87-
}); err != nil {
88-
actionState.AddErrors(err)
88+
return structure.getStructureForObjectSync(sessionState, actionState, app, info.Id, info.Type, settings.IncludeRaw)
89+
}); err != nil {
90+
actionState.AddErrors(err)
91+
}
8992
}
90-
}
9193

92-
for result := range pool.Results() {
93-
if result != nil {
94-
actionState.AddErrors(result)
94+
for result := range pool.Results() {
95+
if result != nil {
96+
actionState.AddErrors(result)
97+
}
9598
}
9699
}
97100

0 commit comments

Comments
 (0)