chroe: adjust logs table name
This commit is contained in:
@@ -75,6 +75,7 @@ func (cs *CronService) UpdateLogsCronRun(cron string) {
|
|||||||
|
|
||||||
// StartLogsCronRun 启动的时候开启定时任务
|
// StartLogsCronRun 启动的时候开启定时任务
|
||||||
func StartLogsCronRun() {
|
func StartLogsCronRun() {
|
||||||
|
logrus.Infof("开始注册定时清除日志任务...")
|
||||||
cs := CronService{}
|
cs := CronService{}
|
||||||
cs.StartLogsCronRun()
|
cs.StartLogsCronRun()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package cron_service
|
package cron_service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
@@ -26,23 +28,30 @@ func init() {
|
|||||||
TaskList = make(map[cron.EntryID]*ScheduledTask)
|
TaskList = make(map[cron.EntryID]*ScheduledTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加定时任务
|
func getFunctionName(f interface{}) string {
|
||||||
|
ptr := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
||||||
|
name := ptr[strings.LastIndex(ptr, ".")+1:]
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTask 添加定时任务
|
||||||
func AddTask(task ScheduledTask) cron.EntryID {
|
func AddTask(task ScheduledTask) cron.EntryID {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|
||||||
|
jobName := getFunctionName(task.Job)
|
||||||
taskId, err := CronInstance.AddFunc(task.Schedule, task.Job)
|
taskId, err := CronInstance.AddFunc(task.Schedule, task.Job)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 处理错误
|
// 处理错误
|
||||||
logrus.Error(fmt.Sprintf("添加定时任务失败,原因:%s", err))
|
logrus.Errorf("注册定时任务失败, job: %s, 原因:%s", jobName, err)
|
||||||
} else {
|
} else {
|
||||||
TaskList[taskId] = &task
|
TaskList[taskId] = &task
|
||||||
logrus.Info(fmt.Sprintf("添加定时任务成功,entryID: %d, cron: %s", taskId, task.Schedule))
|
logrus.Infof("注册定时任务成功, job: %s, entryID: %d, cron: %s", jobName, taskId, task.Schedule)
|
||||||
}
|
}
|
||||||
return taskId
|
return taskId
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除定时任务
|
// RemoveTask 删除定时任务
|
||||||
func RemoveTask(taskID cron.EntryID) {
|
func RemoveTask(taskID cron.EntryID) {
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="发送时间" prop="created_on" width="160px" />
|
<el-table-column label="发送时间" prop="created_on" width="160px" />
|
||||||
<el-table-column label="状态" prop="status" width="120px" fixed="right">
|
<el-table-column label="详情/状态" prop="status" width="120px" fixed="right">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button link size="small" style="margin-right: 10px;" type="primary"
|
<el-button link size="small" style="margin-right: 10px;" type="primary"
|
||||||
@click="drawer = true; logText = scope.row.log">日志</el-button>
|
@click="drawer = true; logText = scope.row.log">日志</el-button>
|
||||||
|
|||||||
Reference in New Issue
Block a user