mirror of https://github.com/ouqiang/gocron
完善文档
parent
e0afae8184
commit
0e37ae335e
11
README.md
11
README.md
|
@ -1,3 +1,12 @@
|
||||||
# cron-scheduler - 定时任务调度、管理
|
# gocron - 定时任务web管理平台
|
||||||
|
|
||||||
[](https://travis-ci.org/ouqiang/cron-scheduler)
|
[](https://travis-ci.org/ouqiang/cron-scheduler)
|
||||||
|
|
||||||
|
## 安装, 解压后执行
|
||||||
|
```shell
|
||||||
|
./gocron server
|
||||||
|
```
|
||||||
|
可选参数
|
||||||
|
+ -p 端口, 指定端口
|
||||||
|
+ -d 后台运行 (不支持windows)
|
||||||
|
+ -h 查看帮
|
||||||
|
|
|
@ -19,7 +19,7 @@ type Task struct {
|
||||||
Id int `xorm:"int pk autoincr"`
|
Id int `xorm:"int pk autoincr"`
|
||||||
Name string `xorm:"varchar(64) notnull"` // 任务名称
|
Name string `xorm:"varchar(64) notnull"` // 任务名称
|
||||||
Spec string `xorm:"varchar(64) notnull"` // crontab
|
Spec string `xorm:"varchar(64) notnull"` // crontab
|
||||||
Protocol TaskProtocol `xorm:"tinyint notnull"` // 协议 1:http 2:ssh-command 3: 本地命令
|
Protocol TaskProtocol `xorm:"tinyint notnull"` // 协议 1:http 2:ssh-command 3: 系统命令
|
||||||
Command string `xorm:"varchar(512) notnull"` // URL地址或shell命令
|
Command string `xorm:"varchar(512) notnull"` // URL地址或shell命令
|
||||||
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
||||||
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 重试次数
|
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 重试次数
|
||||||
|
|
|
@ -14,7 +14,7 @@ type TaskLog struct {
|
||||||
TaskId int `xorm:"int notnull index default 0"` // 任务id
|
TaskId int `xorm:"int notnull index default 0"` // 任务id
|
||||||
Name string `xorm:"varchar(64) notnull"` // 任务名称
|
Name string `xorm:"varchar(64) notnull"` // 任务名称
|
||||||
Spec string `xorm:"varchar(64) notnull"` // crontab
|
Spec string `xorm:"varchar(64) notnull"` // crontab
|
||||||
Protocol TaskProtocol `xorm:"tinyint notnull"` // 协议 1:http 2:ssh-command
|
Protocol TaskProtocol `xorm:"tinyint notnull"` // 协议 1:http 2:ssh-command 3:系统命令
|
||||||
Command string `xorm:"varchar(512) notnull"` // URL地址或shell命令
|
Command string `xorm:"varchar(512) notnull"` // URL地址或shell命令
|
||||||
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
Timeout int `xorm:"mediumint notnull default 0"` // 任务执行超时时间(单位秒),0不限制
|
||||||
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 任务重试次数
|
RetryTimes int8 `xorm:"tinyint notnull default 0"` // 任务重试次数
|
||||||
|
|
|
@ -247,7 +247,7 @@ func parseQueryParams(ctx *macaron.Context) (models.CommonMap) {
|
||||||
func setHostsToTemplate(ctx *macaron.Context) {
|
func setHostsToTemplate(ctx *macaron.Context) {
|
||||||
hostModel := new(models.Host)
|
hostModel := new(models.Host)
|
||||||
hosts, err := hostModel.List(models.CommonMap{})
|
hosts, err := hostModel.List(models.CommonMap{})
|
||||||
if err != nil || len(hosts) == 0 {
|
if err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
}
|
}
|
||||||
ctx.Data["Hosts"] = hosts
|
ctx.Data["Hosts"] = hosts
|
||||||
|
|
|
@ -14,6 +14,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form class="ui form">
|
<form class="ui form">
|
||||||
|
<div class="ui blue center aligned segment">
|
||||||
|
<p>数据库配置</p>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
<div class="three fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>数据库(目前只支持MySQL)</label>
|
<label>数据库(目前只支持MySQL)</label>
|
||||||
|
@ -57,6 +61,11 @@
|
||||||
<input type="text" name="db_table_prefix" value="cron_">
|
<input type="text" name="db_table_prefix" value="cron_">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ui divider"></div>
|
||||||
|
<div class="ui blue center aligned segment">
|
||||||
|
<p>管理员账号配置</p>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
<div class="three fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>管理员账号</label>
|
<label>管理员账号</label>
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<select name="protocol" id="protocol">
|
<select name="protocol" id="protocol">
|
||||||
<option value="0">协议</option>
|
<option value="0">协议</option>
|
||||||
<option value="3" {{{if eq .Params.Protocol 3}}}selected{{{end}}}>本地命令</option>
|
<option value="3" {{{if eq .Params.Protocol 3}}}selected{{{end}}}>系统命令</option>
|
||||||
<option value="2" {{{if eq .Params.Protocol 2}}}selected{{{end}}} data-match="host_id" data-validate-type="selectProtocol">SSH</option>
|
<option value="2" {{{if eq .Params.Protocol 2}}}selected{{{end}}} data-match="host_id" data-validate-type="selectProtocol">SSH</option>
|
||||||
<option value="1" {{{if eq .Params.Protocol 1}}}selected{{{end}}}>HTTP</option>
|
<option value="1" {{{if eq .Params.Protocol 1}}}selected{{{end}}}>HTTP</option>
|
||||||
</select>
|
</select>
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
<td><a href="/task?id={{{.TaskId}}}">{{{.TaskId}}}</a></td>
|
<td><a href="/task?id={{{.TaskId}}}">{{{.TaskId}}}</a></td>
|
||||||
<td>{{{.Name}}}</td>
|
<td>{{{.Name}}}</td>
|
||||||
<td>{{{.Spec}}}</td>
|
<td>{{{.Spec}}}</td>
|
||||||
<td>{{{if eq .Protocol 1}}} HTTP {{{else if eq .Protocol 2}}} SSH {{{else}}} 本地命令 {{{end}}}</td>
|
<td>{{{if eq .Protocol 1}}} HTTP {{{else if eq .Protocol 2}}} SSH {{{else}}} 系统命令 {{{end}}}</td>
|
||||||
<td>{{{if gt .Timeout 0}}}{{{.Timeout}}}秒{{{else}}}不限制{{{end}}}</td>
|
<td>{{{if gt .Timeout 0}}}{{{.Timeout}}}秒{{{else}}}不限制{{{end}}}</td>
|
||||||
<td>{{{.RetryTimes}}}</td>
|
<td>{{{.RetryTimes}}}</td>
|
||||||
<td>{{{.Hostname}}}</td>
|
<td>{{{.Hostname}}}</td>
|
||||||
|
|
|
@ -15,7 +15,9 @@
|
||||||
<input type="hidden" name="id" value="{{{.Task.Id}}}">
|
<input type="hidden" name="id" value="{{{.Task.Id}}}">
|
||||||
<div class="two fields">
|
<div class="two fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
<label>
|
||||||
<div class="content">任务名称</div>
|
<div class="content">任务名称</div>
|
||||||
|
</label>
|
||||||
<div class="ui small input">
|
<div class="ui small input">
|
||||||
<input type="text" name="name" value="{{{.Task.Task.Name}}}">
|
<input type="text" name="name" value="{{{.Task.Task.Name}}}">
|
||||||
</div>
|
</div>
|
||||||
|
@ -23,51 +25,97 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="two fields">
|
<div class="two fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>crontab表达式</label>
|
<label>
|
||||||
|
<div class="content">
|
||||||
|
crontab表达式
|
||||||
|
<div class="ui blue message">
|
||||||
|
Linux-crontab表达式语法, 精确到秒 <br>
|
||||||
|
格式: 秒 分 时 天 月 周 <br>
|
||||||
|
快捷语法: <br>
|
||||||
|
@yearly 每年运行一次 <br>
|
||||||
|
@monthly 每月运行一次 <br>
|
||||||
|
@weekly 每周运行一次 <br>
|
||||||
|
@daily 每天运行一次 <br>
|
||||||
|
@midnight 每天午夜运行一次<br>
|
||||||
|
@hourly 每小时运行一次 <br>
|
||||||
|
@every 30s 每隔30秒运行一次 <br>
|
||||||
|
@every 1m20s 每隔1分钟20秒运行一次 <br>
|
||||||
|
@every 3h5m10s 每隔3小时5分钟10秒运行一次 <br>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
<div class="ui small left icon input">
|
<div class="ui small left icon input">
|
||||||
<textarea rows="5" name="spec">{{{.Task.Spec}}}</textarea>
|
<input type="text" name="spec" value="{{{.Task.Spec}}}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="four fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>协议</label>
|
<label>协议</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
系统命令: 调用本机系统命令 <br>
|
||||||
|
SSH: 通过SSH执行远程命令 <br>
|
||||||
|
HTTP: 执行HTTP-GET请求 <br>
|
||||||
|
</div>
|
||||||
<select name="protocol" id="protocol">
|
<select name="protocol" id="protocol">
|
||||||
<option value="3" {{{if .Task}}} {{{if eq .Task.Protocol 3}}}selected{{{end}}} {{{end}}}>本地命令</option>
|
<option value="3" {{{if .Task}}} {{{if eq .Task.Protocol 3}}}selected{{{end}}} {{{end}}}>系统命令</option>
|
||||||
<option value="2" {{{if .Task}}} {{{if eq .Task.Protocol 2}}}selected{{{end}}} {{{end}}} data-match="host_id" data-validate-type="selectProtocol">SSH</option>
|
<option value="2" {{{if .Task}}} {{{if eq .Task.Protocol 2}}}selected{{{end}}} {{{end}}} data-match="host_id" data-validate-type="selectProtocol">SSH</option>
|
||||||
<option value="1" {{{if .Task}}} {{{if eq .Task.Protocol 1}}}selected{{{end}}} {{{end}}}>HTTP</option>
|
<option value="1" {{{if .Task}}} {{{if eq .Task.Protocol 1}}}selected{{{end}}} {{{end}}}>HTTP</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="four fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>主机</label>
|
<label>主机</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
<pre>选择SSH协议时,需选择执行主机</pre>
|
||||||
|
</div>
|
||||||
<select name="host_id" id="hostId">
|
<select name="host_id" id="hostId">
|
||||||
<option value="">选择主机</option>
|
<option value="">选择主机</option>
|
||||||
{{{range $i, $v := .Hosts}}}
|
{{{range $i, $v := .Hosts}}}
|
||||||
<option value="{{{.Id}}}" {{{if $.Task}}}{{{if eq $.Task.HostId .Id }}} selected {{{end}}} {{{end}}}>{{{.Alias}}}-{{{.Name}}}</option>
|
<option value="{{{.Id}}}" {{{if $.Task}}}{{{if eq $.Task.HostId .Id }}} selected {{{end}}} {{{end}}}>{{{.Alias}}}-{{{.Name}}}</option>
|
||||||
</div>
|
|
||||||
{{{end}}}
|
{{{end}}}
|
||||||
</select>
|
</select> <a class="ui blue button" href="/host/create">添加主机</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="two fields">
|
<div class="two fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>命令(shell命令|URL地址, 多条shell命令";"分隔)</label>
|
<label>命令</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
根据选择的协议输入相应的命令 <br>
|
||||||
|
系统命令 - windows: ipconfig /all linux: ifconfig -a <br>
|
||||||
|
SSH - netstat -natpu <br>
|
||||||
|
HTTP - http://golang.org <br>
|
||||||
|
</div>
|
||||||
<textarea rows="5" name="command">{{{.Task.Command}}}</textarea>
|
<textarea rows="5" name="command">{{{.Task.Command}}}</textarea>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="three fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>任务超时时间 (单位秒, 默认0,不限制超时)</label>
|
<label>任务超时时间(秒)</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
默认0,不限制超时
|
||||||
|
</div>
|
||||||
<input type="text" name="timeout" value="{{{.Task.Timeout}}}">
|
<input type="text" name="timeout" value="{{{.Task.Timeout}}}">
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="two fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>任务重试次数 (默认0, 取值范围1-10)</label>
|
<label>任务重试次数</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
无法连接远程主机,shell返回值非0, http响应码非200等异常返回,可重试<br>
|
||||||
|
重试时间间隔 重试次数 * 分钟, 按1分钟、2分钟、3分钟.....的间隔进行重试<br>
|
||||||
|
取值范围1-10, 默认0,不重试
|
||||||
|
</div>
|
||||||
<input type="text" name="timeout" value="{{{.Task.Timeout}}}">
|
<input type="text" name="timeout" value="{{{.Task.Timeout}}}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="three fields">
|
<div class="three fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>任务状态 (任务添加成功后,是否立即调度)</label>
|
<label>任务状态</label>
|
||||||
|
<div class="ui blue message">
|
||||||
|
任务添加成功后,是否立即调度
|
||||||
|
</div>
|
||||||
<select name="status">
|
<select name="status">
|
||||||
<option value="2"{{{if .Task}}} {{{if eq .Task.Status 2}}}selected{{{end}}} {{{end}}}>暂停</option>
|
<option value="2"{{{if .Task}}} {{{if eq .Task.Status 2}}}selected{{{end}}} {{{end}}}>暂停</option>
|
||||||
<option value="1" {{{if .Task}}} {{{if eq .Task.Status 1}}}selected{{{end}}} {{{end}}}>激活</option>
|
<option value="1" {{{if .Task}}} {{{if eq .Task.Status 1}}}selected{{{end}}} {{{end}}}>激活</option>
|
||||||
|
|
Loading…
Reference in New Issue