1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- package provider
- import (
- "context"
- "gd_management/apis"
- "gd_management/common.in/cache"
- "gd_management/common.in/config"
- "gd_management/common.in/utils"
- "gd_management/errors"
- "github.com/astaxie/beego/orm"
- "go.uber.org/zap"
- )
- func GetHystrix(
- ctx context.Context,
- req *apis.GetProviderApiHystrixReq,
- reply *apis.GetProviderApiHystrixReply,
- ) (err error) {
- o := orm.NewOrm()
- err = o.Raw("select id, max_concurrent_requests, request_volume_threshold, sleep_window, error_percent_threshold, period, is_on from t_gd_provider_api_hystrix where provider_api_code = ?", req.ProviderApiCode).
- QueryRow(&reply.ID, &reply.MaxConcurrentRequests, &reply.RequestVolumeThreshold, &reply.SleepWindow, &reply.ErrorPercentThreshold, &reply.Period, &reply.IsOn)
- if err != nil && err != orm.ErrNoRows {
- l.Error("mysql",
- zap.String("sql", "select * from t_gd_provider_api_hystrix where provider_api_code"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- return nil
- }
- func UpdateHystrix(
- ctx context.Context,
- req *apis.UpdateProviderApiHystrixReq,
- reply *apis.UpdateProviderApiHystrixReply,
- ) (err error) {
- if req.ID == 0 {
- // 创建
- if _, err = orm.NewOrm().Insert(req); err != nil {
- l.Error("mysql",
- zap.String("sql", "insert t_gd_provider_api_hystrix"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- } else {
- // 更新
- if _, err = orm.NewOrm().Raw("UPDATE t_gd_provider_api_hystrix SET max_concurrent_requests=?,request_volume_threshold=?,sleep_window=?,error_percent_threshold=?,period=?,is_on=? WHERE id=?", req.MaxConcurrentRequests, req.RequestVolumeThreshold, req.SleepWindow, req.ErrorPercentThreshold, req.Period, req.IsOn, req.ID).Exec(); err != nil {
- l.Error("mysql",
- zap.String("sql", "update t_gd_provider_api_hystrix"),
- zap.String("fields", utils.MarshalJsonString(req)),
- zap.String("error", err.Error()))
- return errors.DataBaseError
- }
- }
- for i := 0; i < 3; i++ {
- if _, err = cache.Redis.Publish(config.Conf.ThirdPart.HystrixPublishChannel, "hystrix-update"); err == nil {
- break
- }
- }
- return nil
- }
|