crontab upgrade
This commit is contained in:
parent
2f7b2c151a
commit
9853a68f66
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module 474420502.top/eson/imitater
|
||||||
|
|
||||||
|
require (
|
||||||
|
gopkg.in/yaml.v2 v2.2.2
|
||||||
|
github.com/davecgh/go-spew/spew v1.1.1
|
||||||
|
474420502.top/eson/curl2info v1.0.0
|
||||||
|
474420502.top/eson/requests v1.0.0
|
||||||
|
)
|
34
task.go
34
task.go
|
@ -63,7 +63,7 @@ func splitTasks(conf *Config) []ITask {
|
||||||
task := makeRegisterType(curl.ITask).Elem().(ITask)
|
task := makeRegisterType(curl.ITask).Elem().(ITask)
|
||||||
switch conf.Mode {
|
switch conf.Mode {
|
||||||
case 0:
|
case 0:
|
||||||
copy(task.Proxies, conf.Proxies)
|
copy(task.GetProxies(), conf.Proxies)
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
case 1:
|
case 1:
|
||||||
for _, proxy := range conf.Proxies {
|
for _, proxy := range conf.Proxies {
|
||||||
|
@ -72,19 +72,19 @@ func splitTasks(conf *Config) []ITask {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ptask := NewTask(ncurl)
|
ptask := makeRegisterType(ncurl.ITask).Elem().(ITask)
|
||||||
for _, exec := range task.getPlans() {
|
for _, exec := range task.GetPlans() {
|
||||||
switch v := exec.(type) {
|
switch v := exec.(type) {
|
||||||
case *ExecuteAt:
|
case *ExecuteAt:
|
||||||
clone := &*v
|
clone := &*v
|
||||||
ptask.Plan = append(ptask.Plan, clone)
|
ptask.AppendPlans(clone)
|
||||||
case *ExecuteInterval:
|
case *ExecuteInterval:
|
||||||
clone := &*v
|
clone := &*v
|
||||||
ptask.Plan = append(ptask.Plan, clone)
|
ptask.AppendPlans(clone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptask.Proxies = append(ptask.Proxies, proxy)
|
ptask.AppendProxies(proxy)
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ type ITask interface {
|
||||||
GetPlans() []IExecute
|
GetPlans() []IExecute
|
||||||
|
|
||||||
GetProxies() []string
|
GetProxies() []string
|
||||||
SetProxies(proxies string)
|
AppendProxies(proxies ...string)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Task 任务
|
// Task 任务
|
||||||
|
@ -141,17 +141,31 @@ func (task *Task) AppendPlans(plans ...IExecute) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (task *Task) GetPlans() []IExecute {
|
||||||
|
return task.plans
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *Task) AppendProxies(proxies ...string) {
|
||||||
|
for _, proxy := range proxies {
|
||||||
|
task.proxies = append(task.proxies, proxy)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (task *Task) GetProxies() []string {
|
||||||
|
return task.proxies
|
||||||
|
}
|
||||||
|
|
||||||
// InitTask 生成一个新任务
|
// InitTask 生成一个新任务
|
||||||
func InitTask(task ITask, Curl *curl2info.CURL, Plans ...IExecute) {
|
func InitTask(task ITask, Curl *curl2info.CURL, Plans ...IExecute) {
|
||||||
|
|
||||||
// task.Conf = NewConfig(conf)
|
// task.Conf = NewConfig(conf)
|
||||||
task.setCurl(Curl)
|
task.SetCurl(Curl)
|
||||||
task.appendPlans(Plans...)
|
task.AppendPlans(Plans...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteOnPlan 按照计划执行任务并返回结果
|
// ExecuteOnPlan 按照计划执行任务并返回结果
|
||||||
func ExecuteOnPlan(task ITask) {
|
func ExecuteOnPlan(task ITask) {
|
||||||
for _, exec := range task.getPlans() {
|
for _, exec := range task.GetPlans() {
|
||||||
if exec.TimeTo() >= 0 {
|
if exec.TimeTo() >= 0 {
|
||||||
task.Execute() // 事件 在这里变化
|
task.Execute() // 事件 在这里变化
|
||||||
exec.CalculateTrigger()
|
exec.CalculateTrigger()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user