-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsessionretry.go
37 lines (29 loc) · 1.04 KB
/
sessionretry.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
package cassandra
import (
"context"
"github.com/gocql/gocql"
impulse_ctx "github.com/motiv-labs/impulse-ctx"
log "github.com/motiv-labs/logwrapper"
)
// sessionRetry is an implementation of SessionInterface
type sessionRetry struct {
goCqlSession *gocql.Session
}
// Query wrapper to be able to return our own QueryInterface
func (s sessionRetry) Query(ctx context.Context, stmt string, values ...interface{}) QueryInterface {
impulseCtx, ok := ctx.Value(impulse_ctx.ImpulseCtxKey).(impulse_ctx.ImpulseCtx)
if !ok {
log.Warnf(impulseCtx, "ImpulseCtx isn't correct type")
}
log.Debug(impulseCtx, "running SessionRetry Query() method")
return queryRetry{goCqlQuery: s.goCqlSession.Query(stmt, values...)}
}
// Close wrapper to be able to run goCql method
func (s sessionRetry) Close(ctx context.Context) {
impulseCtx, ok := ctx.Value(impulse_ctx.ImpulseCtxKey).(impulse_ctx.ImpulseCtx)
if !ok {
log.Warnf(impulseCtx, "ImpulseCtx isn't correct type")
}
log.Debug(impulseCtx, "running SessionRetry Close() method")
s.goCqlSession.Close()
}