package retrystrategy

import (
	"time"

	boshlog "github.com/cloudfoundry/bosh-utils/logger"
)

type attemptRetryStrategy struct {
	maxAttempts int
	delay       time.Duration
	retryable   Retryable
	logger      boshlog.Logger
	logTag      string
}

func NewAttemptRetryStrategy(
	maxAttempts int,
	delay time.Duration,
	retryable Retryable,
	logger boshlog.Logger,
) RetryStrategy {
	return &attemptRetryStrategy{
		maxAttempts: maxAttempts,
		delay:       delay,
		retryable:   retryable,
		logger:      logger,
		logTag:      "attemptRetryStrategy",
	}
}

func (s *attemptRetryStrategy) Try() error {
	var err error
	var isRetryable bool

	for i := 0; i < s.maxAttempts; i++ {
		s.logger.Debug(s.logTag, "Making attempt #%d", i)

		isRetryable, err = s.retryable.Attempt()
		if err == nil {
			return nil
		}

		if !isRetryable {
			return err
		}

		time.Sleep(s.delay)
	}

	return err
}

package retrystrategy

import (
	"reflect"
	"time"

	boshlog "github.com/cloudfoundry/bosh-utils/logger"
)

type attemptRetryStrategy struct {
	maxAttempts int
	delay       time.Duration
	retryable   Retryable
	logger      boshlog.Logger
	logTag      string
}

func NewAttemptRetryStrategy(
	maxAttempts int,
	delay time.Duration,
	retryable Retryable,
	logger boshlog.Logger,
) RetryStrategy {
	return &attemptRetryStrategy{
		maxAttempts: maxAttempts,
		delay:       delay,
		retryable:   retryable,
		logger:      logger,
		logTag:      "attemptRetryStrategy",
	}
}

func (s *attemptRetryStrategy) Try() error {
	var err error
	var isRetryable bool

	for i := 0; i < s.maxAttempts; i++ {
		s.logger.Debug(s.logTag, "Making attempt #%d for %s", i, reflect.TypeOf(s.retryable))

		isRetryable, err = s.retryable.Attempt()
		if err == nil {
			return nil
		}

		if !isRetryable {
			return err
		}

		time.Sleep(s.delay)
	}

	return err
}

Enhance debug output for retry strategies
Enhance debug output for retry strategies

Retry strategies outputs the retryable type

[#129348495](https://www.pivotaltracker.com/story/show/129348495)

Signed-off-by: Beyhan Veli <0702de361e3c91d973ce2c0ee3e34845ebaf95e6@sap.com>
