refactor: change plugin workdir

This commit is contained in:
710leo 2020-03-26 14:59:08 +08:00
parent 360aa94f66
commit 6d42824c2d
2 changed files with 9 additions and 3 deletions

View File

@ -32,6 +32,7 @@ func ListPlugins(dir string) map[string]*Plugin {
filename := f.Name()
arr := strings.Split(filename, "_")
if len(arr) < 2 {
logger.Warningf("plugin:%s name illegal, should be: $cycle_$xx", filename)
continue
}
@ -39,10 +40,16 @@ func ListPlugins(dir string) map[string]*Plugin {
var cycle int
cycle, err = strconv.Atoi(arr[0])
if err != nil {
logger.Warningf("plugin:%s name illegal, should be: $cycle_$xx %v", filename, err)
continue
}
fpath, err := filepath.Abs(filepath.Join(dir, filename))
if err != nil {
logger.Warningf("plugin:%s absolute path get err:%v", filename, err)
continue
}
fpath := filepath.Join(dir, filename)
plugin := &Plugin{FilePath: fpath, MTime: f.ModTime().Unix(), Cycle: cycle}
ret[fpath] = plugin
}

View File

@ -50,8 +50,7 @@ func PluginRun(plugin *Plugin) {
timeout := plugin.Cycle*1000 - 500 //比运行周期少500毫秒
fpath := filepath.Join(file.SelfDir(), plugin.FilePath)
fpath := plugin.FilePath
if !file.IsExist(fpath) {
logger.Error("no such plugin:", fpath)
return