added part of the system tasks logic

This commit is contained in:
marvzhang
2020-07-30 23:06:11 +08:00
parent ec81344e20
commit d525099568
13 changed files with 258 additions and 56 deletions

View File

@@ -5,8 +5,11 @@ import (
"crawlab/entity"
"encoding/json"
"github.com/apex/log"
"github.com/spf13/viper"
"io/ioutil"
"path"
"runtime/debug"
"strings"
)
func GetLangList() []entity.Lang {
@@ -123,3 +126,24 @@ func GetPackageJsonDeps(filepath string) (deps []string, err error) {
return deps, nil
}
// 获取系统脚本列表
func GetSystemScripts() (res []string) {
scriptsPath := viper.GetString("server.scripts")
for _, fInfo := range ListDir(scriptsPath) {
if !fInfo.IsDir() && strings.HasSuffix(fInfo.Name(), ".sh") {
res = append(res, fInfo.Name())
}
}
return res
}
func GetSystemScriptPath(scriptName string) string {
scriptsPath := viper.GetString("server.scripts")
for _, name := range GetSystemScripts() {
if name == scriptName {
return path.Join(scriptsPath, name)
}
}
return ""
}