policies.go 1.0 KB

12345678910111213141516171819202122232425262728
  1. // Copyright (c) 2012 The gocql Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //This file will be the future home for more policies
  5. package gocql
  6. //RetryableQuery is an interface that represents a query or batch statement that
  7. //exposes the correct functions for the retry policy logic to evaluate correctly.
  8. type RetryableQuery interface {
  9. Attempts() int
  10. }
  11. // RetryPolicy is the interface that is used by gocql to determine if a query
  12. // can be retried based on the policy provided by the using application.
  13. // See SimpleRetryPolicy for an example of how to create a custom policy.
  14. type RetryPolicy interface {
  15. Attempt(RetryableQuery) bool
  16. }
  17. // SimpleRetryPolicy is just a simple number of retries logic.
  18. type SimpleRetryPolicy struct {
  19. NumRetries int //Number of times to retry a query
  20. }
  21. //Attempt tells gocql to attempt the query again.
  22. func (s *SimpleRetryPolicy) Attempt(q RetryableQuery) bool {
  23. return q.Attempts() <= s.NumRetries
  24. }