Skip to content
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

feat: add func invoker #744

Merged
merged 12 commits into from
Dec 21, 2024
23 changes: 10 additions & 13 deletions pkg/saga/statemachine/engine/invoker/func_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,19 @@ func (f *FuncServiceImpl) needRetry(impl *state.ServiceTaskStateImpl, countMap m
return false
}

currentInterval := f.calculateRetryInterval(retry, attempt)
interval := retry.IntervalSecond()
backoffRate := retry.BackoffRate()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 195 以下这块代码可以精简为:
backoffRate := retry.BackoffRate()
curInterval := int64(interval * 1000)
if attempt {
curInterval = int64(interval * backoffRate * float64(attempt) * 1000)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var curInterval int64
if attempt == 0 {
curInterval = int64(interval * 1000)
} else {
curInterval = int64(interval * backoffRate * float64(attempt) * 1000)
}

log.Warnf("invoke service[%s.%s] failed, will retry after %s millis, current retry count: %s, current err: %s",
impl.ServiceName(), impl.ServiceMethod(), currentInterval, attempt, err)
impl.ServiceName(), impl.ServiceMethod(), curInterval, attempt, err)

time.Sleep(time.Duration(currentInterval) * time.Millisecond)
time.Sleep(time.Duration(curInterval) * time.Millisecond)
countMap[retry] = attempt + 1
return true
}

func (f *FuncServiceImpl) calculateRetryInterval(retry state.Retry, attempt int) int64 {
intervalSecond := retry.IntervalSecond()
backoffRate := retry.BackoffRate()

if attempt == 0 {
return int64(intervalSecond * 1000)
}
return int64(intervalSecond * backoffRate * float64(attempt) * 1000)
}
Loading