parent
054097421d
commit
59073c434c
|
@ -41,12 +41,12 @@ RUN set -x \
|
||||||
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
&& git config --global user.email "qinglong@@users.noreply.github.com" \
|
||||||
&& git config --global user.name "qinglong" \
|
&& git config --global user.name "qinglong" \
|
||||||
&& git config --global http.postBuffer 524288000 \
|
&& git config --global http.postBuffer 524288000 \
|
||||||
&& npm install -g yarn \
|
&& npm install -g pnpm \
|
||||||
&& rm -rf /root/.cache \
|
&& rm -rf /root/.cache \
|
||||||
&& rm -rf /root/.npm \
|
&& rm -rf /root/.npm \
|
||||||
&& mkdir -p ${QL_DIR}/data \
|
&& mkdir -p ${QL_DIR}/data \
|
||||||
&& cd ${QL_DIR} \
|
&& cd ${QL_DIR} \
|
||||||
&& wget https://github.com/huoxue1/qinglong/releases/download/v1.0.0/static.tar.gz \
|
&& wget https://github.com/huoxue1/qinglong/releases/download/v1.0.1/static.tar.gz \
|
||||||
&& tar -xzvf static.tar.gz
|
&& tar -xzvf static.tar.gz
|
||||||
|
|
||||||
COPY ./dist/docker_linux_$TARGETARCH*/qinglong-go ${QL_DIR}/ql
|
COPY ./dist/docker_linux_$TARGETARCH*/qinglong-go ${QL_DIR}/ql
|
||||||
|
|
|
@ -12,6 +12,8 @@ func Api(group *gin.RouterGroup) {
|
||||||
group.POST("", post())
|
group.POST("", post())
|
||||||
group.GET("", get())
|
group.GET("", get())
|
||||||
group.GET("/:id", getDep())
|
group.GET("/:id", getDep())
|
||||||
|
|
||||||
|
group.DELETE("", del())
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -34,6 +36,20 @@ func get() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func del() gin.HandlerFunc {
|
||||||
|
|
||||||
|
return func(ctx *gin.Context) {
|
||||||
|
var ids []int
|
||||||
|
err := ctx.ShouldBindJSON(&ids)
|
||||||
|
if err != nil {
|
||||||
|
ctx.JSON(503, res.Err(502, err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dependencies.DelDep(ids)
|
||||||
|
ctx.JSON(200, res.Ok(true))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func post() gin.HandlerFunc {
|
func post() gin.HandlerFunc {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
var deps []*models.Dependences
|
var deps []*models.Dependences
|
||||||
|
|
|
@ -28,12 +28,13 @@ type Crontabs struct {
|
||||||
func QueryCron(page int, size int, searchValue string, orderField string, orderType string) ([]*Crontabs, error) {
|
func QueryCron(page int, size int, searchValue string, orderField string, orderType string) ([]*Crontabs, error) {
|
||||||
crontabs := make([]*Crontabs, 0)
|
crontabs := make([]*Crontabs, 0)
|
||||||
session := engine.Table(new(Crontabs)).Limit(size, (page-1)*size).Where(builder.Like{"name", "%" + searchValue + "%"}.Or(builder.Like{"command", "%" + searchValue + "%"}))
|
session := engine.Table(new(Crontabs)).Limit(size, (page-1)*size).Where(builder.Like{"name", "%" + searchValue + "%"}.Or(builder.Like{"command", "%" + searchValue + "%"}))
|
||||||
if orderType == "DESC" {
|
//if orderType == "DESC" {
|
||||||
session.Desc(orderField)
|
// session.Desc(orderField)
|
||||||
} else if orderType == "ASC" {
|
//} else if orderType == "ASC" {
|
||||||
session.Asc(orderField)
|
// session.Asc(orderField)
|
||||||
}
|
//}
|
||||||
err := session.Find(&crontabs)
|
|
||||||
|
err := session.Asc("status").Find(&crontabs)
|
||||||
return crontabs, err
|
return crontabs, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ func runYarn() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ch := make(chan int, 1)
|
ch := make(chan int, 1)
|
||||||
utils.RunTask(context.WithValue(context.Background(), "cancel", ch), "yarn install", map[string]string{}, func(ctx context.Context) {
|
utils.RunTask(context.WithValue(context.Background(), "cancel", ch), "pnpm install", map[string]string{}, func(ctx context.Context) {
|
||||||
log.Infoln("开始执行yarn初始化!")
|
log.Infoln("开始执行pnpm初始化!")
|
||||||
}, func(ctx context.Context) {
|
}, func(ctx context.Context) {
|
||||||
log.Infoln("yarn初始化执行完成!")
|
log.Infoln("pnpm初始化执行完成!")
|
||||||
}, os.Stdout)
|
}, os.Stdout)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/huoxue1/qinglong-go/service/config"
|
"github.com/huoxue1/qinglong-go/service/config"
|
||||||
"github.com/huoxue1/qinglong-go/utils"
|
"github.com/huoxue1/qinglong-go/utils"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -22,12 +23,45 @@ func AddDep(dep *models.Dependences) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DelDep(ids []int) {
|
||||||
|
for _, id := range ids {
|
||||||
|
dep, err := models.GetDependences(id)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if dep.Type == models.NODE {
|
||||||
|
unInstallDep("pnpm remove "+dep.Name, dep)
|
||||||
|
} else if dep.Type == models.PYTHON {
|
||||||
|
pip := config.GetKey("PipCmd", "pip")
|
||||||
|
unInstallDep(fmt.Sprintf("%s uninstall %s", pip, dep.Name), dep)
|
||||||
|
} else {
|
||||||
|
unInstallDep("apk uninstall "+dep.Name, dep)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unInstallDep(command string, dep *models.Dependences) {
|
||||||
|
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
||||||
|
now := time.Now()
|
||||||
|
go utils.RunTask(ctx, command, map[string]string{}, func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
_, _ = writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
|
}, func(ctx context.Context) {
|
||||||
|
writer := ctx.Value("log").(io.Writer)
|
||||||
|
_, _ = writer.Write([]byte(fmt.Sprintf("\n##执行结束.. %s,耗时%.1f秒\n\n", time.Now().Format("2006-01-02 15:04:05"), time.Now().Sub(now).Seconds())))
|
||||||
|
_ = models.DeleteDependences(dep.Id)
|
||||||
|
}, os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
func addNodeDep(dep *models.Dependences) {
|
func addNodeDep(dep *models.Dependences) {
|
||||||
log := ""
|
log := ""
|
||||||
buffer := bytes.NewBufferString(log)
|
buffer := bytes.NewBufferString(log)
|
||||||
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
utils.RunTask(ctx, fmt.Sprintf("yarn add %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
go utils.RunTask(ctx, fmt.Sprintf("pnpm add %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
||||||
|
dep.Status = 0
|
||||||
|
_, _ = models.AddDependences(dep)
|
||||||
writer := ctx.Value("log").(io.Writer)
|
writer := ctx.Value("log").(io.Writer)
|
||||||
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
}, func(ctx context.Context) {
|
}, func(ctx context.Context) {
|
||||||
|
@ -39,7 +73,7 @@ func addNodeDep(dep *models.Dependences) {
|
||||||
logs = append(logs, i2+"\n\n")
|
logs = append(logs, i2+"\n\n")
|
||||||
}
|
}
|
||||||
dep.Log = logs
|
dep.Log = logs
|
||||||
models.AddDependences(dep)
|
_ = models.UpdateDependences(dep)
|
||||||
}, buffer)
|
}, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +83,9 @@ func addPythonDep(dep *models.Dependences) {
|
||||||
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
pip := config.GetKey("PipCmd", "pip")
|
pip := config.GetKey("PipCmd", "pip")
|
||||||
utils.RunTask(ctx, fmt.Sprintf(pip+" install %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
go utils.RunTask(ctx, fmt.Sprintf(pip+" install %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
||||||
|
dep.Status = 0
|
||||||
|
_, _ = models.AddDependences(dep)
|
||||||
writer := ctx.Value("log").(io.Writer)
|
writer := ctx.Value("log").(io.Writer)
|
||||||
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
}, func(ctx context.Context) {
|
}, func(ctx context.Context) {
|
||||||
|
@ -61,7 +97,7 @@ func addPythonDep(dep *models.Dependences) {
|
||||||
logs = append(logs, i2+"\n\n")
|
logs = append(logs, i2+"\n\n")
|
||||||
}
|
}
|
||||||
dep.Log = logs
|
dep.Log = logs
|
||||||
models.AddDependences(dep)
|
models.UpdateDependences(dep)
|
||||||
}, buffer)
|
}, buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +106,9 @@ func addLinuxDep(dep *models.Dependences) {
|
||||||
buffer := bytes.NewBufferString(log)
|
buffer := bytes.NewBufferString(log)
|
||||||
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
ctx := context.WithValue(context.Background(), "cancel", make(chan int, 1))
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
utils.RunTask(ctx, fmt.Sprintf("apk add %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
go utils.RunTask(ctx, fmt.Sprintf("apk add %s", dep.Name), map[string]string{}, func(ctx context.Context) {
|
||||||
|
dep.Status = 0
|
||||||
|
_, _ = models.AddDependences(dep)
|
||||||
writer := ctx.Value("log").(io.Writer)
|
writer := ctx.Value("log").(io.Writer)
|
||||||
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
writer.Write([]byte(fmt.Sprintf("##开始执行.. %s\n\n", now.Format("2006-01-02 15:04:05"))))
|
||||||
}, func(ctx context.Context) {
|
}, func(ctx context.Context) {
|
||||||
|
@ -82,6 +120,6 @@ func addLinuxDep(dep *models.Dependences) {
|
||||||
logs = append(logs, i2+"\n\n")
|
logs = append(logs, i2+"\n\n")
|
||||||
}
|
}
|
||||||
dep.Log = logs
|
dep.Log = logs
|
||||||
models.AddDependences(dep)
|
models.UpdateDependences(dep)
|
||||||
}, buffer)
|
}, buffer)
|
||||||
}
|
}
|
||||||
|
|
|
@ -277,17 +277,19 @@ func getSubCron(filePath string) (name string, cron string, err error) {
|
||||||
}
|
}
|
||||||
cronReg := regexp.MustCompile(`([0-9\-*/,]{1,} ){4,5}([0-9\-*/,]){1,}`)
|
cronReg := regexp.MustCompile(`([0-9\-*/,]{1,} ){4,5}([0-9\-*/,]){1,}`)
|
||||||
nameEnv := regexp.MustCompile(`new\sEnv\(['|"](.*?)['|"]\)`)
|
nameEnv := regexp.MustCompile(`new\sEnv\(['|"](.*?)['|"]\)`)
|
||||||
if cronReg.Match(data) {
|
|
||||||
cron = string(cronReg.FindAll(data, 1)[0])
|
|
||||||
cron = strings.TrimPrefix(cron, "//")
|
|
||||||
if nameEnv.Match(data) {
|
if nameEnv.Match(data) {
|
||||||
name = string(nameEnv.FindAllSubmatch(data, 1)[0][1])
|
if cronReg.Match(data) {
|
||||||
|
cron = strings.TrimPrefix(strings.TrimPrefix(string(cronReg.FindAll(data, 1)[0]), "//"), " ")
|
||||||
} else {
|
} else {
|
||||||
name = path.Base(filePath)
|
key := config.GetKey("DefaultCronRule", "0 9 * * *")
|
||||||
|
if key == "" {
|
||||||
|
key = "0 9 * * *"
|
||||||
}
|
}
|
||||||
|
cron = key
|
||||||
|
}
|
||||||
|
name = string(nameEnv.FindAllSubmatch(data, 1)[0][1])
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
return "", "", errors.New("not found cron")
|
return "", "", errors.New("not found cron")
|
||||||
}
|
}
|
||||||
cron = strings.TrimPrefix(cron, " ")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/huoxue1/qinglong-go/utils/log"
|
"github.com/huoxue1/qinglong-go/utils/log"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
manager sync.Map
|
manager sync.Map
|
||||||
defaultCron *cron.Cron
|
|
||||||
SixCron *cron.Cron
|
SixCron *cron.Cron
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -20,10 +18,8 @@ type mapValue struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
defaultCron = cron.New(cron.WithChain(cron.Recover(&log.CronLog{})))
|
|
||||||
SixCron = cron.New(cron.WithChain(cron.Recover(&log.CronLog{})), cron.WithParser(
|
SixCron = cron.New(cron.WithChain(cron.Recover(&log.CronLog{})), cron.WithParser(
|
||||||
cron.NewParser(cron.Second|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor)))
|
cron.NewParser(cron.SecondOptional|cron.Minute|cron.Hour|cron.Dom|cron.Month|cron.Dow|cron.Descriptor)))
|
||||||
defaultCron.Start()
|
|
||||||
SixCron.Start()
|
SixCron.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,16 +27,12 @@ func AddCron(id string, value string, task func()) error {
|
||||||
if value == "7 7 7 7 7" {
|
if value == "7 7 7 7 7" {
|
||||||
value = "7 7 7 7 6"
|
value = "7 7 7 7 6"
|
||||||
}
|
}
|
||||||
crons := strings.Split(value, " ")
|
|
||||||
cronCmd := defaultCron
|
en, err := SixCron.AddFunc(value, task)
|
||||||
if len(crons) == 6 {
|
|
||||||
cronCmd = SixCron
|
|
||||||
}
|
|
||||||
en, err := cronCmd.AddFunc(value, task)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
manager.Store(id, &mapValue{en, cronCmd})
|
manager.Store(id, &mapValue{en, SixCron})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue