Merge remote-tracking branch 'origin/delPrivilege' into staging

This commit is contained in:
skeris 2024-07-23 20:12:23 +03:00
commit 7ab7712b2e
13 changed files with 121 additions and 435 deletions

@ -8,8 +8,8 @@ import (
"github.com/themakers/hlog"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/wctools"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/wctools"
"time"
)

@ -8,10 +8,8 @@ import (
"github.com/themakers/hlog"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/customer"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/wctools"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/wctools"
"time"
"github.com/go-redis/redis/v8"
@ -21,7 +19,6 @@ type DepsSendToClient struct {
Redis *redis.Client
Dal *dal.DAL
MailClient *mailclient.Client
CustomerService customer.CustomerServiceClient
}
type SendToClient struct {
@ -176,12 +173,6 @@ func (w *SendToClient) processAnswerWithPrivileges(ctx context.Context, quizName
questionsMap map[uint64]string, privileges []model.ShortPrivilege, account model.Account, allAnswers []model.ResultAnswer,
answerContent model.ResultContent, answerTime time.Time) (bool, error) {
err := w.notificationCustomer(account, privileges)
fmt.Println("ANS81", err)
if err != nil {
return false, err
}
if wctools.HasUnlimitedPrivilege(privileges) {
err := w.ProcessMessageToClient(quizConfig, questionsMap, account, allAnswers, answerContent, answerTime)
if err != nil {
@ -264,47 +255,6 @@ func (w *SendToClient) checkAndSendTaskReminders(ctx context.Context, deps sendT
}
}
func (w *SendToClient) notificationCustomer(account model.Account, privileges []model.ShortPrivilege) error {
for _, privilege := range privileges {
fmt.Println("NOTIFIC", privilege.PrivilegeID, privilege.Amount, !wctools.IsPrivilegeExpired(privilege))
if privilege.PrivilegeID == "quizUnlimTime" && !wctools.IsPrivilegeExpired(privilege) {
rawDetail, err := wctools.ToJSON(privilege)
historyData := &customer.History{
UserID: account.UserID,
Comment: fmt.Sprintf("Привилегия %s просрочена", privilege.PrivilegeID),
Key: "privilege_expired",
RawDetails: rawDetail,
}
_, err = w.deps.CustomerService.InsertHistory(context.Background(), historyData)
if err != nil {
return err
}
}
if privilege.PrivilegeID == "quizCnt" && privilege.Amount == 0 {
rawDetail, err := wctools.ToJSON(privilege)
if err != nil {
return err
}
historyData := &customer.History{
UserID: account.UserID,
Comment: fmt.Sprintf("У привилегии %s истек amount", privilege.PrivilegeID),
Key: "privilege_expired",
RawDetails: rawDetail,
}
_, err = w.deps.CustomerService.InsertHistory(context.Background(), historyData)
if err != nil {
return err
}
}
}
return nil
}
// сделал экспортируемым для теста
func (w *SendToClient) ProcessMessageToClient(quizConfig model.QuizConfig, questionsMap map[uint64]string, account model.Account, allAnswers []model.ResultAnswer, answerContent model.ResultContent, answerTime time.Time) error {
theme := quizConfig.Mailing.Theme

@ -10,15 +10,13 @@ import (
"github.com/skeris/appInit"
"github.com/themakers/hlog"
"go.uber.org/zap"
"google.golang.org/grpc"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/answerwc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/customer"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/privilegewc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/workers/shortstat"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/workers/timeout"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/answerwc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/privilegewc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/workers/shortstat"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/workers/timeout"
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/customer_clients"
"time"
)
@ -136,11 +134,10 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
mailClient := mailclient.NewClient(smtpData)
customerServiceConn, err := grpc.Dial(options.CustomerServiceAddress, grpc.WithInsecure())
if err != nil {
return nil, err
}
customerServiceClient := customer.NewCustomerServiceClient(customerServiceConn)
customerClient := customer_clients.NewCustomersClient(customer_clients.CustomersClientDeps{
Logger: zapLogger,
CustomerServiceHost: options.CustomerServiceAddress,
})
minioClient, err := minio.New(options.MinioEP, &minio.Options{
Creds: credentials.NewStaticV4(options.MinioAK, options.MinioSK, ""),
@ -169,16 +166,13 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
return nil, err
}
checkWorker := privilegewc.NewCheckWorker(privilegewc.CheckWorkerConfig{
DefaultData: model.DefaultData{
PrivilegeID: options.PrivilegeID,
Amount: options.Amount,
UnlimID: options.UnlimID,
},
checkWorker := privilegewc.NewCheckWorker(privilegewc.Deps{
PrivilegeIDsDays: []string{"quizUnlimTime", "squizHideBadge"},
PrivilegeIDsCount: []string{"quizCnt", "quizManual"},
TickerInterval: time.Minute,
Logger: logger,
ErrChan: errChan,
}, pgdal)
PrivilegeDAL: pgdal,
CustomerClient: customerClient,
}, errChan)
go kafkaWorker.Start(ctx)
go checkWorker.Start(ctx)
@ -186,7 +180,6 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
Redis: redisClient,
Dal: pgdal,
MailClient: mailClient,
CustomerService: customerServiceClient,
}, logger, errChan)
toRespWorker := answerwc.NewRespWorker(answerwc.DepsRespWorker{

@ -1,182 +0,0 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.31.0
// protoc (unknown)
// source: customer/service.proto
package customer
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
emptypb "google.golang.org/protobuf/types/known/emptypb"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type History struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
UserID string `protobuf:"bytes,1,opt,name=UserID,proto3" json:"UserID,omitempty"`
Comment string `protobuf:"bytes,2,opt,name=Comment,proto3" json:"Comment,omitempty"`
Key string `protobuf:"bytes,3,opt,name=Key,proto3" json:"Key,omitempty"`
RawDetails string `protobuf:"bytes,4,opt,name=RawDetails,proto3" json:"RawDetails,omitempty"`
}
func (x *History) Reset() {
*x = History{}
if protoimpl.UnsafeEnabled {
mi := &file_customer_service_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *History) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*History) ProtoMessage() {}
func (x *History) ProtoReflect() protoreflect.Message {
mi := &file_customer_service_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use History.ProtoReflect.Descriptor instead.
func (*History) Descriptor() ([]byte, []int) {
return file_customer_service_proto_rawDescGZIP(), []int{0}
}
func (x *History) GetUserID() string {
if x != nil {
return x.UserID
}
return ""
}
func (x *History) GetComment() string {
if x != nil {
return x.Comment
}
return ""
}
func (x *History) GetKey() string {
if x != nil {
return x.Key
}
return ""
}
func (x *History) GetRawDetails() string {
if x != nil {
return x.RawDetails
}
return ""
}
var File_customer_service_proto protoreflect.FileDescriptor
var file_customer_service_proto_rawDesc = []byte{
0x0a, 0x16, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69,
0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d,
0x65, 0x72, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22,
0x6d, 0x0a, 0x07, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73,
0x65, 0x72, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72,
0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03,
0x4b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4b, 0x65, 0x79, 0x12, 0x1e,
0x0a, 0x0a, 0x52, 0x61, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x04, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0a, 0x52, 0x61, 0x77, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x32, 0x4f,
0x0a, 0x0f, 0x43, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63,
0x65, 0x12, 0x3c, 0x0a, 0x0d, 0x49, 0x6e, 0x73, 0x65, 0x72, 0x74, 0x48, 0x69, 0x73, 0x74, 0x6f,
0x72, 0x79, 0x12, 0x11, 0x2e, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x2e, 0x48, 0x69,
0x73, 0x74, 0x6f, 0x72, 0x79, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x00, 0x42,
0x0c, 0x5a, 0x0a, 0x2e, 0x2f, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x62, 0x06, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
file_customer_service_proto_rawDescOnce sync.Once
file_customer_service_proto_rawDescData = file_customer_service_proto_rawDesc
)
func file_customer_service_proto_rawDescGZIP() []byte {
file_customer_service_proto_rawDescOnce.Do(func() {
file_customer_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_customer_service_proto_rawDescData)
})
return file_customer_service_proto_rawDescData
}
var file_customer_service_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
var file_customer_service_proto_goTypes = []interface{}{
(*History)(nil), // 0: customer.History
(*emptypb.Empty)(nil), // 1: google.protobuf.Empty
}
var file_customer_service_proto_depIdxs = []int32{
0, // 0: customer.CustomerService.InsertHistory:input_type -> customer.History
1, // 1: customer.CustomerService.InsertHistory:output_type -> google.protobuf.Empty
1, // [1:2] is the sub-list for method output_type
0, // [0:1] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_customer_service_proto_init() }
func file_customer_service_proto_init() {
if File_customer_service_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_customer_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*History); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_customer_service_proto_rawDesc,
NumEnums: 0,
NumMessages: 1,
NumExtensions: 0,
NumServices: 1,
},
GoTypes: file_customer_service_proto_goTypes,
DependencyIndexes: file_customer_service_proto_depIdxs,
MessageInfos: file_customer_service_proto_msgTypes,
}.Build()
File_customer_service_proto = out.File
file_customer_service_proto_rawDesc = nil
file_customer_service_proto_goTypes = nil
file_customer_service_proto_depIdxs = nil
}

@ -1,108 +0,0 @@
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc (unknown)
// source: customer/service.proto
package customer
import (
context "context"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
const (
CustomerService_InsertHistory_FullMethodName = "/customer.CustomerService/InsertHistory"
)
// CustomerServiceClient is the client API for CustomerService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type CustomerServiceClient interface {
InsertHistory(ctx context.Context, in *History, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
type customerServiceClient struct {
cc grpc.ClientConnInterface
}
func NewCustomerServiceClient(cc grpc.ClientConnInterface) CustomerServiceClient {
return &customerServiceClient{cc}
}
func (c *customerServiceClient) InsertHistory(ctx context.Context, in *History, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, CustomerService_InsertHistory_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// CustomerServiceServer is the server API for CustomerService service.
// All implementations should embed UnimplementedCustomerServiceServer
// for forward compatibility
type CustomerServiceServer interface {
InsertHistory(context.Context, *History) (*emptypb.Empty, error)
}
// UnimplementedCustomerServiceServer should be embedded to have forward compatible implementations.
type UnimplementedCustomerServiceServer struct {
}
func (UnimplementedCustomerServiceServer) InsertHistory(context.Context, *History) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method InsertHistory not implemented")
}
// UnsafeCustomerServiceServer may be embedded to opt out of forward compatibility for this service.
// Use of this interface is not recommended, as added methods to CustomerServiceServer will
// result in compilation errors.
type UnsafeCustomerServiceServer interface {
mustEmbedUnimplementedCustomerServiceServer()
}
func RegisterCustomerServiceServer(s grpc.ServiceRegistrar, srv CustomerServiceServer) {
s.RegisterService(&CustomerService_ServiceDesc, srv)
}
func _CustomerService_InsertHistory_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(History)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CustomerServiceServer).InsertHistory(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CustomerService_InsertHistory_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CustomerServiceServer).InsertHistory(ctx, req.(*History))
}
return interceptor(ctx, in, info, handler)
}
// CustomerService_ServiceDesc is the grpc.ServiceDesc for CustomerService service.
// It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy)
var CustomerService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "customer.CustomerService",
HandlerType: (*CustomerServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "InsertHistory",
Handler: _CustomerService_InsertHistory_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "customer/service.proto",
}

20
go.mod

@ -1,4 +1,4 @@
module penahub.gitlab.yandexcloud.net/backend/quiz/worker.git
module penahub.gitlab.yandexcloud.net/backend/quiz/worker
go 1.22.0
@ -15,10 +15,9 @@ require (
github.com/themakers/hlog v0.0.0-20191205140925-235e0e4baddf
github.com/twmb/franz-go v1.17.0
go.uber.org/zap v1.27.0
golang.org/x/net v0.25.0
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1
golang.org/x/net v0.26.0
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240617173955-a34278088ddd
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240704132928-7e6f6e267d71
)
@ -52,12 +51,13 @@ require (
github.com/valyala/fasthttp v1.54.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c // indirect
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.0 // indirect
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607202348-efe5f2bf3e8c // indirect
)

44
go.sum

@ -32,8 +32,9 @@ github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ib
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
@ -75,6 +76,8 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/skeris/appInit v1.0.2 h1:Hr4KbXYd6kolTVq4cXGqDpgnpmaauiOiKizA1+Ep4KQ=
@ -109,40 +112,41 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
@ -155,9 +159,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c h1:jxnyIeC2CNDNmfdFx2qnLS4Qd0v5ocYrY9X+OL9qsvc=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240527160654-bd1c2126bc6c/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607202348-efe5f2bf3e8c h1:CWb4UcuNXhd1KTNOmy2U0TJO4+Qxgxrj5cwkyFqbgrk=
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240607202348-efe5f2bf3e8c/go.mod h1:+bPxq2wfW5S1gd+83vZYmHm33AE7nEBfznWS8AM1TKE=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240617173955-a34278088ddd h1:/FW9GjEbxXWD5/e3oUGn4iKihhc77FvfDPnVqL1SQvM=
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240617173955-a34278088ddd/go.mod h1:n66zm88Dh12+idyfqh0vU5nd9BZYxM6Pv0XYnmy0398=
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.0 h1:PkXvLTnVgnch+O81wWU0ayLe6CfccP/wKgOCu/xc9sc=
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.0/go.mod h1:fKiHnVzo7ScG4LNQABOxe7EdAfyu6RpkpAIXBx2I19k=
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240704132928-7e6f6e267d71 h1:Zvtn7Va/QBycMUiskrTZWFEMtz53xcW0d8VcKu9sEwk=
penahub.gitlab.yandexcloud.net/pena-services/customer v1.0.1-0.20240704132928-7e6f6e267d71/go.mod h1:KA4gYdLDt/fzK4YcyC0if00Q7nYuE1DMQEGMdQgUF/8=

@ -2,7 +2,7 @@ package main
import (
"github.com/skeris/appInit"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/app"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/app"
)
func main() {

@ -3,40 +3,49 @@ package privilegewc
import (
"context"
"fmt"
"github.com/themakers/hlog"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/customer_clients"
"time"
)
type CheckWorkerConfig struct {
type Deps struct {
PrivilegeDAL *dal.DAL
TickerInterval time.Duration
DefaultData model.DefaultData
Logger hlog.Logger
ErrChan chan<- error
PrivilegeIDsDays []string
PrivilegeIDsCount []string
CustomerClient *customer_clients.CustomersClient
}
type CheckWorker struct {
config CheckWorkerConfig
privilegeDAL *dal.DAL
tickerInterval time.Duration
errChan chan<- error
privilegeIDsDays []string
privilegeIDsCount []string
customerClient *customer_clients.CustomersClient
}
func NewCheckWorker(config CheckWorkerConfig, privilegeDAL *dal.DAL) *CheckWorker {
func NewCheckWorker(deps Deps, errChan chan<- error) *CheckWorker {
return &CheckWorker{
config: config,
privilegeDAL: privilegeDAL,
privilegeDAL: deps.PrivilegeDAL,
tickerInterval: deps.TickerInterval,
errChan: errChan,
privilegeIDsCount: deps.PrivilegeIDsCount,
privilegeIDsDays: deps.PrivilegeIDsDays,
customerClient: deps.CustomerClient,
}
}
func (w *CheckWorker) Start(ctx context.Context) {
ticker := time.NewTicker(w.config.TickerInterval)
ticker := time.NewTicker(w.tickerInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
fmt.Println("CHECK")
w.performScheduledTasks(ctx)
w.deleteExpired(ctx)
case <-ctx.Done():
fmt.Println("Check worker terminated")
return
@ -44,24 +53,44 @@ func (w *CheckWorker) Start(ctx context.Context) {
}
}
// TODO: Maybe one query?
func (w *CheckWorker) performScheduledTasks(ctx context.Context) {
fmt.Println("CHEC0")
w.deleteExpired(ctx)
func (w *CheckWorker) deleteExpired(ctx context.Context) {
var toHistory []customer_clients.InsertHistoryDeps
var expiredData []model.ExpiredPrivileges
for _, id := range w.privilegeIDsDays {
expired, err := w.privilegeDAL.AccountRepo.GetExpired(ctx, id)
if err != nil {
w.errChan <- err
}
expiredData = append(expiredData, expired...)
}
func (w *CheckWorker) deleteExpired(ctx context.Context) {
expiredData, err := w.privilegeDAL.AccountRepo.GetExpired(ctx, w.config.DefaultData.UnlimID)
for _, id := range w.privilegeIDsCount {
expired, err := w.privilegeDAL.AccountRepo.GetExpiredCount(ctx, id)
if err != nil {
w.config.Logger.Module("Error getting expired quizUnlimTime records")
w.config.ErrChan <- err
w.errChan <- err
}
expiredData = append(expiredData, expired...)
}
for _, data := range expiredData {
err := w.privilegeDAL.AccountRepo.DeletePrivilegeByID(ctx, data.Privilege.ID)
if err != nil {
w.config.Logger.Module("Error deleting expired quizUnlimTime record")
w.config.ErrChan <- err
w.errChan <- err
continue
}
toHistory = append(toHistory, customer_clients.InsertHistoryDeps{
UserID: data.UserID,
Comment: fmt.Sprintf("%s privilege has expired, it was created at %d", data.Privilege.PrivilegeID, data.Privilege.CreatedAt.Unix()),
Key: "privilege_expired",
})
}
for _, to := range toHistory {
err := w.customerClient.InsertHistory(ctx, to)
if err != nil {
w.errChan <- err
}
}
}

@ -8,7 +8,7 @@ import (
"github.com/twmb/franz-go/pkg/kgo"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/wctools"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/wctools"
"strings"
"time"
)

@ -6,8 +6,8 @@ import (
"github.com/pioz/faker"
"github.com/stretchr/testify/assert"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/answerwc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/clients/mailclient"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/answerwc"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/clients/mailclient"
"testing"
"time"
)

@ -5,7 +5,7 @@ import (
"database/sql"
"fmt"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/workers"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/workers"
"time"
)

@ -4,7 +4,7 @@ import (
"context"
"database/sql"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker.git/workers"
"penahub.gitlab.yandexcloud.net/backend/quiz/worker/workers"
"time"
)