Skip to content

Commit

Permalink
fix: start discoverer client before the logic is executed
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Nov 1, 2023
1 parent b950fc8 commit 25173a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
6 changes: 6 additions & 0 deletions pkg/index/job/creation/service/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (

// Indexer represents an interface for indexing.
type Indexer interface {
PreStart(ctx context.Context) (<-chan error, error)
Start(ctx context.Context) error
}

Expand Down Expand Up @@ -70,6 +71,11 @@ func New(opts ...Option) (Indexer, error) {
return idx, nil

Check warning on line 71 in pkg/index/job/creation/service/indexer.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/service/indexer.go#L67-L71

Added lines #L67 - L71 were not covered by tests
}

// PreStart starts the preparation process.
func (idx *index) PreStart(ctx context.Context) (<-chan error, error) {
return idx.client.Start(ctx)

Check warning on line 76 in pkg/index/job/creation/service/indexer.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/service/indexer.go#L75-L76

Added lines #L75 - L76 were not covered by tests
}

// Start starts indexing process.
func (idx *index) Start(ctx context.Context) error {
ctx, span := trace.StartSpan(ctx, apiName+"/service/index.Start")
Expand Down
19 changes: 7 additions & 12 deletions pkg/index/job/creation/usecase/creation.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,18 @@ func (r *run) PreStart(ctx context.Context) error {
// during the operation and an error representing any initialization errors.
func (r *run) Start(ctx context.Context) (<-chan error, error) {
ech := make(chan error, 4)
iech := make(chan error, 1)
var sech, oech <-chan error
if r.observability != nil {
oech = r.observability.Start(ctx)
}
sech = r.server.ListenAndServe(ctx)
ipech, err := r.indexer.PreStart(ctx)
if err != nil {
close(ech)
return nil, err
}

Check warning on line 150 in pkg/index/job/creation/usecase/creation.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/usecase/creation.go#L139-L150

Added lines #L139 - L150 were not covered by tests

r.eg.Go(safety.RecoverFunc(func() (err error) {
defer close(iech)
defer func() {
p, err := os.FindProcess(os.Getpid())
if err != nil {
Expand All @@ -160,14 +163,7 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) {
log.Error(err)
}

Check warning on line 164 in pkg/index/job/creation/usecase/creation.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/usecase/creation.go#L152-L164

Added lines #L152 - L164 were not covered by tests
}()
if err = r.indexer.Start(ctx); err != nil {
select {
case <-ctx.Done():
return errors.Join(ctx.Err(), err)
case iech <- err:
}
}
return err
return r.indexer.Start(ctx)

Check warning on line 166 in pkg/index/job/creation/usecase/creation.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/usecase/creation.go#L166

Added line #L166 was not covered by tests
}))

r.eg.Go(safety.RecoverFunc(func() (err error) {
Expand All @@ -178,7 +174,7 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) {
return ctx.Err()
case err = <-oech:
case err = <-sech:
case err = <-iech:
case err = <-ipech:

Check warning on line 177 in pkg/index/job/creation/usecase/creation.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/usecase/creation.go#L169-L177

Added lines #L169 - L177 were not covered by tests
}
if err != nil {
select {
Expand All @@ -189,7 +185,6 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) {
}
}
}))

return ech, nil

Check warning on line 188 in pkg/index/job/creation/usecase/creation.go

View check run for this annotation

Codecov / codecov/patch

pkg/index/job/creation/usecase/creation.go#L188

Added line #L188 was not covered by tests
}

Expand Down

0 comments on commit 25173a5

Please sign in to comment.