123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package access_log
- import (
- "gd_statistics/rpc_apis/gd_management"
- "sync"
- "time"
- "gd_statistics/common.in/cache"
- )
- var globalApiExportMux sync.RWMutex
- var globalProviderExportMux sync.RWMutex
- var globalTimeoutInfo map[string]int
- var globalShowInfo map[int64]bool
- var globalCountCode []gd_management.UserMerchantCountCode
- var globalCountCodeMap map[string]gd_management.UserMerchantCountCode
- var globalProviderCountInfo map[int64]ProviderCountInfo
- func apiExportInfoInit() error {
- var err error
- globalShowInfo, err = getNotShow()
- if err != nil {
- globalShowInfo = nil
- return err
- }
- globalTimeoutInfo, err = getTimeoutInfo()
- if err != nil {
- globalTimeoutInfo = nil
- return err
- }
- globalCountCodeMap, globalCountCode, err = getCountCodeInfoNew()
- if err != nil {
- globalCountCodeMap = nil
- globalCountCode = []gd_management.UserMerchantCountCode{}
- return err
- }
- return nil
- }
- func providerExportInfoInit() error {
- var err error
- globalProviderCountInfo, err = getProviderCountInfo()
- if err != nil {
- globalProviderCountInfo = nil
- return err
- }
- return nil
- }
- func LogExportInfoInit() {
- go func() {
- for {
- err := apiExportInfoReset("")
- if err != nil {
- time.Sleep(5 * time.Second)
- continue
- }
- break
- }
- for {
- err := providerExportInfoReset("")
- if err != nil {
- time.Sleep(5 * time.Second)
- continue
- }
- break
- }
- }()
- }
- func apiExportInfoReset(empty string) error {
- globalApiExportMux.Lock()
- defer globalApiExportMux.Unlock()
- globalShowInfo = nil
- globalTimeoutInfo = nil
- globalCountCodeMap = nil
- globalCountCode = []gd_management.UserMerchantCountCode{}
- return apiExportInfoInit()
- }
- func providerExportInfoReset(empty string) error {
- globalProviderExportMux.Lock()
- defer globalProviderExportMux.Unlock()
- globalProviderCountInfo = nil
- return providerExportInfoInit()
- }
- func UpdateLocalCache() {
- t := time.NewTicker(10 * time.Minute)
- for {
- select {
- case <-t.C:
- apiExportInfoReset("")
- providerExportInfoReset("")
- }
- }
- }
- var ApiExportInfoNotifyChannel = "api_export_info_notify"
- var ProviderExportInfoNotifyChannel = "provider_export_info_notify"
- func Watch() {
- go func() {
- cache.Redis.RegisterFunc(ApiExportInfoNotifyChannel, apiExportInfoReset)
- cache.Redis.RegisterFunc(ProviderExportInfoNotifyChannel, providerExportInfoReset)
- cache.Redis.SubscribeAndHandle(ApiExportInfoNotifyChannel, ProviderExportInfoNotifyChannel)
- }()
- }
|