mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - Fallback to endpoint name in task executor - Fix metrics to use endpoint name instead of ID (regression from #6118) - Signature of ClientProvider changed and no longer requires resolving the nexus endpoint - Renamed `nexusoperations.InvocationTask.Destination` to `EndpointName` - Renamed `nexusoperations.CancelationTask.Destination` to `EndpointName` ## Why? A temporary workaround for not implementing endpoint replication, and endpoint ID being a UUID set by the system, try to get the endpoint by name to support cases where an operator manually created an endpoint with the same name in two replicas. This practice is not recommended in production use cases and when replication is implemented, if endpoints are defined with the same name and different IDs and two replicas, they'll need to nuke their endpoint registry. ## How did you test it? Unit tests and XDC test.
110 lines
3.1 KiB
Go
110 lines
3.1 KiB
Go
// The MIT License
|
|
//
|
|
// Copyright (c) 2024 Temporal Technologies Inc. All rights reserved.
|
|
//
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
// in the Software without restriction, including without limitation the rights
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
// furnished to do so, subject to the following conditions:
|
|
//
|
|
// The above copyright notice and this permission notice shall be included in
|
|
// all copies or substantial portions of the Software.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
package callbacks
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"go.temporal.io/server/service/history/hsm"
|
|
)
|
|
|
|
const (
|
|
TaskTypeInvocation = "callbacks.Invocation"
|
|
TaskTypeBackoff = "callbacks.Backoff"
|
|
)
|
|
|
|
type InvocationTask struct {
|
|
// The base URL for nexus callbacks.
|
|
// Will have other meanings as more callback use cases are added.
|
|
Destination string
|
|
}
|
|
|
|
var _ hsm.Task = InvocationTask{}
|
|
|
|
func (InvocationTask) Type() string {
|
|
return TaskTypeInvocation
|
|
}
|
|
|
|
func (t InvocationTask) Kind() hsm.TaskKind {
|
|
return hsm.TaskKindOutbound{Destination: t.Destination}
|
|
}
|
|
|
|
func (InvocationTask) Concurrent() bool {
|
|
return false
|
|
}
|
|
|
|
type InvocationTaskSerializer struct{}
|
|
|
|
func (InvocationTaskSerializer) Deserialize(data []byte, kind hsm.TaskKind) (hsm.Task, error) {
|
|
if kind, ok := kind.(hsm.TaskKindOutbound); ok {
|
|
return InvocationTask{Destination: kind.Destination}, nil
|
|
}
|
|
return nil, fmt.Errorf("%w: expected outbound", hsm.ErrInvalidTaskKind)
|
|
}
|
|
|
|
func (InvocationTaskSerializer) Serialize(hsm.Task) ([]byte, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
type BackoffTask struct {
|
|
Deadline time.Time
|
|
}
|
|
|
|
var _ hsm.Task = BackoffTask{}
|
|
|
|
func (BackoffTask) Type() string {
|
|
return TaskTypeBackoff
|
|
}
|
|
|
|
func (t BackoffTask) Kind() hsm.TaskKind {
|
|
return hsm.TaskKindTimer{Deadline: t.Deadline}
|
|
}
|
|
|
|
func (BackoffTask) Concurrent() bool {
|
|
return false
|
|
}
|
|
|
|
type BackoffTaskSerializer struct{}
|
|
|
|
func (BackoffTaskSerializer) Deserialize(data []byte, kind hsm.TaskKind) (hsm.Task, error) {
|
|
if kind, ok := kind.(hsm.TaskKindTimer); ok {
|
|
return BackoffTask{Deadline: kind.Deadline}, nil
|
|
}
|
|
return nil, fmt.Errorf("%w: expected timer", hsm.ErrInvalidTaskKind)
|
|
}
|
|
|
|
func (BackoffTaskSerializer) Serialize(hsm.Task) ([]byte, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func RegisterTaskSerializers(reg *hsm.Registry) error {
|
|
if err := reg.RegisterTaskSerializer(TaskTypeInvocation, InvocationTaskSerializer{}); err != nil {
|
|
return err
|
|
}
|
|
if err := reg.RegisterTaskSerializer(TaskTypeBackoff, BackoffTaskSerializer{}); err != nil { // nolint:revive
|
|
return err
|
|
}
|
|
return nil
|
|
}
|