| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- package jobs
- import (
- "IotAdmin/core/logger"
- iotLog "IotAdmin/iot/log"
- "strconv"
- "strings"
- "time"
- )
- // CleanLog
- // 新添加的job 必须按照以下格式定义,并实现Exec函数
- type CleanLog struct {
- }
- func (t *CleanLog) Exec(arg interface{}) error {
- logger.Info(time.Now().Format(timeFormat) + " [INFO] JobCore CleanLog exec START")
- switch arg.(type) {
- case string:
- if arg.(string) != "" {
- str := arg.(string)
- arr := strings.Split(str, ",")
- p1, err := strconv.Atoi(arr[0])
- if err != nil {
- logger.Error(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error:" + err.Error())
- return err
- }
- if len(arr) > 1 {
- p2, err := strconv.Atoi(arr[1])
- if err != nil {
- logger.Error(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error:" + err.Error())
- return err
- }
- err = iotLog.Clean(p1, p2)
- if err != nil {
- logger.Error(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error:" + err.Error())
- return err
- }
- } else {
- err = iotLog.Clean(p1, p1)
- if err != nil {
- logger.Error(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error:" + err.Error())
- return err
- }
- }
- } else {
- logger.Errorf(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error: arg is empty")
- }
- break
- case int:
- if arg.(int) != 0 {
- p := arg.(int)
- err := iotLog.Clean(p, p)
- if err != nil {
- logger.Error(time.Now().Format(timeFormat) + " [ERROR] JobCore CleanLog exec error:" + err.Error())
- return err
- }
- }
- break
- default:
- }
- return nil
- }
|