mirror of
https://github.com/ManyakRus/crud_generator.git
synced 2024-12-22 00:36:41 +02:00
сделал Start_ctx()
This commit is contained in:
parent
26c8aca28d
commit
4513765666
@ -1,106 +0,0 @@
|
||||
package grpc_client
|
||||
|
||||
import (
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/stopapp"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SettingsINI struct {
|
||||
SYNC_SERVICE_HOST string
|
||||
SYNC_SERVICE_PORT string
|
||||
}
|
||||
|
||||
var Settings SettingsINI
|
||||
|
||||
var Conn *grpc.ClientConn
|
||||
var Client grpc_proto.SyncServiceClient
|
||||
|
||||
func Connect() {
|
||||
var err error
|
||||
|
||||
if Settings.SYNC_SERVICE_HOST == "" {
|
||||
FillSettings()
|
||||
}
|
||||
|
||||
addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT
|
||||
Conn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
|
||||
log.Info("GRPC client connected. Address: ", addr)
|
||||
|
||||
Client = grpc_proto.NewSyncServiceClient(Conn)
|
||||
}
|
||||
|
||||
func FillSettings() {
|
||||
Settings = SettingsINI{}
|
||||
Settings.SYNC_SERVICE_HOST = os.Getenv("SYNC_SERVICE_HOST")
|
||||
Settings.SYNC_SERVICE_PORT = os.Getenv("SYNC_SERVICE_PORT")
|
||||
|
||||
if Settings.SYNC_SERVICE_HOST == "" {
|
||||
log.Panic("Need fill SYNC_SERVICE_HOST ! in OS Environment ")
|
||||
}
|
||||
|
||||
if Settings.SYNC_SERVICE_PORT == "" {
|
||||
log.Panic("Need fill SYNC_SERVICE_PORT ! in OS Environment ")
|
||||
}
|
||||
}
|
||||
|
||||
// WaitStop - ожидает отмену глобального контекста
|
||||
func WaitStop() {
|
||||
|
||||
select {
|
||||
case <-contextmain.GetContext().Done():
|
||||
log.Warn("Context app is canceled. grpc_connect")
|
||||
}
|
||||
|
||||
// ждём пока отправляемых сейчас сообщений будет =0
|
||||
stopapp.WaitTotalMessagesSendingNow("sync_service_client")
|
||||
|
||||
// закрываем соединение
|
||||
CloseConnection()
|
||||
stopapp.GetWaitGroup_Main().Done()
|
||||
}
|
||||
|
||||
// Start - необходимые процедуры для запуска сервера GRPC
|
||||
func Start() {
|
||||
Connect()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go WaitStop()
|
||||
|
||||
}
|
||||
|
||||
func CloseConnection() {
|
||||
err := Conn.Close()
|
||||
if err != nil {
|
||||
log.Panic("GRPC client CloseConnection() error: ", err)
|
||||
} else {
|
||||
log.Info("GRPC client connection closed")
|
||||
}
|
||||
}
|
||||
|
||||
// IsRecordNotFound - возвращает true если ошибка = "record not found"
|
||||
func IsRecordNotFound(err error) bool {
|
||||
Otvet := false
|
||||
|
||||
if err == nil {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
TextErr := err.Error()
|
||||
pos1 := strings.Index(TextErr, constants.TEXT_RECORD_NOT_FOUND)
|
||||
if pos1 >= 0 {
|
||||
Otvet = true
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
@ -4,19 +4,19 @@ syntax = "proto3";
|
||||
Файл содержит описание сервиса Sync_service
|
||||
*/
|
||||
|
||||
|
||||
package grpc;
|
||||
|
||||
option go_package = "./grpc_proto";
|
||||
|
||||
// Sync_service - сервис обмена с Базой данных
|
||||
service Sync_service {
|
||||
|
||||
//
|
||||
rpc AccountingArea_Read(RequestId) returns (Response) {}
|
||||
rpc AccountingArea_Create(RequestModel) returns (Response) {}
|
||||
rpc AccountingArea_Update(RequestModel) returns (Response) {}
|
||||
rpc AccountingArea_Save(RequestModel) returns (Response) {}
|
||||
rpc AccountingArea_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc AccountingArea_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc AccountingArea_Delete(RequestId) returns (Response) {}
|
||||
rpc AccountingArea_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -33,7 +33,7 @@ service Sync_service {
|
||||
rpc Balance_Create(RequestModel) returns (Response) {}
|
||||
rpc Balance_Update(RequestModel) returns (Response) {}
|
||||
rpc Balance_Save(RequestModel) returns (Response) {}
|
||||
rpc Balance_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Balance_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc Balance_Delete(RequestId) returns (Response) {}
|
||||
rpc Balance_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -42,7 +42,7 @@ service Sync_service {
|
||||
rpc BankAccountOrganization_Create(RequestModel) returns (Response) {}
|
||||
rpc BankAccountOrganization_Update(RequestModel) returns (Response) {}
|
||||
rpc BankAccountOrganization_Save(RequestModel) returns (Response) {}
|
||||
rpc BankAccountOrganization_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc BankAccountOrganization_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc BankAccountOrganization_Delete(RequestId) returns (Response) {}
|
||||
rpc BankAccountOrganization_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -51,7 +51,7 @@ service Sync_service {
|
||||
rpc Bank_Create(RequestModel) returns (Response) {}
|
||||
rpc Bank_Update(RequestModel) returns (Response) {}
|
||||
rpc Bank_Save(RequestModel) returns (Response) {}
|
||||
rpc Bank_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Bank_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc Bank_Delete(RequestId) returns (Response) {}
|
||||
rpc Bank_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -132,12 +132,10 @@ service Sync_service {
|
||||
rpc CompletedMonth_Create(RequestModel) returns (Response) {}
|
||||
rpc CompletedMonth_Update(RequestModel) returns (Response) {}
|
||||
rpc CompletedMonth_Save(RequestModel) returns (Response) {}
|
||||
rpc CompletedMonth_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc CompletedMonth_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc CompletedMonth_Delete(RequestId) returns (Response) {}
|
||||
rpc CompletedMonth_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc ContractBlackItem_Read(RequestId) returns (Response) {}
|
||||
rpc ContractBlackItem_Create(RequestModel) returns (Response) {}
|
||||
@ -151,7 +149,7 @@ service Sync_service {
|
||||
rpc ContractCategoryType_Create(RequestModel) returns (Response) {}
|
||||
rpc ContractCategoryType_Update(RequestModel) returns (Response) {}
|
||||
rpc ContractCategoryType_Save(RequestModel) returns (Response) {}
|
||||
rpc ContractCategoryType_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc ContractCategoryType_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc ContractCategoryType_Delete(RequestId) returns (Response) {}
|
||||
rpc ContractCategoryType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -168,7 +166,7 @@ service Sync_service {
|
||||
rpc Contract_Create(RequestModel) returns (Response) {}
|
||||
rpc Contract_Update(RequestModel) returns (Response) {}
|
||||
rpc Contract_Save(RequestModel) returns (Response) {}
|
||||
rpc Contract_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Contract_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc Contract_Delete(RequestId) returns (Response) {}
|
||||
rpc Contract_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -193,7 +191,7 @@ service Sync_service {
|
||||
rpc DebtType_Create(RequestModel) returns (Response) {}
|
||||
rpc DebtType_Update(RequestModel) returns (Response) {}
|
||||
rpc DebtType_Save(RequestModel) returns (Response) {}
|
||||
rpc DebtType_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc DebtType_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc DebtType_Delete(RequestId) returns (Response) {}
|
||||
rpc DebtType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -218,7 +216,7 @@ service Sync_service {
|
||||
rpc DocumentLink_Create(RequestModel) returns (Response) {}
|
||||
rpc DocumentLink_Update(RequestModel) returns (Response) {}
|
||||
rpc DocumentLink_Save(RequestModel) returns (Response) {}
|
||||
rpc DocumentLink_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc DocumentLink_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc DocumentLink_Delete(RequestId) returns (Response) {}
|
||||
rpc DocumentLink_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -227,7 +225,7 @@ service Sync_service {
|
||||
rpc DocumentType_Create(RequestModel) returns (Response) {}
|
||||
rpc DocumentType_Update(RequestModel) returns (Response) {}
|
||||
rpc DocumentType_Save(RequestModel) returns (Response) {}
|
||||
rpc DocumentType_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc DocumentType_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc DocumentType_Delete(RequestId) returns (Response) {}
|
||||
rpc DocumentType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -236,12 +234,12 @@ service Sync_service {
|
||||
rpc Document_Create(RequestModel) returns (Response) {}
|
||||
rpc Document_Update(RequestModel) returns (Response) {}
|
||||
rpc Document_Save(RequestModel) returns (Response) {}
|
||||
rpc Document_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Document_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc Document_Delete(RequestId) returns (Response) {}
|
||||
rpc Document_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc Employee_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Employee_FindByExtID(RequestExtID) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc EventType_Read(RequestId) returns (Response) {}
|
||||
@ -289,8 +287,6 @@ service Sync_service {
|
||||
rpc FileType_Delete(RequestId) returns (Response) {}
|
||||
rpc FileType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc GenderType_Read(RequestId) returns (Response) {}
|
||||
rpc GenderType_Create(RequestModel) returns (Response) {}
|
||||
@ -320,7 +316,7 @@ service Sync_service {
|
||||
rpc Individual_Create(RequestModel) returns (Response) {}
|
||||
rpc Individual_Update(RequestModel) returns (Response) {}
|
||||
rpc Individual_Save(RequestModel) returns (Response) {}
|
||||
rpc Individual_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Individual_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc Individual_Delete(RequestId) returns (Response) {}
|
||||
rpc Individual_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -380,10 +376,6 @@ service Sync_service {
|
||||
rpc LawsuitStageType_Delete(RequestId) returns (Response) {}
|
||||
rpc LawsuitStageType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc LawsuitType_Read(RequestId) returns (Response) {}
|
||||
rpc LawsuitType_Create(RequestModel) returns (Response) {}
|
||||
@ -393,7 +385,7 @@ service Sync_service {
|
||||
rpc LawsuitType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc Lawsuit_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Lawsuit_FindByExtID(RequestExtID) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc LegalType_Read(RequestId) returns (Response) {}
|
||||
@ -403,8 +395,6 @@ service Sync_service {
|
||||
rpc LegalType_Delete(RequestId) returns (Response) {}
|
||||
rpc LegalType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc MessageSendStatus_Read(RequestId) returns (Response) {}
|
||||
rpc MessageSendStatus_Create(RequestModel) returns (Response) {}
|
||||
@ -413,10 +403,6 @@ service Sync_service {
|
||||
rpc MessageSendStatus_Delete(RequestId) returns (Response) {}
|
||||
rpc MessageSendStatus_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc NotificationType_Read(RequestId) returns (Response) {}
|
||||
rpc NotificationType_Create(RequestModel) returns (Response) {}
|
||||
@ -425,14 +411,12 @@ service Sync_service {
|
||||
rpc NotificationType_Delete(RequestId) returns (Response) {}
|
||||
rpc NotificationType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
|
||||
//
|
||||
rpc OrganizationCategoryType_Read(RequestId) returns (Response) {}
|
||||
rpc OrganizationCategoryType_Create(RequestModel) returns (Response) {}
|
||||
rpc OrganizationCategoryType_Update(RequestModel) returns (Response) {}
|
||||
rpc OrganizationCategoryType_Save(RequestModel) returns (Response) {}
|
||||
rpc OrganizationCategoryType_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc OrganizationCategoryType_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc OrganizationCategoryType_Delete(RequestId) returns (Response) {}
|
||||
rpc OrganizationCategoryType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -445,14 +429,14 @@ service Sync_service {
|
||||
rpc OrganizationStateType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc Organization_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc Organization_FindByExtID(RequestExtID) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc PaymentDay_Read(RequestId) returns (Response) {}
|
||||
rpc PaymentDay_Create(RequestModel) returns (Response) {}
|
||||
rpc PaymentDay_Update(RequestModel) returns (Response) {}
|
||||
rpc PaymentDay_Save(RequestModel) returns (Response) {}
|
||||
rpc PaymentDay_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc PaymentDay_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc PaymentDay_Delete(RequestId) returns (Response) {}
|
||||
rpc PaymentDay_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -461,7 +445,7 @@ service Sync_service {
|
||||
rpc PaymentSchedule_Create(RequestModel) returns (Response) {}
|
||||
rpc PaymentSchedule_Update(RequestModel) returns (Response) {}
|
||||
rpc PaymentSchedule_Save(RequestModel) returns (Response) {}
|
||||
rpc PaymentSchedule_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc PaymentSchedule_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc PaymentSchedule_Delete(RequestId) returns (Response) {}
|
||||
rpc PaymentSchedule_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -470,7 +454,7 @@ service Sync_service {
|
||||
rpc PenaltyCalculationItem_Create(RequestModel) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_Update(RequestModel) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_Save(RequestModel) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_Delete(RequestId) returns (Response) {}
|
||||
rpc PenaltyCalculationItem_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -495,7 +479,7 @@ service Sync_service {
|
||||
rpc ServiceProvider_Create(RequestModel) returns (Response) {}
|
||||
rpc ServiceProvider_Update(RequestModel) returns (Response) {}
|
||||
rpc ServiceProvider_Save(RequestModel) returns (Response) {}
|
||||
rpc ServiceProvider_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc ServiceProvider_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc ServiceProvider_Delete(RequestId) returns (Response) {}
|
||||
rpc ServiceProvider_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -504,7 +488,7 @@ service Sync_service {
|
||||
rpc ServiceType_Create(RequestModel) returns (Response) {}
|
||||
rpc ServiceType_Update(RequestModel) returns (Response) {}
|
||||
rpc ServiceType_Save(RequestModel) returns (Response) {}
|
||||
rpc ServiceType_FindByExtID(RequestExtId) returns (Response) {}
|
||||
rpc ServiceType_FindByExtID(RequestExtID) returns (Response) {}
|
||||
rpc ServiceType_Delete(RequestId) returns (Response) {}
|
||||
rpc ServiceType_Restore(RequestId) returns (Response) {}
|
||||
|
||||
@ -548,7 +532,7 @@ service Sync_service {
|
||||
rpc Organization_Delete(RequestId) returns (Response) {}
|
||||
rpc Organization_Restore(RequestId) returns (Response) {}
|
||||
rpc Organization_FindByInnKpp(RequestInnKpp) returns (Response) {}
|
||||
rpc Organization_FindByExtId(RequestExtId) returns (Response) {}
|
||||
rpc Organization_FindByExtId(RequestExtID) returns (Response) {}
|
||||
|
||||
//
|
||||
rpc File_Read(RequestId) returns (Response) {}
|
||||
@ -586,7 +570,7 @@ service Sync_service {
|
||||
rpc Employee_Save(RequestModel) returns (Response) {}
|
||||
rpc Employee_Delete(RequestId) returns (Response) {}
|
||||
rpc Employee_Restore(RequestId) returns (Response) {}
|
||||
rpc Employee_FindByExtId(RequestExtId) returns (Response) {}
|
||||
rpc Employee_FindByExtId(RequestExtID) returns (Response) {}
|
||||
rpc Employee_FindByLogin(RequestString) returns (Response) {}
|
||||
rpc Employee_FindByEMail(RequestString) returns (Response) {}
|
||||
rpc Employee_FindByFIO(RequestString3) returns (Response) {}
|
||||
@ -600,6 +584,7 @@ service Sync_service {
|
||||
rpc LawsuitStatusState_Restore(RequestId) returns (Response) {}
|
||||
rpc LawsuitStatusState_FillFromLawsuit(RequestIdId) returns (ResponseEmpty) {}
|
||||
rpc LawsuitStatusState_FindDebtSum(RequestIdId) returns (ResponseFloat64) {}
|
||||
rpc LawsuitStatusState_FindLastStatus(RequestIdId) returns (ResponseInt64) {} //находит последний статус претензии, кроме переданного ID
|
||||
|
||||
//
|
||||
rpc LawsuitStatusType_Read(RequestId) returns (Response) {}
|
||||
@ -673,9 +658,9 @@ message RequestString3 {
|
||||
}
|
||||
|
||||
// RequestId - параметры запроса на сервер
|
||||
message RequestExtId {
|
||||
message RequestExtID {
|
||||
uint32 VersionModel= 1; //версия структуры модели
|
||||
int64 Ext_id = 2; // ext_id записи в БД
|
||||
int64 ExtID = 2; // ext_id записи в БД
|
||||
int64 Connection_id =3; // Connection_id записи в БД
|
||||
}
|
||||
|
||||
@ -692,33 +677,36 @@ message RequestInnKpp {
|
||||
string Kpp =3; // КПП
|
||||
}
|
||||
|
||||
// RequestId - параметры запроса на сервер
|
||||
// RequestIdId - параметры запроса на сервер
|
||||
message RequestIdId {
|
||||
uint32 VersionModel= 1; //версия структуры модели
|
||||
int64 ID1 = 2; // id записи в БД
|
||||
int64 ID2 = 3; // id записи в БД
|
||||
int64 iD1 = 2; // id записи в БД
|
||||
int64 iD2 = 3; // id записи в БД
|
||||
}
|
||||
|
||||
// RequestIdIdId - параметры запроса на сервер
|
||||
message RequestIdIdId {
|
||||
uint32 VersionModel= 1; //версия структуры модели
|
||||
int64 ID1 = 2; // id записи в БД
|
||||
int64 ID2 = 3; // id записи в БД
|
||||
int64 ID3 = 4; // id записи в БД
|
||||
int64 iD1 = 2; // id записи в БД
|
||||
int64 iD2 = 3; // id записи в БД
|
||||
int64 iD3 = 4; // id записи в БД
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Response - параметры ответа на клиент
|
||||
// Response - возвращает строка json Модель
|
||||
message Response {
|
||||
string ModelString = 1; //объект-модель в формате json
|
||||
}
|
||||
|
||||
// ResponseFloat64 - параметры ответа на клиент
|
||||
// ResponseFloat64 - возвращает float64
|
||||
message ResponseFloat64 {
|
||||
double Otvet = 1; //Ответ - число
|
||||
}
|
||||
|
||||
// ResponseInt64 - возвращает int64
|
||||
message ResponseInt64 {
|
||||
int64 Otvet = 1; //Ответ - число
|
||||
}
|
||||
|
||||
// Response - параметры ответа на клиент
|
||||
message ResponseEmpty {
|
||||
}
|
@ -245,7 +245,7 @@ func (s *ServerGRPC) LawsuitStatusType_Save(ctx context.Context, Request *grpc_p
|
||||
}
|
||||
|
||||
// LawsuitStatusType_FindByExtID - возвращает запись из БД по ext_id и connection_id
|
||||
func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request *grpc_proto.RequestExtId) (*grpc_proto.Response, error) {
|
||||
func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request *grpc_proto.RequestExtID) (*grpc_proto.Response, error) {
|
||||
var Otvet grpc_proto.Response
|
||||
var err error
|
||||
|
||||
@ -265,7 +265,7 @@ func (s *ServerGRPC) LawsuitStatusType_FindByExtID(ctx context.Context, Request
|
||||
|
||||
//запрос в БД
|
||||
Model := &lawsuit_status_types.LawsuitStatusType{}
|
||||
Model.ExtID = Request.ExtId
|
||||
Model.ExtID = Request.ExtID
|
||||
Model.ConnectionID = Request.ConnectionId
|
||||
err = Model.Find_ByExtID()
|
||||
if err != nil {
|
@ -177,16 +177,16 @@ func Test_server_LawsuitStatusType_FindByExtID(t *testing.T) {
|
||||
|
||||
|
||||
ctx = context.Background()
|
||||
RequestExtId:= grpc_proto.RequestExtId{}
|
||||
RequestExtId.ExtId = Model.ExtID
|
||||
RequestExtId.ConnectionId = Model.ConnectionID
|
||||
RequestExtId.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
||||
RequestExtID:= grpc_proto.RequestExtID{}
|
||||
RequestExtID.ExtID = Model.ExtID
|
||||
RequestExtID.ConnectionId = Model.ConnectionID
|
||||
RequestExtID.VersionModel = lawsuit_status_types.LawsuitStatusType{}.GetStructVersion()
|
||||
|
||||
Otvet, err := server1.LawsuitStatusType_FindByExtID(ctx, &RequestExtId)
|
||||
Otvet, err := server1.LawsuitStatusType_FindByExtID(ctx, &RequestExtID)
|
||||
if err != nil {
|
||||
t.Error("Test_server_LawsuitStatusType_FindByExtId() error: ", err)
|
||||
t.Error("Test_server_LawsuitStatusType_FindByExtID() error: ", err)
|
||||
}
|
||||
if Otvet.ModelString == "" {
|
||||
t.Error("Test_server_LawsuitStatusType_FindByExtId() error: ModelString=''")
|
||||
t.Error("Test_server_LawsuitStatusType_FindByExtID() error: ModelString=''")
|
||||
}
|
||||
}
|
@ -0,0 +1,193 @@
|
||||
package grpc_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/port_checker"
|
||||
"github.com/ManyakRus/starter/stopapp"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SettingsINI - тип структуры для хранения настроек подключени
|
||||
type SettingsINI struct {
|
||||
SYNC_SERVICE_HOST string
|
||||
SYNC_SERVICE_PORT string
|
||||
}
|
||||
|
||||
// SettingsINI - структура для хранения настроек подключени
|
||||
var Settings SettingsINI
|
||||
|
||||
// Conn - подключение к серверу GRPC
|
||||
var Conn *grpc.ClientConn
|
||||
|
||||
// Client - подключение к клиенту GRPC
|
||||
var Client grpc_proto.SyncServiceClient
|
||||
|
||||
// mutexReconnect - защита от многопоточности Reconnect()
|
||||
var mutexReconnect = &sync.Mutex{}
|
||||
|
||||
// NeedReconnect - флаг необходимости переподключения
|
||||
var NeedReconnect bool
|
||||
|
||||
// Connect - подключается к серверу GRPC, при ошибке вызывает панику
|
||||
func Connect() {
|
||||
var err error
|
||||
|
||||
err = Connect_err()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("GRPC Connect() error: %v", err)
|
||||
} else {
|
||||
addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT
|
||||
log.Info("GRPC client connected. Address: ", addr)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Connect_err - подключается к серверу GRPC, возвращает ошибку
|
||||
func Connect_err() error {
|
||||
var err error
|
||||
|
||||
if Settings.SYNC_SERVICE_HOST == "" {
|
||||
FillSettings()
|
||||
}
|
||||
|
||||
addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT
|
||||
Conn, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
|
||||
Client = grpc_proto.NewSyncServiceClient(Conn)
|
||||
return err
|
||||
}
|
||||
|
||||
func FillSettings() {
|
||||
Settings = SettingsINI{}
|
||||
Settings.SYNC_SERVICE_HOST = os.Getenv("SYNC_SERVICE_HOST")
|
||||
Settings.SYNC_SERVICE_PORT = os.Getenv("SYNC_SERVICE_PORT")
|
||||
|
||||
if Settings.SYNC_SERVICE_HOST == "" {
|
||||
log.Panic("Need fill SYNC_SERVICE_HOST ! in OS Environment ")
|
||||
}
|
||||
|
||||
if Settings.SYNC_SERVICE_PORT == "" {
|
||||
log.Panic("Need fill SYNC_SERVICE_PORT ! in OS Environment ")
|
||||
}
|
||||
}
|
||||
|
||||
// WaitStop - ожидает отмену глобального контекста
|
||||
func WaitStop() {
|
||||
|
||||
select {
|
||||
case <-contextmain.GetContext().Done():
|
||||
log.Warn("Context app is canceled. grpc_connect")
|
||||
}
|
||||
|
||||
// ждём пока отправляемых сейчас сообщений будет =0
|
||||
stopapp.WaitTotalMessagesSendingNow("sync_service_client")
|
||||
|
||||
// закрываем соединение
|
||||
CloseConnection()
|
||||
stopapp.GetWaitGroup_Main().Done()
|
||||
}
|
||||
|
||||
// Start - необходимые процедуры для запуска сервера GRPC
|
||||
// если контекст хранится в contextmain.GetContext()
|
||||
func Start() {
|
||||
contextmain.GetContext()
|
||||
ctx := contextmain.Ctx
|
||||
wg := stopapp.GetWaitGroup_Main()
|
||||
Start_ctx(ctx, wg)
|
||||
}
|
||||
|
||||
// Start_ctx - необходимые процедуры для запуска сервера GRPC
|
||||
// ctx - глобальный контекст приложения
|
||||
// wg - глобальный WaitGroup приложения
|
||||
func Start_ctx(ctx *context.Context, wg *sync.WaitGroup) {
|
||||
contextmain.Ctx = ctx
|
||||
stopapp.SetWaitGroup_Main(wg)
|
||||
|
||||
Connect()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go WaitStop()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go ping_go()
|
||||
|
||||
}
|
||||
|
||||
// CloseConnection - закрывает подключение к GRPC, и пишет лог
|
||||
func CloseConnection() {
|
||||
err := CloseConnection_err()
|
||||
if err != nil {
|
||||
log.Error("GRPC client CloseConnection() error: ", err)
|
||||
} else {
|
||||
log.Info("GRPC client connection closed")
|
||||
}
|
||||
}
|
||||
|
||||
// CloseConnection - закрывает подключение к GRPC, и возвращает ошибку
|
||||
func CloseConnection_err() error {
|
||||
err := Conn.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
// IsRecordNotFound - возвращает true если ошибка = "record not found"
|
||||
func IsRecordNotFound(err error) bool {
|
||||
Otvet := false
|
||||
|
||||
if err == nil {
|
||||
return Otvet
|
||||
}
|
||||
|
||||
TextErr := err.Error()
|
||||
pos1 := strings.Index(TextErr, constants.TEXT_RECORD_NOT_FOUND)
|
||||
if pos1 >= 0 {
|
||||
Otvet = true
|
||||
}
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// ping_go - делает пинг каждые 60 секунд, и реконнект
|
||||
func ping_go() {
|
||||
|
||||
ticker := time.NewTicker(60 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
addr := Settings.SYNC_SERVICE_HOST + ":" + Settings.SYNC_SERVICE_PORT
|
||||
|
||||
//бесконечный цикл
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-contextmain.GetContext().Done():
|
||||
log.Warn("Context app is canceled. grpc_client.ping")
|
||||
break loop
|
||||
case <-ticker.C:
|
||||
err := port_checker.CheckPort_err(Settings.SYNC_SERVICE_HOST, Settings.SYNC_SERVICE_PORT)
|
||||
//log.Debug("ticker, ping err: ", err) //удалить
|
||||
if err != nil {
|
||||
NeedReconnect = true
|
||||
log.Warn("grpc_client CheckPort(", addr, ") error: ", err)
|
||||
} else if NeedReconnect == true {
|
||||
log.Warn("grpc_client CheckPort(", addr, ") OK. Start Reconnect()")
|
||||
NeedReconnect = false
|
||||
err = Connect_err()
|
||||
if err != nil {
|
||||
NeedReconnect = true
|
||||
log.Error("grpc_client Connect() error: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stopapp.GetWaitGroup_Main().Done()
|
||||
}
|
@ -291,8 +291,8 @@ func (crud Crud_GRPC) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) er
|
||||
//подготовка запроса
|
||||
var VersionModel = crud.GetVersionModel()
|
||||
|
||||
Request := &grpc_proto.RequestExtId{}
|
||||
Request.ExtId = m.ExtID
|
||||
Request := &grpc_proto.RequestExtID{}
|
||||
Request.ExtID = m.ExtID
|
||||
Request.ConnectionId = m.ConnectionID
|
||||
Request.VersionModel = VersionModel
|
||||
|
@ -1,23 +1,31 @@
|
||||
//Файл создан автоматически кодогенератором crud_generator
|
||||
//Не изменяйте ничего здесь.
|
||||
|
||||
package nrpc_client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/ManyakRus/starter/contextmain"
|
||||
"github.com/ManyakRus/starter/log"
|
||||
"github.com/ManyakRus/starter/port_checker"
|
||||
"github.com/ManyakRus/starter/stopapp"
|
||||
"github.com/nats-io/nats.go"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/api/grpc_proto"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/db/constants"
|
||||
"gitlab.aescorp.ru/dsp_dev/claim/sync_service/pkg/network/grpc/grpc_proto"
|
||||
"sync"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SettingsINI - тип структуры для хранения настроек подключени
|
||||
type SettingsINI struct {
|
||||
NATS_HOST string
|
||||
NATS_PORT string
|
||||
}
|
||||
|
||||
// SettingsINI - структура для хранения настроек подключени
|
||||
var Settings SettingsINI
|
||||
|
||||
// Conn - подключение к NATS
|
||||
@ -26,10 +34,31 @@ var Conn *nats.Conn
|
||||
// Client - подключение к клиенту NRPC
|
||||
var Client *grpc_proto.Sync_serviceClient
|
||||
|
||||
// Connect - подключается к NATS
|
||||
// mutexReconnect - защита от многопоточности Reconnect()
|
||||
var mutexReconnect = &sync.Mutex{}
|
||||
|
||||
// NeedReconnect - флаг необходимости переподключения
|
||||
var NeedReconnect bool
|
||||
|
||||
// Connect - подключается к серверу NRPC, при ошибке вызывает панику
|
||||
func Connect() {
|
||||
var err error
|
||||
|
||||
err = Connect_err()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("NRPC Connect() error: %v", err)
|
||||
} else {
|
||||
NatsURL := "nats://" + Settings.NATS_HOST + ":" + Settings.NATS_PORT
|
||||
log.Info("GRPC client connected. Address: ", NatsURL)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Connect_err - подключается к серверу NRPC, возвращает ошибку
|
||||
func Connect_err() error {
|
||||
var err error
|
||||
|
||||
if Settings.NATS_HOST == "" {
|
||||
FillSettings()
|
||||
}
|
||||
@ -45,7 +74,7 @@ func Connect() {
|
||||
// This is our generated client.
|
||||
Client = grpc_proto.NewSync_serviceClient(Conn)
|
||||
|
||||
log.Info("Client NRPC connected: ", NatsURL)
|
||||
return err
|
||||
}
|
||||
|
||||
// FillSettings - заполняет настройки из переменных окружения
|
||||
@ -63,7 +92,6 @@ func FillSettings() {
|
||||
Settings.NATS_PORT = os.Getenv("BUS_LOCAL_PORT")
|
||||
}
|
||||
|
||||
|
||||
if Settings.NATS_HOST == "" {
|
||||
log.Panic("Need fill BUS_LOCAL_HOST ! in OS Environment ")
|
||||
}
|
||||
@ -90,12 +118,29 @@ func WaitStop() {
|
||||
}
|
||||
|
||||
// Start - необходимые процедуры для запуска сервера NRPC
|
||||
// если контекст хранится в contextmain.GetContext()
|
||||
func Start() {
|
||||
contextmain.GetContext()
|
||||
ctx := contextmain.Ctx
|
||||
wg := stopapp.GetWaitGroup_Main()
|
||||
Start_ctx(ctx, wg)
|
||||
}
|
||||
|
||||
// Start_ctx - необходимые процедуры для запуска сервера NRPC
|
||||
// ctx - глобальный контекст приложения
|
||||
// wg - глобальный WaitGroup приложения
|
||||
func Start_ctx(ctx *context.Context, wg *sync.WaitGroup) {
|
||||
contextmain.Ctx = ctx
|
||||
stopapp.SetWaitGroup_Main(wg)
|
||||
|
||||
Connect()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go WaitStop()
|
||||
|
||||
stopapp.GetWaitGroup_Main().Add(1)
|
||||
go ping_go()
|
||||
|
||||
}
|
||||
|
||||
// CloseConnection - закрывает подключение к NATS
|
||||
@ -122,3 +167,39 @@ func IsRecordNotFound(err error) bool {
|
||||
|
||||
return Otvet
|
||||
}
|
||||
|
||||
// ping_go - делает пинг каждые 60 секунд, и реконнект
|
||||
func ping_go() {
|
||||
|
||||
ticker := time.NewTicker(60 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
addr := Settings.NATS_HOST + ":" + Settings.NATS_PORT
|
||||
|
||||
//бесконечный цикл
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-contextmain.GetContext().Done():
|
||||
log.Warn("Context app is canceled. nrpc_client.ping")
|
||||
break loop
|
||||
case <-ticker.C:
|
||||
err := port_checker.CheckPort_err(Settings.NATS_HOST, Settings.NATS_PORT)
|
||||
//log.Debug("ticker, ping err: ", err) //удалить
|
||||
if err != nil {
|
||||
NeedReconnect = true
|
||||
log.Warn("nrpc_client CheckPort(", addr, ") error: ", err)
|
||||
} else if NeedReconnect == true {
|
||||
log.Warn("nrpc_client CheckPort(", addr, ") OK. Start Reconnect()")
|
||||
NeedReconnect = false
|
||||
err = Connect_err()
|
||||
if err != nil {
|
||||
NeedReconnect = true
|
||||
log.Error("nrpc_client Connect() error: ", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stopapp.GetWaitGroup_Main().Done()
|
||||
}
|
@ -265,8 +265,8 @@ func (crud Crud_NRPC) Find_ByExtID(m *lawsuit_status_types.LawsuitStatusType) er
|
||||
//подготовка запроса
|
||||
var VersionModel = crud.GetVersionModel()
|
||||
|
||||
Request := &grpc_proto.RequestExtId{}
|
||||
Request.ExtId = m.ExtID
|
||||
Request := &grpc_proto.RequestExtID{}
|
||||
Request.ExtID = m.ExtID
|
||||
Request.ConnectionId = m.ConnectionID
|
||||
Request.VersionModel = VersionModel
|
||||
|
@ -175,10 +175,10 @@ func TestFindByExtID(t *testing.T) {
|
||||
err = crud.Find_ByExtID(&Otvet)
|
||||
|
||||
if err != nil {
|
||||
t.Error("TestFindByExtId() error: ", err)
|
||||
t.Error("TestFindByExtID() error: ", err)
|
||||
}
|
||||
|
||||
if Otvet.ID == 0 {
|
||||
t.Error("TestFindByExtId() error: ID =0")
|
||||
t.Error("TestFindByExtID() error: ID =0")
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ type ICrud_LawsuitStatusType interface {
|
||||
Find_ByExtID(*LawsuitStatusType) error
|
||||
}
|
||||
|
||||
// TableName - возвращает имя таблицы в БД, нужен для gorm
|
||||
// TableName - возвращает имя таблицы в БД
|
||||
func (m LawsuitStatusType) TableNameDB() string {
|
||||
return "lawsuit_status_types"
|
||||
}
|
Loading…
Reference in New Issue
Block a user