2020-12-10 12:26:40 +00:00
|
|
|
package searchsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Search serves a request to select the objects.
|
|
|
|
func (s *Service) Search(ctx context.Context, prm Prm) error {
|
|
|
|
exec := &execCtx{
|
|
|
|
svc: s,
|
|
|
|
prm: prm,
|
|
|
|
}
|
|
|
|
|
|
|
|
exec.prepare()
|
|
|
|
|
|
|
|
exec.setLogger(s.log)
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.execute(ctx)
|
2020-12-10 12:26:40 +00:00
|
|
|
|
|
|
|
return exec.statusError.err
|
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) execute(ctx context.Context) {
|
2020-12-10 12:26:40 +00:00
|
|
|
exec.log.Debug("serving request...")
|
|
|
|
|
|
|
|
// perform local operation
|
|
|
|
exec.executeLocal()
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.analyzeStatus(ctx, true)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 09:54:21 +00:00
|
|
|
func (exec *execCtx) analyzeStatus(ctx context.Context, execCnr bool) {
|
2020-12-10 12:26:40 +00:00
|
|
|
// analyze local result
|
|
|
|
switch exec.status {
|
|
|
|
default:
|
|
|
|
exec.log.Debug("operation finished with error",
|
|
|
|
zap.String("error", exec.err.Error()),
|
|
|
|
)
|
|
|
|
case statusOK:
|
|
|
|
exec.log.Debug("operation finished successfully")
|
|
|
|
}
|
|
|
|
|
|
|
|
if execCnr {
|
2023-04-04 09:54:21 +00:00
|
|
|
exec.executeOnContainer(ctx)
|
|
|
|
exec.analyzeStatus(ctx, false)
|
2020-12-10 12:26:40 +00:00
|
|
|
}
|
|
|
|
}
|