Files
tasks/common/serviceerror/obsolete_matching_task.go
Alex ShtinandGitHub 846d88c8cb Refactor: use new serviceerror.New...f constructors (#7785)
## What changed?
Refactor: use new `serviceerror.New...f` constructors.

## Why?
Most of service errors now supports `fmt.Sprintf` format and they should
be used instead of `fmt.Sprintf`.

## How did you test it?
- [ ] built
- [ ] run locally and tested manually
- [x] covered by existing tests
- [ ] added new unit test(s)
- [ ] added new functional test(s)
2025-05-17 00:21:32 +00:00

61 lines
1.6 KiB
Go

package serviceerror
import (
"fmt"
errordetailsspb "go.temporal.io/server/api/errordetails/v1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type (
// ObsoleteMatchingTask happens when History determines a task that Matching wants to dispatch
// is no longer valid. Some examples:
// - WFT belongs to a sticky queue but the workflow is not on that sticky queue anymore.
// - WFT belongs to the normal queue but no the workflow is on a sticky queue.
// - WF or activity task wants to start but their schedule time directive deployment no longer
// matched the workflows effective deployment.
// When Matching receives this error it can safely drop the task because History has already
// scheduled new Matching tasks on the right task queue and deployment.
ObsoleteMatchingTask struct {
Message string
st *status.Status
}
)
func NewObsoleteMatchingTask(msg string) error {
return &ObsoleteMatchingTask{
Message: msg,
}
}
func NewObsoleteMatchingTaskf(format string, args ...any) error {
return &ObsoleteMatchingTask{
Message: fmt.Sprintf(format, args...),
}
}
// Error returns string message.
func (e *ObsoleteMatchingTask) Error() string {
return e.Message
}
func (e *ObsoleteMatchingTask) Status() *status.Status {
if e.st != nil {
return e.st
}
st := status.New(codes.FailedPrecondition, e.Message)
st, _ = st.WithDetails(
&errordetailsspb.ObsoleteMatchingTaskFailure{},
)
return st
}
func newObsoleteMatchingTask(st *status.Status) error {
return &ObsoleteMatchingTask{
Message: st.Message(),
st: st,
}
}