Skip to content

Commit

Permalink
fix(proxy): wait on the wait group if concurrency selected (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Feb 23, 2024
1 parent 16cae0b commit e672025
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
4 changes: 3 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"blur",
"--files",
"wonky*",
"--dry-run"
"--dry-run",
"--now",
"3"
],
"isBackground": true,
"problemMatcher": {
Expand Down
17 changes: 17 additions & 0 deletions src/app/proxy/common/const-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ type (
Discriminator string // helps to identify files that should be filtered out
}

interactionDefs struct {
Names struct {
Discovery string
Primary string
}
}

definitions struct {
Pixa pixaDefs
ThirdParty thirdPartyDefs
Commands commandDefs
Defaults defaultDefs
Environment environmentDefs
Filing filingDefs
Interaction interactionDefs
}
)

Expand Down Expand Up @@ -95,4 +103,13 @@ var Definitions = definitions{
JournalExt: ".txt",
Discriminator: ".$",
},
Interaction: interactionDefs{
Names: struct {
Discovery string
Primary string
}{
Discovery: "discover",
Primary: "primary",
},
},
}
1 change: 1 addition & 0 deletions src/app/proxy/common/interaction-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type (
// ClientTraverseInfo represents an entity which needs start a navigation
// operation.
ClientTraverseInfo interface {
Name() string
// ActiveOptionsFn allows the client to obtain the options func
// for the current phase.
ActiveOptionsFn() nav.TraverseOptionFn
Expand Down
9 changes: 9 additions & 0 deletions src/app/proxy/user/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ type interaction struct {
arity uint
}

func (u *interaction) IfWithPool(with nav.CreateNewRunnerWith) bool {
// this should go into nav, alongside IfWithPoolUseContext
return with&nav.RunnerWithPool > 0
}

func (u *interaction) navigate(ci common.ClientTraverseInfo,
with nav.CreateNewRunnerWith,
after ...common.AfterFunc,
Expand Down Expand Up @@ -69,6 +74,10 @@ func (u *interaction) navigate(ci common.ClientTraverseInfo,
nav.IfWithPoolUseContext(with, ctx, cancel)...,
)

if u.IfWithPool(with) {
wgan.Wait(boost.GoRoutineName(fmt.Sprintf("👾 %v", ci.Name())))
}

for _, fn := range after {
fn(result, err)
}
Expand Down
17 changes: 10 additions & 7 deletions src/app/proxy/user/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package user
import (
"fmt"
"path/filepath"
"runtime"
"sync/atomic"
"time"

"github.com/charmbracelet/bubbles/spinner"
Expand Down Expand Up @@ -32,9 +34,8 @@ type model struct {
inputs *common.ShrinkCommandInputs
executable string
status string
workload uint
arity uint
level uint
level int32
latest JobDescription
di common.DriverTraverseInfo
ui walker
Expand Down Expand Up @@ -105,7 +106,6 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.result = msg.Result
m.err = msg.Err
m.status = "🎭 discovered"
m.workload = msg.Result.Metrics.Count(nav.MetricNoFilesInvokedEn) * m.arity

if msg.Err != nil {
return m, tea.Quit
Expand All @@ -116,7 +116,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, principal(m.di, m.ui)

case *common.ProgressMsg:
m.level++
atomic.AddInt32(&m.level, 1)
m.latest.Source = msg.Source
m.latest.Destination = msg.Destination
m.latest.Scheme = msg.Scheme
Expand Down Expand Up @@ -188,7 +188,10 @@ func (m *model) View() string {
wpf := m.inputs.Root.WorkerPoolFam.Native
cpus := lo.TernaryF(wpf.NoWorkers > 1 || wpf.CPU,
func() string {
return fmt.Sprintf("%v CPUs", fmt.Sprintf("%v", wpf.CPU))
if wpf.CPU {
return fmt.Sprintf("NumCPUs %v", runtime.NumCPU())
}
return fmt.Sprintf("%v workers", fmt.Sprintf("%v", wpf.NoWorkers))
},
func() string {
return "single CPU"
Expand All @@ -213,13 +216,13 @@ func (m *model) View() string {
--> info: %v
%v
--> error: %v
--> progress: %v of %v
--> progress: %v
`,
m.spinner.View(), executable, m.status,
info,
bc.view(),
e,
m.level, m.workload,
m.level,
)

// the view will be a series of 'lanes', each one representing a job
Expand Down
7 changes: 7 additions & 0 deletions src/app/proxy/user/walk-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

type walkInfo struct {
name string
discoverOptionsFn nav.TraverseOptionFn
principalOptionsFn nav.TraverseOptionFn
activeOptionsFn nav.TraverseOptionFn
Expand All @@ -21,6 +22,7 @@ func NewWalkInfo(discoverOptionsFn nav.TraverseOptionFn,
inputs *common.ShrinkCommandInputs,
) common.DriverTraverseInfo {
return &walkInfo{
name: common.Definitions.Interaction.Names.Discovery,
discoverOptionsFn: discoverOptionsFn,
principalOptionsFn: principalOptionsFn,
activeOptionsFn: discoverOptionsFn,
Expand All @@ -30,6 +32,10 @@ func NewWalkInfo(discoverOptionsFn nav.TraverseOptionFn,
}
}

func (wi *walkInfo) Name() string {
return wi.name
}

func (wi *walkInfo) ActiveOptionsFn() nav.TraverseOptionFn {
return wi.activeOptionsFn
}
Expand All @@ -47,5 +53,6 @@ func (wi *walkInfo) IsDryRun() bool {
}

func (wi *walkInfo) Next() {
wi.name = common.Definitions.Interaction.Names.Primary
wi.activeOptionsFn = wi.principalOptionsFn
}

0 comments on commit e672025

Please sign in to comment.