k3cloud_fetch_data.go
928 字节
package redis
import (
"fmt"
"github.com/go-redis/redis"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-manufacture/pkg/constant"
"time"
)
// 获取每日设备运行数据
func GetLastK3CloudFetchTime() (time.Time, error) {
client := GetRedis()
key := K3CloudFetchTimeKey()
result := client.Get(key)
t, err := result.Int()
if err == redis.Nil {
if _, err := client.Set(key, time.Now().Unix(), 0).Result(); err != nil {
return time.Time{}, err
}
}
fetchTime := time.Unix(int64(t), 0)
if fetchTime.IsZero() {
return time.Time{}, fmt.Errorf("zerotime retry")
}
if _, err := client.Set(key, time.Now().Unix(), 0).Result(); err != nil {
return time.Time{}, err
}
return fetchTime, nil
}
func K3CloudFetchTimeKey() string {
str := fmt.Sprintf("%v:k3clound-data:last-fetch:%v-%v", constant.CACHE_PREFIX, constant.MANUFACTURE_DEFAULT_COMPANYID, constant.MANUFACTURE_DEFAULT_ORGID)
return str
}