去掉常驻任务逻辑
写了再去掉……
This commit is contained in:
@@ -16,9 +16,6 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"os/exec"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
type TaskController struct {
|
||||
@@ -46,9 +43,6 @@ func (this *TaskController) List() {
|
||||
row["cron_spec"] = v.CronSpec
|
||||
row["status"] = v.Status
|
||||
row["description"] = v.Description
|
||||
|
||||
row["task_type"] = v.TaskType
|
||||
|
||||
e := jobs.GetEntryById(v.Id)
|
||||
if e != nil {
|
||||
row["next_time"] = beego.Date(e.Next, "Y-m-d H:i:s")
|
||||
@@ -90,8 +84,6 @@ func (this *TaskController) Add() {
|
||||
task.UserId = this.userId
|
||||
task.GroupId, _ = this.GetInt("group_id")
|
||||
task.TaskName = strings.TrimSpace(this.GetString("task_name"))
|
||||
task.TaskTag = strings.TrimSpace(this.GetString("task_tag"))
|
||||
task.TaskType, _ = this.GetInt("task_type")
|
||||
task.Description = strings.TrimSpace(this.GetString("description"))
|
||||
task.Concurrent, _ = this.GetInt("concurrent")
|
||||
task.CronSpec = strings.TrimSpace(this.GetString("cron_spec"))
|
||||
@@ -99,7 +91,6 @@ func (this *TaskController) Add() {
|
||||
task.Notify, _ = this.GetInt("notify")
|
||||
task.Timeout, _ = this.GetInt("timeout")
|
||||
|
||||
|
||||
notifyEmail := strings.TrimSpace(this.GetString("notify_email"))
|
||||
if notifyEmail != "" {
|
||||
emailList := make([]string, 0)
|
||||
@@ -146,8 +137,6 @@ func (this *TaskController) Edit() {
|
||||
|
||||
if this.isPost() {
|
||||
task.TaskName = strings.TrimSpace(this.GetString("task_name"))
|
||||
task.TaskTag = strings.TrimSpace(this.GetString("task_tag"))
|
||||
task.TaskType, _ = this.GetInt("task_type")
|
||||
task.Description = strings.TrimSpace(this.GetString("description"))
|
||||
task.GroupId, _ = this.GetInt("group_id")
|
||||
task.Concurrent, _ = this.GetInt("concurrent")
|
||||
@@ -304,9 +293,6 @@ func (this *TaskController) Batch() {
|
||||
if task, err := models.TaskGetById(id); err == nil {
|
||||
task.Status = 0
|
||||
task.Update()
|
||||
if task.TaskType==1 {
|
||||
stopProcess(task.TaskTag)//杀死进程
|
||||
}
|
||||
}
|
||||
|
||||
case "delete":
|
||||
@@ -358,10 +344,6 @@ func (this *TaskController) Pause() {
|
||||
task.Status = 0
|
||||
task.Update()
|
||||
|
||||
//如果是常驻进程,kill
|
||||
if task.TaskType==1 {
|
||||
stopProcess(task.TaskTag)
|
||||
}
|
||||
refer := this.Ctx.Request.Referer()
|
||||
if refer == "" {
|
||||
refer = beego.URLFor("TaskController.List")
|
||||
@@ -385,11 +367,3 @@ func (this *TaskController) Run() {
|
||||
job.Run()
|
||||
this.redirect(beego.URLFor("TaskController.ViewLog", "id", job.GetLogId()))
|
||||
}
|
||||
//杀死进程
|
||||
func stopProcess(taskTag string) {
|
||||
ppPath,_ := os.Getwd() //项目根目录
|
||||
shellFile := ppPath+"/kill_process.sh "
|
||||
cmd:= exec.Command("sh","-c", shellFile + taskTag)
|
||||
out,err:=cmd.Output()
|
||||
log.Printf("==========================out:%s err:%s",out,err)
|
||||
}
|
||||
|
||||
21
jobs/init.go
21
jobs/init.go
@@ -49,24 +49,3 @@ func runCmdWithTimeout(cmd *exec.Cmd, timeout time.Duration) (error, bool) {
|
||||
}
|
||||
}
|
||||
|
||||
//func stopCmd(cmd *exec.Cmd) (error,bool) {
|
||||
// done := make(chan error)
|
||||
// go func() {
|
||||
// done <- cmd.Wait()
|
||||
// }()
|
||||
//
|
||||
// var err error
|
||||
// select {
|
||||
// case <-time.After(timeout):
|
||||
// beego.Warn(fmt.Sprintf("任务执行时间超过%d秒,进程将被强制杀掉: %d", int(timeout/time.Second), cmd.Process.Pid))
|
||||
// go func() {
|
||||
// <-done // 读出上面的goroutine数据,避免阻塞导致无法退出
|
||||
// }()
|
||||
// if err = cmd.Process.Kill(); err != nil {
|
||||
// beego.Error(fmt.Sprintf("进程无法杀掉: %d, 错误信息: %s", cmd.Process.Pid, err))
|
||||
// }
|
||||
// return err, true
|
||||
// case err = <-done:
|
||||
// return err, false
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -133,13 +133,7 @@ func (j *Job) Run() {
|
||||
if j.task.Timeout > 0 {
|
||||
timeout = time.Second * time.Duration(j.task.Timeout)
|
||||
}
|
||||
|
||||
cmdOut, cmdErr, err, isTimeout := j.runFunc(timeout)
|
||||
if err.Error() == "signal: killed" {
|
||||
cmdOut += err.Error()
|
||||
err = nil
|
||||
}
|
||||
|
||||
ut := time.Now().Sub(t) / time.Millisecond
|
||||
|
||||
// 插入日志
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/bash
|
||||
# @Author: haodaquan
|
||||
# @Date: 2017-06-29 17:44:45
|
||||
# @Last Modified by: haodaquan
|
||||
# @Last Modified time: 2017-06-29 17:44:45
|
||||
|
||||
process_tag=$1
|
||||
arrproc=$(ps -ef | grep "${process_tag}" | grep -v grep | awk '{print $2}')
|
||||
for p in $arrproc; do
|
||||
if [ "${p}"=~^[0-9]+$ ]; then
|
||||
kill -9 "${p}"
|
||||
echo `date "+%Y/%m/%d %H:%M:%S> "` ${p} " 进程已杀死!"
|
||||
fi
|
||||
done
|
||||
@@ -25,7 +25,6 @@ type Task struct {
|
||||
GroupId int
|
||||
TaskName string
|
||||
TaskType int
|
||||
TaskTag string
|
||||
Description string
|
||||
CronSpec string
|
||||
Concurrent int
|
||||
@@ -55,9 +54,6 @@ func TaskAdd(task *Task) (int64, error) {
|
||||
return 0, fmt.Errorf("TaskName字段不能为空")
|
||||
}
|
||||
|
||||
if task.TaskTag == "" {
|
||||
return 0, fmt.Errorf("TaskTag字段不能为空")
|
||||
}
|
||||
if task.CronSpec == "" {
|
||||
return 0, fmt.Errorf("CronSpec字段不能为空")
|
||||
}
|
||||
|
||||
11
ppgo_job.sql
11
ppgo_job.sql
File diff suppressed because one or more lines are too long
@@ -30,16 +30,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="task_tag">进程标志</label>
|
||||
<div class="col-sm-3" >
|
||||
<input type="text" class="form-control input-sm" placeholder="用于查找进程,一般为方法名称" name="task_tag" value="" required />
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-top:5px;">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="description">任务说明</label>
|
||||
<div class="col-sm-5" >
|
||||
@@ -80,21 +70,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="task_type">任务类型</label>
|
||||
<div class="col-sm-3" >
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="task_type" value="0" checked> 定时任务
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="task_type" value="1"> 常驻任务
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-top:5px;">
|
||||
<i></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="cron_spec">时间表达式</label>
|
||||
<div class="col-sm-3" >
|
||||
|
||||
@@ -30,15 +30,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="task_tag">进程标志</label>
|
||||
<div class="col-sm-3" >
|
||||
<input type="text" class="form-control input-sm" placeholder="用于查找进程,一般为方法名称" name="task_tag" value="{{.task.TaskTag}}" required />
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-top:5px;">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="task_name">任务说明</label>
|
||||
@@ -80,21 +71,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="task_type">任务类型</label>
|
||||
<div class="col-sm-3" >
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="task_type" value="0" {{if eq .task.TaskType 0}}checked{{end}}> 定时任务
|
||||
</label>
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="task_type" value="1" {{if eq .task.TaskType 1}}checked{{end}}> 常驻任务
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-sm-6" style="padding-top:5px;">
|
||||
<i></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group" style="margin-top: 15px">
|
||||
<label class="col-sm-3 control-label" for="cron_spec">时间表达式</label>
|
||||
<div class="col-sm-3" >
|
||||
|
||||
@@ -62,7 +62,6 @@
|
||||
<td width="20%">任务名称</td>
|
||||
<td>时间表达式</td>
|
||||
<td>任务说明</td>
|
||||
<td>任务类型</td>
|
||||
<td>上次执行时间</td>
|
||||
<td>下次执行时间</td>
|
||||
<td width="25%">操作</td>
|
||||
@@ -84,14 +83,6 @@
|
||||
</td>
|
||||
<td> {{$v.cron_spec}} </td>
|
||||
<td> {{$v.description}} </td>
|
||||
<td>
|
||||
{{if eq $v.task_type 0}}
|
||||
定时任务
|
||||
{{else}}
|
||||
<i style="color:red">常驻任务</i>
|
||||
{{end}}
|
||||
|
||||
</td>
|
||||
<td> {{$v.prev_time}} </td>
|
||||
<td> {{$v.next_time}} </td>
|
||||
<td>
|
||||
@@ -107,14 +98,9 @@
|
||||
<a class="btn btn-info btn-xs" href="{{urlfor "TaskController.Edit"}}?id={{$v.id}}">
|
||||
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span> 编辑
|
||||
</a>
|
||||
|
||||
{{if eq $v.task_type 0}}
|
||||
<a class="btn btn-info btn-run btn-xs" href="{{urlfor "TaskController.Run"}}?id={{$v.id}}">
|
||||
<span class="glyphicon glyphicon-flash" aria-hidden="true"></span> 执行
|
||||
</a>
|
||||
{{end}}
|
||||
|
||||
|
||||
<a class="btn btn-info btn-xs" href="{{urlfor "TaskController.Logs"}}?id={{$v.id}}">
|
||||
<span class="glyphicon glyphicon-file" aria-hidden="true"></span> 日志
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user