mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? - Refactored Nexus Registry code to merge incoming and outgoing into one registry - Added separate concept of "endpoints" - which is roughly analogous to what was previously called "services" - Upgraded the Nexus Go SDK and API dependencies accordingly - Command handler interface was modified to accept a context given new requirements - Note that invoking a worker endpoint is not yet supported, there will be some minor restructuring required to enable that - Requires this unmerged API PR https://github.com/temporalio/api/pull/403. The two PRs should be merged together. ## Why? Part of late redesign. See also https://github.com/nexus-rpc/api/pull/5 ## How did you test it? Modified existing and added new tests.
115 lines
3.8 KiB
Go
115 lines
3.8 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 sqlite
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"go.temporal.io/server/common/persistence/sql/sqlplugin"
|
|
)
|
|
|
|
const (
|
|
createEndpointsTableVersionQry = `INSERT INTO nexus_endpoints_partition_status(version) VALUES(1)`
|
|
incrementEndpointsTableVersionQry = `UPDATE nexus_endpoints_partition_status SET version = ? WHERE version = ?`
|
|
getEndpointsTableVersionQry = `SELECT version FROM nexus_endpoints_partition_status`
|
|
|
|
createEndpointQry = `INSERT INTO nexus_endpoints(id, data, data_encoding, version) VALUES (?, ?, ?, 1)`
|
|
updateEndpointQry = `UPDATE nexus_endpoints SET data = ?, data_encoding = ?, version = ? WHERE id = ? AND version = ?`
|
|
deleteEndpointQry = `DELETE FROM nexus_endpoints WHERE id = ?`
|
|
getEndpointByIdQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id = ?`
|
|
getEndpointsQry = `SELECT id, data, data_encoding, version FROM nexus_endpoints WHERE id > ? LIMIT ?`
|
|
)
|
|
|
|
func (mdb *db) InitializeNexusEndpointsTableVersion(ctx context.Context) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, createEndpointsTableVersionQry)
|
|
}
|
|
|
|
func (mdb *db) IncrementNexusEndpointsTableVersion(
|
|
ctx context.Context,
|
|
lastKnownTableVersion int64,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, incrementEndpointsTableVersionQry, lastKnownTableVersion+1, lastKnownTableVersion)
|
|
}
|
|
|
|
func (mdb *db) GetNexusEndpointsTableVersion(ctx context.Context) (int64, error) {
|
|
var version int64
|
|
err := mdb.conn.GetContext(ctx, &version, getEndpointsTableVersionQry)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return 0, nil
|
|
}
|
|
return version, err
|
|
}
|
|
|
|
func (mdb *db) InsertIntoNexusEndpoints(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(
|
|
ctx,
|
|
createEndpointQry,
|
|
row.ID,
|
|
row.Data,
|
|
row.DataEncoding)
|
|
}
|
|
|
|
func (mdb *db) UpdateNexusEndpoint(
|
|
ctx context.Context,
|
|
row *sqlplugin.NexusEndpointsRow,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(
|
|
ctx,
|
|
updateEndpointQry,
|
|
row.Data,
|
|
row.DataEncoding,
|
|
row.Version+1,
|
|
row.ID,
|
|
row.Version)
|
|
}
|
|
|
|
func (mdb *db) DeleteFromNexusEndpoints(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (sql.Result, error) {
|
|
return mdb.conn.ExecContext(ctx, deleteEndpointQry, id)
|
|
}
|
|
|
|
func (mdb *db) GetNexusEndpointByID(
|
|
ctx context.Context,
|
|
id []byte,
|
|
) (*sqlplugin.NexusEndpointsRow, error) {
|
|
var row sqlplugin.NexusEndpointsRow
|
|
err := mdb.conn.GetContext(ctx, &row, getEndpointByIdQry, id)
|
|
return &row, err
|
|
}
|
|
|
|
func (mdb *db) ListNexusEndpoints(
|
|
ctx context.Context,
|
|
request *sqlplugin.ListNexusEndpointsRequest,
|
|
) ([]sqlplugin.NexusEndpointsRow, error) {
|
|
var rows []sqlplugin.NexusEndpointsRow
|
|
err := mdb.conn.SelectContext(ctx, &rows, getEndpointsQry, request.LastID, request.Limit)
|
|
return rows, err
|
|
}
|