mirror of https://github.com/ouqiang/gocron
使用goimports格式化代码
parent
4c940c2088
commit
94c9963e81
4
build.sh
4
build.sh
|
@ -63,9 +63,9 @@ fi
|
||||||
|
|
||||||
echo '开始编译调度器'
|
echo '开始编译调度器'
|
||||||
if [[ $OS = 'windows' ]];then
|
if [[ $OS = 'windows' ]];then
|
||||||
GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
|
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
|
||||||
else
|
else
|
||||||
GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
|
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags gocron -ldflags '-w'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $? != 0 ]];then
|
if [[ $? != 0 ]];then
|
||||||
|
|
|
@ -70,9 +70,9 @@ fi
|
||||||
|
|
||||||
echo '开始编译任务节点'
|
echo '开始编译任务节点'
|
||||||
if [[ $OS = 'windows' ]];then
|
if [[ $OS = 'windows' ]];then
|
||||||
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
||||||
else
|
else
|
||||||
GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -tags node -ldflags '-w' -o $EXEC_NAME
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $? != 0 ]];then
|
if [[ $? != 0 ]];then
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/app"
|
"github.com/ouqiang/gocron/modules/app"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
|
@ -9,9 +13,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/service"
|
"github.com/ouqiang/gocron/service"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// web服务器默认端口
|
// web服务器默认端口
|
||||||
|
|
|
@ -3,9 +3,10 @@ package models
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Migration struct{}
|
type Migration struct{}
|
||||||
|
@ -172,7 +173,7 @@ func (migration *Migration) upgradeFor130(session *xorm.Session) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 升级到v1.4版本
|
// 升级到v1.4版本
|
||||||
func (migration *Migration) upgradeFor140(session *xorm.Session) error {
|
func (migration *Migration) upgradeFor140(session *xorm.Session) error {
|
||||||
logger.Info("开始升级到v1.4")
|
logger.Info("开始升级到v1.4")
|
||||||
|
|
||||||
tableName := TablePrefix + "task"
|
tableName := TablePrefix + "task"
|
||||||
|
@ -180,15 +181,13 @@ func (migration *Migration) upgradeFor140(session *xorm.Session) error {
|
||||||
// retry_interval 重试间隔时间(秒)
|
// retry_interval 重试间隔时间(秒)
|
||||||
// http_method http请求方法
|
// http_method http请求方法
|
||||||
sql := fmt.Sprintf(
|
sql := fmt.Sprintf(
|
||||||
"ALTER TABLE %s ADD COLUMN retry_interval SMALLINT NOT NULL DEFAULT 0,ADD COLUMN http_method TINYINT NOT NULL DEFAULT 1", tableName)
|
"ALTER TABLE %s ADD COLUMN retry_interval SMALLINT NOT NULL DEFAULT 0,ADD COLUMN http_method TINYINT NOT NULL DEFAULT 1", tableName)
|
||||||
_, err := session.Exec(sql)
|
_, err := session.Exec(sql)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logger.Info("已升级到v1.4\n")
|
logger.Info("已升级到v1.4\n")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -2,6 +2,9 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/go-xorm/core"
|
"github.com/go-xorm/core"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
|
@ -9,8 +12,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/setting"
|
"github.com/ouqiang/gocron/modules/setting"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Status int8
|
type Status int8
|
||||||
|
|
|
@ -2,9 +2,10 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/go-xorm/xorm"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-xorm/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskProtocol int8
|
type TaskProtocol int8
|
||||||
|
@ -31,17 +32,17 @@ const (
|
||||||
type TaskHTTPMethod int8
|
type TaskHTTPMethod int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TaskHTTPMethodGet TaskHTTPMethod = 1;
|
TaskHTTPMethodGet TaskHTTPMethod = 1
|
||||||
TaskHttpMethodPost TaskHTTPMethod = 2;
|
TaskHttpMethodPost TaskHTTPMethod = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
// 任务
|
// 任务
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Id int `xorm:"int pk autoincr"`
|
Id int `xorm:"int pk autoincr"`
|
||||||
Name string `xorm:"varchar(32) notnull"` // 任务名称
|
Name string `xorm:"varchar(32) notnull"` // 任务名称
|
||||||
Level TaskLevel `xorm:"tinyint notnull index default 1"` // 任务等级 1: 主任务 2: 依赖任务
|
Level TaskLevel `xorm:"tinyint notnull index default 1"` // 任务等级 1: 主任务 2: 依赖任务
|
||||||
DependencyTaskId string `xorm:"varchar(64) notnull default ''"` // 依赖任务ID,多个ID逗号分隔
|
DependencyTaskId string `xorm:"varchar(64) notnull default ''"` // 依赖任务ID,多个ID逗号分隔
|
||||||
DependencyStatus TaskDependencyStatus `xorm:"tinyint notnull default 1"` // 依赖关系 1:强依赖 主任务执行成功, 依赖任务才会被执行 2:弱依赖
|
DependencyStatus TaskDependencyStatus `xorm:"tinyint notnull default 1"` // 依赖关系 1:强依赖 主任务执行成功, 依赖任务才会被执行 2:弱依赖
|
||||||
Spec string `xorm:"varchar(64) notnull"` // crontab
|
Spec string `xorm:"varchar(64) notnull"` // crontab
|
||||||
Protocol TaskProtocol `xorm:"tinyint notnull index"` // 协议 1:http 2:系统命令
|
Protocol TaskProtocol `xorm:"tinyint notnull index"` // 协议 1:http 2:系统命令
|
||||||
Command string `xorm:"varchar(256) notnull"` // URL地址或shell命令
|
Command string `xorm:"varchar(256) notnull"` // URL地址或shell命令
|
||||||
|
@ -49,9 +50,9 @@ type Task struct {
|
||||||
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
||||||
Multi int8 `xorm:"tinyint notnull default 1"` // 是否允许多实例运行
|
Multi int8 `xorm:"tinyint notnull default 1"` // 是否允许多实例运行
|
||||||
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 重试次数
|
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 重试次数
|
||||||
RetryInterval int16 `xorm:"smallint notnull default 0"` // 重试间隔时间
|
RetryInterval int16 `xorm:"smallint notnull default 0"` // 重试间隔时间
|
||||||
NotifyStatus int8 `xorm:"tinyint notnull default 1"` // 任务执行结束是否通知 0: 不通知 1: 失败通知 2: 执行结束通知
|
NotifyStatus int8 `xorm:"tinyint notnull default 1"` // 任务执行结束是否通知 0: 不通知 1: 失败通知 2: 执行结束通知
|
||||||
NotifyType int8 `xorm:"tinyint notnull default 0"` // 通知类型 1: 邮件 2: slack
|
NotifyType int8 `xorm:"tinyint notnull default 0"` // 通知类型 1: 邮件 2: slack
|
||||||
NotifyReceiverId string `xorm:"varchar(256) notnull default '' "` // 通知接受者ID, setting表主键ID,多个ID逗号分隔
|
NotifyReceiverId string `xorm:"varchar(256) notnull default '' "` // 通知接受者ID, setting表主键ID,多个ID逗号分隔
|
||||||
Tag string `xorm:"varchar(32) notnull default ''"`
|
Tag string `xorm:"varchar(32) notnull default ''"`
|
||||||
Remark string `xorm:"varchar(100) notnull default ''"` // 备注
|
Remark string `xorm:"varchar(100) notnull default ''"` // 备注
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/go-xorm/xorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-xorm/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskType int8
|
type TaskType int8
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const PasswordSaltLength = 6
|
const PasswordSaltLength = 6
|
||||||
|
@ -78,7 +79,7 @@ func (user *User) Match(username, password string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户详情
|
// 获取用户详情
|
||||||
func (user *User) Find(id int) (error) {
|
func (user *User) Find(id int) error {
|
||||||
_, err := Db.Id(id).Get(user)
|
_, err := Db.Id(id).Get(user)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -3,13 +3,14 @@ package app
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"fmt"
|
||||||
"github.com/ouqiang/gocron/modules/setting"
|
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
|
||||||
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
|
"github.com/ouqiang/gocron/modules/setting"
|
||||||
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -2,10 +2,11 @@ package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/cihub/seelog"
|
|
||||||
"gopkg.in/macaron.v1"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/cihub/seelog"
|
||||||
|
"gopkg.in/macaron.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 日志库
|
// 日志库
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package notify
|
package notify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-gomail/gomail"
|
"github.com/go-gomail/gomail"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @author qiang.ou<qingqianludao@gmail.com>
|
// @author qiang.ou<qingqianludao@gmail.com>
|
||||||
|
|
|
@ -2,8 +2,9 @@ package notify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message map[string]interface{}
|
type Message map[string]interface{}
|
||||||
|
|
|
@ -4,13 +4,14 @@ package notify
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/httpclient"
|
"github.com/ouqiang/gocron/modules/httpclient"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Slack struct{}
|
type Slack struct{}
|
||||||
|
|
|
@ -5,8 +5,9 @@ import (
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"google.golang.org/grpc/credentials"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"google.golang.org/grpc/credentials"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Certificate struct {
|
type Certificate struct {
|
||||||
|
|
|
@ -3,14 +3,15 @@ package client
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/rpc/grpcpool"
|
"github.com/ouqiang/gocron/modules/rpc/grpcpool"
|
||||||
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"time"
|
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -25,7 +26,7 @@ func generateTaskUniqueKey(ip string, port int, id int64) string {
|
||||||
return fmt.Sprintf("%s:%d:%d", ip, port, id)
|
return fmt.Sprintf("%s:%d:%d", ip, port, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Stop(ip string, port int , id int64) {
|
func Stop(ip string, port int, id int64) {
|
||||||
key := generateTaskUniqueKey(ip, port, id)
|
key := generateTaskUniqueKey(ip, port, id)
|
||||||
cancel, ok := taskMap.Load(key)
|
cancel, ok := taskMap.Load(key)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -2,13 +2,14 @@ package grpcpool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/app"
|
"github.com/ouqiang/gocron/modules/app"
|
||||||
"github.com/ouqiang/gocron/modules/rpc/auth"
|
"github.com/ouqiang/gocron/modules/rpc/auth"
|
||||||
"github.com/silenceper/pool"
|
"github.com/silenceper/pool"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/rpc/auth"
|
"github.com/ouqiang/gocron/modules/rpc/auth"
|
||||||
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
|
@ -8,7 +10,6 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct{}
|
type Server struct{}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package setting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,12 @@ package utils
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"github.com/Tang-RoseChild/mahonia"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Tang-RoseChild/mahonia"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 生成长度为length的随机字符串
|
// 生成长度为length的随机字符串
|
||||||
|
|
|
@ -4,9 +4,10 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
|
|
|
@ -4,10 +4,11 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"golang.org/x/net/context"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
|
|
|
@ -2,6 +2,10 @@ package host
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
"github.com/go-macaron/binding"
|
"github.com/go-macaron/binding"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
|
@ -13,9 +17,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
"github.com/ouqiang/gocron/service"
|
"github.com/ouqiang/gocron/service"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Index 主机列表
|
// Index 主机列表
|
||||||
|
|
|
@ -2,6 +2,8 @@ package install
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-macaron/binding"
|
"github.com/go-macaron/binding"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/app"
|
"github.com/ouqiang/gocron/modules/app"
|
||||||
|
@ -9,7 +11,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"github.com/ouqiang/gocron/service"
|
"github.com/ouqiang/gocron/service"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 系统安装
|
// 系统安装
|
||||||
|
|
|
@ -2,12 +2,13 @@ package loginlog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"html/template"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Index(ctx *macaron.Context) {
|
func Index(ctx *macaron.Context) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package manage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"html/template"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-macaron/binding"
|
"github.com/go-macaron/binding"
|
||||||
"github.com/go-macaron/cache"
|
"github.com/go-macaron/cache"
|
||||||
"github.com/go-macaron/captcha"
|
"github.com/go-macaron/captcha"
|
||||||
|
@ -18,11 +24,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/routers/tasklog"
|
"github.com/ouqiang/gocron/routers/tasklog"
|
||||||
"github.com/ouqiang/gocron/routers/user"
|
"github.com/ouqiang/gocron/routers/user"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 静态文件目录
|
// 静态文件目录
|
||||||
|
@ -220,13 +221,13 @@ func userAuth(ctx *macaron.Context, sess session.Store) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// URL权限验证
|
// URL权限验证
|
||||||
func urlAuth(ctx *macaron.Context, sess session.Store) {
|
func urlAuth(ctx *macaron.Context, sess session.Store) {
|
||||||
if user.IsAdmin(sess) {
|
if user.IsAdmin(sess) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uri := strings.TrimSpace(ctx.Req.URL.Path)
|
uri := strings.TrimSpace(ctx.Req.URL.Path)
|
||||||
uri = strings.TrimRight(uri, "/")
|
uri = strings.TrimRight(uri, "/")
|
||||||
if (strings.HasPrefix(uri, "/api")) {
|
if strings.HasPrefix(uri, "/api") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 普通用户允许访问的URL地址
|
// 普通用户允许访问的URL地址
|
||||||
|
|
|
@ -2,6 +2,10 @@ package task
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
"github.com/go-macaron/binding"
|
"github.com/go-macaron/binding"
|
||||||
"github.com/jakecoffman/cron"
|
"github.com/jakecoffman/cron"
|
||||||
|
@ -11,9 +15,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
"github.com/ouqiang/gocron/service"
|
"github.com/ouqiang/gocron/service"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"html/template"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type TaskForm struct {
|
type TaskForm struct {
|
||||||
|
@ -23,11 +24,11 @@ type TaskForm struct {
|
||||||
DependencyTaskId string
|
DependencyTaskId string
|
||||||
Name string `binding:"Required;MaxSize(32)"`
|
Name string `binding:"Required;MaxSize(32)"`
|
||||||
Spec string
|
Spec string
|
||||||
Protocol models.TaskProtocol `binding:"In(1,2)"`
|
Protocol models.TaskProtocol `binding:"In(1,2)"`
|
||||||
Command string `binding:"Required;MaxSize(256)"`
|
Command string `binding:"Required;MaxSize(256)"`
|
||||||
HttpMethod models.TaskHTTPMethod `binding:"In(1,2)"`
|
HttpMethod models.TaskHTTPMethod `binding:"In(1,2)"`
|
||||||
Timeout int `binding:"Range(0,86400)"`
|
Timeout int `binding:"Range(0,86400)"`
|
||||||
Multi int8 `binding:"In(1,2)"`
|
Multi int8 `binding:"In(1,2)"`
|
||||||
RetryTimes int8
|
RetryTimes int8
|
||||||
RetryInterval int16
|
RetryInterval int16
|
||||||
HostId string
|
HostId string
|
||||||
|
|
|
@ -4,14 +4,15 @@ package tasklog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
|
||||||
"github.com/Unknwon/paginater"
|
"github.com/Unknwon/paginater"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/logger"
|
"github.com/ouqiang/gocron/modules/logger"
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
"gopkg.in/macaron.v1"
|
|
||||||
"html/template"
|
|
||||||
"github.com/ouqiang/gocron/service"
|
"github.com/ouqiang/gocron/service"
|
||||||
|
"gopkg.in/macaron.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Index(ctx *macaron.Context) {
|
func Index(ctx *macaron.Context) {
|
||||||
|
@ -50,14 +51,14 @@ func Clear(ctx *macaron.Context) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止运行中的任务
|
// 停止运行中的任务
|
||||||
func Stop(ctx *macaron.Context) string {
|
func Stop(ctx *macaron.Context) string {
|
||||||
id := ctx.QueryInt64("id")
|
id := ctx.QueryInt64("id")
|
||||||
taskId := ctx.QueryInt("task_id")
|
taskId := ctx.QueryInt("task_id")
|
||||||
taskModel := new(models.Task)
|
taskModel := new(models.Task)
|
||||||
task, err := taskModel.Detail(taskId)
|
task, err := taskModel.Detail(taskId)
|
||||||
json := utils.JsonResponse{}
|
json := utils.JsonResponse{}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return json.CommonFailure("获取任务信息失败#" + err.Error(), err)
|
return json.CommonFailure("获取任务信息失败#"+err.Error(), err)
|
||||||
}
|
}
|
||||||
if task.Protocol != models.TaskRPC {
|
if task.Protocol != models.TaskRPC {
|
||||||
return json.CommonFailure("仅支持SHELL任务手动停止")
|
return json.CommonFailure("仅支持SHELL任务手动停止")
|
||||||
|
@ -70,7 +71,7 @@ func Stop(ctx *macaron.Context) string {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return json.Success("已执行停止操作, 请等待任务退出", nil);
|
return json.Success("已执行停止操作, 请等待任务退出", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除N个月前的日志
|
// 删除N个月前的日志
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Unknwon/paginater"
|
||||||
"github.com/go-macaron/captcha"
|
"github.com/go-macaron/captcha"
|
||||||
"github.com/go-macaron/session"
|
"github.com/go-macaron/session"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
|
@ -8,10 +13,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/modules/utils"
|
"github.com/ouqiang/gocron/modules/utils"
|
||||||
"github.com/ouqiang/gocron/routers/base"
|
"github.com/ouqiang/gocron/routers/base"
|
||||||
"gopkg.in/macaron.v1"
|
"gopkg.in/macaron.v1"
|
||||||
"github.com/Unknwon/paginater"
|
|
||||||
"html/template"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// @author qiang.ou<qingqianludao@gmail.com>
|
// @author qiang.ou<qingqianludao@gmail.com>
|
||||||
|
@ -19,17 +20,17 @@ import (
|
||||||
|
|
||||||
// UserForm 用户表单
|
// UserForm 用户表单
|
||||||
type UserForm struct {
|
type UserForm struct {
|
||||||
Id int
|
Id int
|
||||||
Name string `binding:"Required;MaxSize(32)"` // 用户名
|
Name string `binding:"Required;MaxSize(32)"` // 用户名
|
||||||
Password string // 密码
|
Password string // 密码
|
||||||
ConfirmPassword string // 确认密码
|
ConfirmPassword string // 确认密码
|
||||||
Email string `binding:"Required;MaxSize(50)"` // 邮箱
|
Email string `binding:"Required;MaxSize(50)"` // 邮箱
|
||||||
IsAdmin int8 // 是否是管理员 1:管理员 0:普通用户
|
IsAdmin int8 // 是否是管理员 1:管理员 0:普通用户
|
||||||
Status models.Status
|
Status models.Status
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index 用户列表页
|
// Index 用户列表页
|
||||||
func Index(ctx *macaron.Context) {
|
func Index(ctx *macaron.Context) {
|
||||||
queryParams := parseQueryParams(ctx)
|
queryParams := parseQueryParams(ctx)
|
||||||
userModel := new(models.User)
|
userModel := new(models.User)
|
||||||
users, err := userModel.List(queryParams)
|
users, err := userModel.List(queryParams)
|
||||||
|
@ -59,7 +60,7 @@ func parseQueryParams(ctx *macaron.Context) models.CommonMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create 新增用户页
|
// Create 新增用户页
|
||||||
func Create(ctx *macaron.Context) {
|
func Create(ctx *macaron.Context) {
|
||||||
userModel := new(models.User)
|
userModel := new(models.User)
|
||||||
userModel.Status = models.Enabled
|
userModel.Status = models.Enabled
|
||||||
userModel.IsAdmin = 0
|
userModel.IsAdmin = 0
|
||||||
|
@ -129,9 +130,9 @@ func Store(ctx *macaron.Context, form UserForm) string {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_, err = userModel.Update(form.Id, models.CommonMap{
|
_, err = userModel.Update(form.Id, models.CommonMap{
|
||||||
"name": form.Name,
|
"name": form.Name,
|
||||||
"email": form.Email,
|
"email": form.Email,
|
||||||
"status": form.Status,
|
"status": form.Status,
|
||||||
"is_admin": form.IsAdmin,
|
"is_admin": form.IsAdmin,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -139,7 +140,6 @@ func Store(ctx *macaron.Context, form UserForm) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return json.Success("保存成功", nil)
|
return json.Success("保存成功", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,12 @@ package service
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jakecoffman/cron"
|
"github.com/jakecoffman/cron"
|
||||||
"github.com/ouqiang/gocron/models"
|
"github.com/ouqiang/gocron/models"
|
||||||
"github.com/ouqiang/gocron/modules/httpclient"
|
"github.com/ouqiang/gocron/modules/httpclient"
|
||||||
|
@ -10,11 +16,6 @@ import (
|
||||||
"github.com/ouqiang/gocron/modules/notify"
|
"github.com/ouqiang/gocron/modules/notify"
|
||||||
rpcClient "github.com/ouqiang/gocron/modules/rpc/client"
|
rpcClient "github.com/ouqiang/gocron/modules/rpc/client"
|
||||||
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
pb "github.com/ouqiang/gocron/modules/rpc/proto"
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -23,7 +24,7 @@ var (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// 定时任务调度管理器
|
// 定时任务调度管理器
|
||||||
serviceCron *cron.Cron
|
serviceCron *cron.Cron
|
||||||
|
|
||||||
// 同一任务是否有实例处于运行中
|
// 同一任务是否有实例处于运行中
|
||||||
runInstance Instance
|
runInstance Instance
|
||||||
|
@ -32,7 +33,7 @@ var (
|
||||||
taskCount TaskCount
|
taskCount TaskCount
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
serviceCron = cron.New()
|
serviceCron = cron.New()
|
||||||
serviceCron.Start()
|
serviceCron.Start()
|
||||||
taskCount = TaskCount{sync.WaitGroup{}, make(chan bool)}
|
taskCount = TaskCount{sync.WaitGroup{}, make(chan bool)}
|
||||||
|
@ -41,24 +42,24 @@ func init() {
|
||||||
|
|
||||||
// 任务计数
|
// 任务计数
|
||||||
type TaskCount struct {
|
type TaskCount struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
exit chan bool
|
exit chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TaskCount) Add() {
|
func (tc *TaskCount) Add() {
|
||||||
tc.wg.Add(1)
|
tc.wg.Add(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TaskCount) Done() {
|
func (tc *TaskCount) Done() {
|
||||||
tc.wg.Done()
|
tc.wg.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TaskCount) Exit() {
|
func (tc *TaskCount) Exit() {
|
||||||
tc.wg.Done()
|
tc.wg.Done()
|
||||||
<-tc.exit
|
<-tc.exit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TaskCount) Wait() {
|
func (tc *TaskCount) Wait() {
|
||||||
tc.Add()
|
tc.Add()
|
||||||
tc.wg.Wait()
|
tc.wg.Wait()
|
||||||
close(tc.exit)
|
close(tc.exit)
|
||||||
|
@ -92,7 +93,6 @@ type TaskResult struct {
|
||||||
RetryTimes int8
|
RetryTimes int8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 初始化任务, 从数据库取出所有任务, 添加到定时任务并运行
|
// 初始化任务, 从数据库取出所有任务, 添加到定时任务并运行
|
||||||
func (task Task) Initialize() {
|
func (task Task) Initialize() {
|
||||||
taskModel := new(models.Task)
|
taskModel := new(models.Task)
|
||||||
|
@ -137,11 +137,11 @@ func (task Task) Add(taskModel models.Task) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 停止运行中的任务
|
// 停止运行中的任务
|
||||||
func (task Task) Stop(ip string, port int, id int64) {
|
func (task Task) Stop(ip string, port int, id int64) {
|
||||||
rpcClient.Stop(ip, port, id)
|
rpcClient.Stop(ip, port, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (task Task) Remove(id int) {
|
func (task Task) Remove(id int) {
|
||||||
serviceCron.RemoveJob(strconv.Itoa(id))
|
serviceCron.RemoveJob(strconv.Itoa(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,13 +171,13 @@ func (h *HTTPHandler) Run(taskModel models.Task, taskUniqueId int64) (result str
|
||||||
taskModel.Timeout = HttpExecTimeout
|
taskModel.Timeout = HttpExecTimeout
|
||||||
}
|
}
|
||||||
var resp httpclient.ResponseWrapper
|
var resp httpclient.ResponseWrapper
|
||||||
if (taskModel.HttpMethod == models.TaskHTTPMethodGet) {
|
if taskModel.HttpMethod == models.TaskHTTPMethodGet {
|
||||||
resp = httpclient.Get(taskModel.Command, taskModel.Timeout)
|
resp = httpclient.Get(taskModel.Command, taskModel.Timeout)
|
||||||
} else {
|
} else {
|
||||||
urlFields := strings.Split(taskModel.Command, "?")
|
urlFields := strings.Split(taskModel.Command, "?")
|
||||||
taskModel.Command = urlFields[0]
|
taskModel.Command = urlFields[0]
|
||||||
var params string
|
var params string
|
||||||
if (len(urlFields) >= 2) {
|
if len(urlFields) >= 2 {
|
||||||
params = urlFields[1]
|
params = urlFields[1]
|
||||||
}
|
}
|
||||||
resp = httpclient.PostParams(taskModel.Command, params, taskModel.Timeout)
|
resp = httpclient.PostParams(taskModel.Command, params, taskModel.Timeout)
|
||||||
|
|
Loading…
Reference in New Issue