-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.go
54 lines (49 loc) · 1.9 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package service
import (
"fmt"
"github.com/cenkalti/backoff/v4"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-api/repository"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/common"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-common-module/utils"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/log"
"github.com/pkg/errors"
"golang.org/x/net/context"
"time"
)
func WaitForNodeCreatedInNeo4j(ctx context.Context, repositories *repository.Repositories, id, nodeLabel string, span opentracing.Span) {
operation := func() error {
found, findErr := repositories.Neo4jRepositories.CommonReadRepository.ExistsById(ctx, common.GetTenantFromContext(ctx), id, nodeLabel)
if findErr != nil {
return findErr
}
if !found {
return errors.New(fmt.Sprintf("Node %s with id %s not found in Neo4j", nodeLabel, id))
}
return nil
}
err := backoff.Retry(operation, utils.BackOffConfig(100*time.Millisecond, 1.5, 1*time.Second, 5*time.Second, 10))
if err != nil {
span.LogFields(log.Bool("result.created", false))
} else {
span.LogFields(log.Bool("result.created", true))
}
}
func WaitForNodeDeletedFromNeo4j(ctx context.Context, repositories *repository.Repositories, id, nodeLabel string, span opentracing.Span) {
operation := func() error {
found, findErr := repositories.Neo4jRepositories.CommonReadRepository.ExistsById(ctx, common.GetTenantFromContext(ctx), id, nodeLabel)
if findErr != nil {
return findErr
}
if found {
return errors.New(fmt.Sprintf("Node %s with id %s still exists in Neo4j", nodeLabel, id))
}
return nil
}
err := backoff.Retry(operation, utils.BackOffConfig(100*time.Millisecond, 1.5, 1*time.Second, 5*time.Second, 10))
if err != nil {
span.LogFields(log.Bool("result.deleted", false))
} else {
span.LogFields(log.Bool("result.deleted", true))
}
}