mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
140 lines
3.7 KiB
Go
140 lines
3.7 KiB
Go
package persistence
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
enumspb "go.temporal.io/api/enums/v1"
|
|
"go.temporal.io/api/serviceerror"
|
|
persistencespb "go.temporal.io/server/api/persistence/v1"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/log/tag"
|
|
"go.temporal.io/server/common/persistence/serialization"
|
|
)
|
|
|
|
var (
|
|
ErrNexusTableVersionConflict = serviceerror.NewFailedPrecondition("nexus endpoints table version mismatch")
|
|
ErrNexusEndpointVersionConflict = serviceerror.NewFailedPrecondition("nexus endpoint version mismatch")
|
|
ErrNegativeListNexusEndpointsPageSize = &InvalidPersistenceRequestError{
|
|
Msg: "received negative page size for listing Nexus endpoints",
|
|
}
|
|
)
|
|
|
|
type (
|
|
nexusEndpointManagerImpl struct {
|
|
persistence NexusEndpointStore
|
|
serializer serialization.Serializer
|
|
logger log.Logger
|
|
}
|
|
)
|
|
|
|
func NewNexusEndpointManager(
|
|
persistence NexusEndpointStore,
|
|
serializer serialization.Serializer,
|
|
logger log.Logger,
|
|
) NexusEndpointManager {
|
|
return &nexusEndpointManagerImpl{
|
|
persistence: persistence,
|
|
serializer: serializer,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) GetName() string {
|
|
return m.persistence.GetName()
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) Close() {
|
|
m.persistence.Close()
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) GetNexusEndpoint(
|
|
ctx context.Context,
|
|
request *GetNexusEndpointRequest,
|
|
) (*persistencespb.NexusEndpointEntry, error) {
|
|
internalEndpoint, err := m.persistence.GetNexusEndpoint(ctx, request)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
endpoint, err := m.serializer.NexusEndpointFromBlob(internalEndpoint.Data)
|
|
if err != nil {
|
|
m.logger.Error(fmt.Sprintf("error deserializing nexus endpoint with ID:%v", internalEndpoint.ID), tag.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
return &persistencespb.NexusEndpointEntry{
|
|
Id: internalEndpoint.ID,
|
|
Version: internalEndpoint.Version,
|
|
Endpoint: endpoint,
|
|
}, nil
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) ListNexusEndpoints(
|
|
ctx context.Context,
|
|
request *ListNexusEndpointsRequest,
|
|
) (*ListNexusEndpointsResponse, error) {
|
|
if request.PageSize < 0 {
|
|
return nil, ErrNegativeListNexusEndpointsPageSize
|
|
}
|
|
|
|
result := &ListNexusEndpointsResponse{}
|
|
|
|
resp, err := m.persistence.ListNexusEndpoints(ctx, request)
|
|
if resp != nil {
|
|
result.TableVersion = resp.TableVersion
|
|
}
|
|
if err != nil {
|
|
return result, err
|
|
}
|
|
|
|
entries := make([]*persistencespb.NexusEndpointEntry, len(resp.Endpoints))
|
|
for i, entry := range resp.Endpoints {
|
|
endpoint, err := m.serializer.NexusEndpointFromBlob(entry.Data)
|
|
if err != nil {
|
|
m.logger.Error(fmt.Sprintf("error deserializing nexus endpoint with ID: %v", entry.ID), tag.Error(err))
|
|
return nil, err
|
|
}
|
|
entries[i] = &persistencespb.NexusEndpointEntry{
|
|
Id: entry.ID,
|
|
Version: entry.Version,
|
|
Endpoint: endpoint,
|
|
}
|
|
}
|
|
|
|
result.NextPageToken = resp.NextPageToken
|
|
result.Entries = entries
|
|
return result, nil
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) CreateOrUpdateNexusEndpoint(
|
|
ctx context.Context,
|
|
request *CreateOrUpdateNexusEndpointRequest,
|
|
) (*CreateOrUpdateNexusEndpointResponse, error) {
|
|
blob, err := m.serializer.NexusEndpointToBlob(request.Entry.Endpoint, enumspb.ENCODING_TYPE_PROTO3)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = m.persistence.CreateOrUpdateNexusEndpoint(ctx, &InternalCreateOrUpdateNexusEndpointRequest{
|
|
LastKnownTableVersion: request.LastKnownTableVersion,
|
|
Endpoint: InternalNexusEndpoint{
|
|
ID: request.Entry.Id,
|
|
Version: request.Entry.Version,
|
|
Data: blob,
|
|
},
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &CreateOrUpdateNexusEndpointResponse{Version: request.Entry.Version + 1}, nil
|
|
}
|
|
|
|
func (m *nexusEndpointManagerImpl) DeleteNexusEndpoint(
|
|
ctx context.Context,
|
|
request *DeleteNexusEndpointRequest,
|
|
) error {
|
|
return m.persistence.DeleteNexusEndpoint(ctx, request)
|
|
}
|