MODULE_READY can be handled several times
This commit is contained in:
1 parent
481f06bfec
commit
2a846c67e4
4 files changed
+17
-7
No files matched your search
@@ -1,3 +1,5 @@
|
||||
### v3.10.0
|
||||
* событие `MODULE_READY` теперь может быть обработано несколько раз, обновляя полученные данные об инстансе модуля
|
||||
### v3.9.3
|
||||
* обновлены зависимости
|
||||
### v3.9.2
|
||||
|
||||
+12
-4
@@ -4,11 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"isp-config-service/entity"
|
||||
"isp-config-service/middlewares/sql_metrics"
|
||||
"isp-config-service/service/rqlite/db"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Backend struct {
|
||||
@@ -21,8 +22,8 @@ func NewBackend(db db.DB) Backend {
|
||||
}
|
||||
}
|
||||
|
||||
func (r Backend) Insert(ctx context.Context, backend entity.Backend) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.Insert")
|
||||
func (r Backend) Upsert(ctx context.Context, backend entity.Backend) error {
|
||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Backend.Upsert")
|
||||
|
||||
query, args, err := squirrel.Insert(Table("backend")).
|
||||
Columns("ws_connection_id", "module_id", "address",
|
||||
@@ -34,6 +35,13 @@ func (r Backend) Insert(ctx context.Context, backend entity.Backend) error {
|
||||
backend.ConfigServiceNodeId, backend.Endpoints, backend.RequiredModules,
|
||||
backend.MetricsAutodiscovery,
|
||||
).
|
||||
Suffix(`on conflict (ws_connection_id) do update
|
||||
set module_id = excluded.module_id, address = excluded.address,
|
||||
version = excluded.version, lib_version = excluded.lib_version,
|
||||
module_name = excluded.module_name, transport = excluded.transport,
|
||||
config_service_node_id = excluded.config_service_node_id,
|
||||
endpoints = excluded.endpoints, required_modules = excluded.required_modules,
|
||||
metrics_autodiscovery = excluded.metrics_autodiscovery`).
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "build query")
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
type Repo interface {
|
||||
Insert(ctx context.Context, backend entity.Backend) error
|
||||
Upsert(ctx context.Context, backend entity.Backend) error
|
||||
DeleteByWsConnectionIds(ctx context.Context, wsConnIds []string) error
|
||||
GetByConfigServiceNodeId(ctx context.Context, configServiceNodeId string) ([]entity.Backend, error)
|
||||
DeleteByConfigServiceNodeId(ctx context.Context, configServiceNodeId string) (int, error)
|
||||
@@ -86,7 +86,7 @@ func (s Backend) Connect(
|
||||
MetricsAutodiscovery: metricsAd,
|
||||
}
|
||||
|
||||
err := s.backendRepo.Insert(ctx, backend)
|
||||
err := s.backendRepo.Upsert(ctx, backend)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "upsert backend in store")
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user