mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
Merge pull request #97 from foomo/update-temporal-errors
Update temporal errors
This commit is contained in:
commit
319d6940ed
@ -32,6 +32,7 @@ type (
|
||||
func main() {
|
||||
// set env vars to override e.g. example.string
|
||||
_ = os.Setenv("ENV_STRING", "bar")
|
||||
_ = os.Setenv("ENV_STRINGS", "bar baz")
|
||||
_ = os.Setenv("ENV_DURATION", "240h")
|
||||
_ = os.Setenv("STRUCT_STRING", "bar")
|
||||
_ = os.Setenv("STRUCT_NESTED_STRING", "bar")
|
||||
@ -50,6 +51,7 @@ func main() {
|
||||
intFn := config.GetInt(c, "env.int", 1)
|
||||
boolFn := config.GetBool(c, "env.bool", true)
|
||||
stringFn := config.GetString(c, "env.string", "foo")
|
||||
stringsFn := config.GetStringSlice(c, "env.strings", []string{"foo"})
|
||||
durationFn := config.GetDuration(c, "env.duration", time.Minute)
|
||||
|
||||
structFn, err := config.GetStruct(c, "struct", Config{
|
||||
@ -77,12 +79,13 @@ func main() {
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("intCfg: %d\n", intFn())))
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("boolCfg: %v\n", boolFn())))
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("stringCfg: %s\n", stringFn())))
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("stringsCfg: %v\n", stringsFn())))
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("durationCfg: %.2f\n", durationFn().Hours())))
|
||||
_, _ = w.Write([]byte(fmt.Sprintf("stuctCfg: %s\n", spew.Sdump(structCfg))))
|
||||
})
|
||||
|
||||
svr.AddService(
|
||||
keel.NewServiceHTTP(l, "demo", "localhost:8080", svs),
|
||||
keel.NewServiceHTTP(l, "demo", "localhost:8081", svs),
|
||||
)
|
||||
|
||||
svr.Run()
|
||||
|
||||
@ -1,34 +1,73 @@
|
||||
package keeltemporal
|
||||
|
||||
// ActivityCanceledError indicated that the activity is canceled on purpose
|
||||
type ActivityCanceledError struct {
|
||||
error
|
||||
// see https://docs.temporal.io/go/error-handling/
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"go.temporal.io/sdk/temporal"
|
||||
)
|
||||
|
||||
const ActivityErrorType = "keeltemporal.ActivityError"
|
||||
|
||||
func NewActivityError(msg string, err error, details ...interface{}) error {
|
||||
return temporal.NewNonRetryableApplicationError(msg, ActivityErrorType, err, details...)
|
||||
}
|
||||
|
||||
func NewActivityCanceledError(err error) *ActivityCanceledError {
|
||||
return &ActivityCanceledError{
|
||||
error: err,
|
||||
func IsErrorType(err error, errorType string) bool {
|
||||
if applicationErr := AsApplicationError(err); applicationErr != nil && applicationErr.Type() == errorType {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// ActivityFailedError indicated that sth in the activity failed
|
||||
type ActivityFailedError struct {
|
||||
error
|
||||
func IsActivityError(err error) bool {
|
||||
return IsErrorType(err, ActivityErrorType)
|
||||
}
|
||||
|
||||
func NewActivityFailedError(err error) *ActivityFailedError {
|
||||
return &ActivityFailedError{
|
||||
error: err,
|
||||
func IsApplicationError(err error, handler func(applicationErr *temporal.ApplicationError)) bool {
|
||||
return AsApplicationError(err) != nil
|
||||
}
|
||||
|
||||
func AsApplicationError(err error) *temporal.ApplicationError {
|
||||
var applicationErr *temporal.ApplicationError
|
||||
if err != nil && errors.As(err, &applicationErr) {
|
||||
return applicationErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ActivityUnprocessableError indicates that the activity is not
|
||||
type ActivityUnprocessableError struct {
|
||||
error
|
||||
func IsCanceledError(err error, handler func(canceledErr *temporal.CanceledError)) bool {
|
||||
return AsCanceledError(err) != nil
|
||||
}
|
||||
|
||||
func NewActivityUnprocessableError(err error) *ActivityUnprocessableError {
|
||||
return &ActivityUnprocessableError{
|
||||
error: err,
|
||||
func AsCanceledError(err error) *temporal.CanceledError {
|
||||
var canceledErr *temporal.CanceledError
|
||||
if err != nil && errors.As(err, &canceledErr) {
|
||||
return canceledErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsTimeoutError(err error, handler func(timeoutErr *temporal.TimeoutError)) bool {
|
||||
return AsTimeoutError(err) != nil
|
||||
}
|
||||
|
||||
func AsTimeoutError(err error) *temporal.TimeoutError {
|
||||
var timeoutErr *temporal.TimeoutError
|
||||
if err != nil && errors.As(err, &timeoutErr) {
|
||||
return timeoutErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsPanicError(err error, handler func(panicErr *temporal.PanicError)) bool {
|
||||
return AsPanicError(err) != nil
|
||||
}
|
||||
|
||||
func AsPanicError(err error) *temporal.PanicError {
|
||||
var panicErr *temporal.PanicError
|
||||
if err != nil && errors.As(err, &panicErr) {
|
||||
return panicErr
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user