Improve reconnection policy and context handling in Queryx

This commit is contained in:
Fuad Hasan authored and Sylwia Szunejko committed 2025-01-29 14:38:57 +01:00
1 parent 2f79f86b7c
commit fd84cf32de
2 files changed
+7

No files matched your search

+4
View File
@@ -51,6 +51,10 @@ func CreateCluster() *gocql.ClusterConfig {
cluster.Timeout = *flagTimeout cluster.Timeout = *flagTimeout
cluster.Consistency = gocql.Quorum cluster.Consistency = gocql.Quorum
cluster.MaxWaitSchemaAgreement = 2 * time.Minute // travis might be slow cluster.MaxWaitSchemaAgreement = 2 * time.Minute // travis might be slow
cluster.ReconnectionPolicy = &gocql.ConstantReconnectionPolicy{
MaxRetries: 10,
Interval: 3 * time.Second,
}
if *flagRetry > 0 { if *flagRetry > 0 {
cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: *flagRetry} cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: *flagRetry}
} }
+3
View File
@@ -86,6 +86,9 @@ func (q *Queryx) RoutingKey(routingKey []byte) *Queryx {
// query, queries will be canceled and return once the context is // query, queries will be canceled and return once the context is
// canceled. // canceled.
func (q *Queryx) WithContext(ctx context.Context) *Queryx { func (q *Queryx) WithContext(ctx context.Context) *Queryx {
if ctx == nil {
ctx = context.Background()
}
q.Query = q.Query.WithContext(ctx) q.Query = q.Query.WithContext(ctx)
return q return q
} }