数据上报
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

40 lines
824 B

package monitors
import (
"github.com/robfig/cron/v3"
"log"
)
type FileMonitor struct {
Directory string
FilenameExtension string
MonitorHelper
}
func (the *FileMonitor) Initial() {
the.Cron = cron.New()
log.Printf("文件目录监听 cronStr=%s", the.CronStr)
}
func (the *FileMonitor) Subscribe(task func()) {
entryID, err := the.Cron.AddFunc(the.CronStr, task)
if err != nil {
log.Printf("cron 定时任务[%v]添加异常:%s", entryID, err.Error())
}
the.Cron.Start()
}
func FileMonitorInitial(Directory string, FilenameExtension string, cron string) *FileMonitor {
fileMonitorHelper := FileMonitor{
Directory: Directory,
FilenameExtension: FilenameExtension,
MonitorHelper: MonitorHelper{
CronStr: cron,
},
}
fileMonitorHelper.Initial()
return &fileMonitorHelper
}