New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

idea: retry builder #84

Open
kamilsk opened this Issue Sep 6, 2017 · 8 comments

Comments

1 participant
@kamilsk
Owner

kamilsk commented Sep 6, 2017

Retrier.Before.Try.Otherwise.Finally

@kamilsk kamilsk added this to the retry 3.0 milestone Sep 6, 2017

@kamilsk kamilsk self-assigned this Sep 6, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Sep 8, 2017

The concept:

ctx := pipeline.Context()
err := retry.New().
	Before(retry.Retry(ctx.Done(), action.Login, login.Strategies...)).
	Try(action.DoSomething).
	Try(action.DoSomethingElse).
	Parallel().
	Try(transaction.Commit).
	Otherwise(transaction.Rollback).
	Finally(connection.Close).
	Do(ctx.Done())

@kamilsk kamilsk changed the title from investigate builder to investigate new retry builder Sep 8, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Sep 8, 2017

type Retrier struct {
	parallel                   []retry.Action
	sequence                   []retry.Action
	before, otherwise, finally func() error
}

func (r *Retrier) Parallel() *Retrier {
	r.parallel = append(r.parallel, r.sequence...)
	r.sequence = []retry.Action{}
	return r
}

func (r *Retrier) Try(action retry.Action) *Retrier {
	r.sequence = append(r.sequence, action)
	return r
}

func (r *Retrier) Do(deadline <-chan struct{}, strategies ...strategy.Strategy) error {
	ch := make(chan error, 1)
	go func() {
		err := <-ch
		if r.finally != nil {
			err := r.finally
			...
		}
		close(...)
	}()
	if r.before != nil {
		r.before()
	}
	for _, action := range r.parallel {
		go func() {
			ch <- retry.Retry(deadline, action, strategies...)
		}()
	}
	...

	return nil
}
@kamilsk

This comment has been minimized.

Owner

kamilsk commented Sep 8, 2017

Maybe is it better to use next semantic:

Try(action.DoSomething, retry.Parallel(action.DoSomethingElse, action.DoSomethingMore)).
@kamilsk

This comment has been minimized.

Owner

kamilsk commented Sep 8, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Sep 8, 2017

Retry(
  Before(Do).Try(Action, Parallel(Action, ...), ...).With(Strategies...).Catch(Do).Finally(Do)
)

@kamilsk kamilsk removed this from the retry 3.0 milestone Nov 29, 2017

@kamilsk kamilsk changed the title from investigate new retry builder to idea: retry builder Nov 29, 2017

@kamilsk kamilsk added this to TODO in Version 4.0 Nov 30, 2017

@kamilsk kamilsk added this to the retry 4.0 milestone Nov 30, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Dec 15, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Dec 19, 2017

@kamilsk

This comment has been minimized.

Owner

kamilsk commented Dec 1, 2018

Repeat(Action).Until(...).Success(callback).Failure(callback)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment