12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package data
- import (
- "context"
- "encoding/json"
- "eta/eta_task/utils"
- "fmt"
- "io/ioutil"
- "time"
- )
- // RefreshPCSGBloomberg 中石油新加坡-定时刷新指标
- func RefreshPCSGBloomberg(cont context.Context) (err error) {
- defer func() {
- if err != nil {
- tips := "RefreshPCSGBloombergDaily-中石油新加坡-刷新彭博指标失败, ErrMsg:\n" + err.Error()
- utils.FileLog.Info(tips)
- }
- }()
- runTime := time.Now().Local().Format("15:04")
- tasks, e := LoadPCSGBloombergTask()
- if e != nil {
- err = fmt.Errorf("读取配置失败, %v", e)
- return
- }
- if len(tasks) == 0 {
- utils.FileLog.Info("任务未配置")
- return
- }
- // 根据分钟匹配任务
- uri := "bloomberg/pcsg/refresh_task"
- for _, v := range tasks {
- if runTime != v.TaskTime {
- continue
- }
- utils.FileLog.Info(fmt.Sprintf("执行%s", v.TaskKey))
- param := make(map[string]interface{})
- param["TaskKey"] = v.TaskKey
- res, e := postRefreshEdbData(param, uri)
- if e != nil {
- utils.FileLog.Info(fmt.Sprintf("postRefreshEdbData, %v", e))
- continue
- }
- if res != nil && res.Ret != 200 {
- utils.FileLog.Info("postRefreshEdbData, fail")
- continue
- }
- utils.FileLog.Info(fmt.Sprintf("执行结束%s", v.TaskKey))
- }
- return
- }
- type PCSGBloombergTask struct {
- TaskKey string `json:"TaskKey"`
- TaskTime string `json:"TaskTime"`
- }
- // LoadPCSGBloombergTask 加载配置
- func LoadPCSGBloombergTask() (tasks []*PCSGBloombergTask, err error) {
- filePath := "./static/pcsg_task.json"
- b, e := ioutil.ReadFile(filePath)
- if e != nil {
- err = fmt.Errorf("读取配置失败, err: %v", e)
- return
- }
- if e = json.Unmarshal(b, &tasks); e != nil {
- err = fmt.Errorf("解析配置失败, err: %v", e)
- return
- }
- return
- }
|