fix badge some deleted if expired
This commit is contained in:
parent
8e6e09daa0
commit
14dc33368f
20
app/app.go
20
app/app.go
@ -11,7 +11,6 @@ import (
|
||||
"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"
|
||||
@ -50,19 +49,16 @@ var _ appInit.CommonApp = (*App)(nil)
|
||||
|
||||
type Options struct {
|
||||
ServiceName string `env:"SERVICE_NAME" default:"squiz"`
|
||||
KafkaBroker string `env:"KAFKA_BROKER"`
|
||||
KafkaTopic string `env:"KAFKA_TOPIC"`
|
||||
PrivilegeID string `env:"QUIZ_ID"`
|
||||
Amount uint64 `env:"AMOUNT"`
|
||||
UnlimID string `env:"UNLIM_ID"`
|
||||
KafkaBroker string `env:"KAFKA_BROKER" default:"localhost:6379"`
|
||||
KafkaTopic string `env:"KAFKA_TOPIC" default:"test-topic"`
|
||||
LoggerProdMode bool `env:"IS_PROD_LOG" default:"false"`
|
||||
IsProd bool `env:"IS_PROD" default:"false"`
|
||||
MinioEP string `env:"MINIO_EP" default:"localhost:3002"`
|
||||
MinioAK string `env:"MINIO_AK" default:"minio"`
|
||||
MinioSK string `env:"MINIO_SK" default:"miniostorage"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=5432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
PostgresCredentials string `env:"PG_CRED" default:"host=localhost port=35432 user=squiz password=Redalert2 dbname=squiz sslmode=disable"`
|
||||
RedisHost string `env:"REDIS_HOST" default:"localhost:6379"`
|
||||
RedisPassword string `env:"REDIS_PASSWORD"`
|
||||
RedisPassword string `env:"REDIS_PASSWORD" default:"test"`
|
||||
RedisDB uint64 `env:"REDIS_DB" default:"2"`
|
||||
SmtpHost string `env:"SMTP_HOST" default:"connect.mailclient.bz"`
|
||||
SmtpPort string `env:"SMTP_PORT" default:"587"`
|
||||
@ -71,7 +67,7 @@ type Options struct {
|
||||
SmtpPassword string `env:"SMTP_PASSWORD" default:"vWwbCSg4bf0p"`
|
||||
SmtpApiKey string `env:"SMTP_API_KEY" default:"P0YsjUB137upXrr1NiJefHmXVKW1hmBWlpev"`
|
||||
SmtpApiUrl string `env:"SMTP_API_URL" default:"https://api.smtp.bz/v1/smtp/send"`
|
||||
CustomerServiceAddress string `env:"CUSTOMER_SERVICE_ADDRESS"`
|
||||
CustomerServiceAddress string `env:"CUSTOMER_SERVICE_ADDRESS" default:"http://localhost:8081"`
|
||||
}
|
||||
|
||||
func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.CommonApp, error) {
|
||||
@ -171,11 +167,7 @@ func New(ctx context.Context, opts interface{}, ver appInit.Version) (appInit.Co
|
||||
}
|
||||
|
||||
checkWorker := privilegewc.NewCheckWorker(privilegewc.CheckWorkerConfig{
|
||||
DefaultData: model.DefaultData{
|
||||
PrivilegeID: options.PrivilegeID,
|
||||
Amount: options.Amount,
|
||||
UnlimID: options.UnlimID,
|
||||
},
|
||||
PrivilegeIDs: []string{"quizUnlimTime", "squizHideBadge"},
|
||||
TickerInterval: time.Minute,
|
||||
Logger: logger,
|
||||
ErrChan: errChan,
|
||||
|
@ -5,15 +5,14 @@ import (
|
||||
"fmt"
|
||||
"github.com/themakers/hlog"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CheckWorkerConfig struct {
|
||||
TickerInterval time.Duration
|
||||
DefaultData model.DefaultData
|
||||
Logger hlog.Logger
|
||||
ErrChan chan<- error
|
||||
PrivilegeIDs []string
|
||||
}
|
||||
|
||||
type CheckWorker struct {
|
||||
@ -36,7 +35,7 @@ func (w *CheckWorker) Start(ctx context.Context) {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
fmt.Println("CHECK")
|
||||
w.performScheduledTasks(ctx)
|
||||
w.deleteExpired(ctx)
|
||||
case <-ctx.Done():
|
||||
fmt.Println("Check worker terminated")
|
||||
return
|
||||
@ -44,14 +43,9 @@ 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) {
|
||||
expiredData, err := w.privilegeDAL.AccountRepo.GetExpired(ctx, w.config.DefaultData.UnlimID)
|
||||
for _, id := range w.config.PrivilegeIDs {
|
||||
expiredData, err := w.privilegeDAL.AccountRepo.GetExpired(ctx, id)
|
||||
if err != nil {
|
||||
w.config.Logger.Module("Error getting expired quizUnlimTime records")
|
||||
w.config.ErrChan <- err
|
||||
@ -65,3 +59,4 @@ func (w *CheckWorker) deleteExpired(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user