crontab upgrade

This commit is contained in:
eson 2018-12-03 03:17:24 +08:00
parent 2f7b2c151a
commit 9853a68f66
2 changed files with 32 additions and 10 deletions

8
go.mod Normal file
View 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
View File

@ -63,7 +63,7 @@ func splitTasks(conf *Config) []ITask {
task := makeRegisterType(curl.ITask).Elem().(ITask)
switch conf.Mode {
case 0:
copy(task.Proxies, conf.Proxies)
copy(task.GetProxies(), conf.Proxies)
tasks = append(tasks, task)
case 1:
for _, proxy := range conf.Proxies {
@ -72,19 +72,19 @@ func splitTasks(conf *Config) []ITask {
panic(err)
}
ptask := NewTask(ncurl)
for _, exec := range task.getPlans() {
ptask := makeRegisterType(ncurl.ITask).Elem().(ITask)
for _, exec := range task.GetPlans() {
switch v := exec.(type) {
case *ExecuteAt:
clone := &*v
ptask.Plan = append(ptask.Plan, clone)
ptask.AppendPlans(clone)
case *ExecuteInterval:
clone := &*v
ptask.Plan = append(ptask.Plan, clone)
ptask.AppendPlans(clone)
}
}
ptask.Proxies = append(ptask.Proxies, proxy)
ptask.AppendProxies(proxy)
tasks = append(tasks, task)
}
}
@ -110,7 +110,7 @@ type ITask interface {
GetPlans() []IExecute
GetProxies() []string
SetProxies(proxies string)
AppendProxies(proxies ...string)
}
// 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 生成一个新任务
func InitTask(task ITask, Curl *curl2info.CURL, Plans ...IExecute) {
// task.Conf = NewConfig(conf)
task.setCurl(Curl)
task.appendPlans(Plans...)
task.SetCurl(Curl)
task.AppendPlans(Plans...)
}
// ExecuteOnPlan 按照计划执行任务并返回结果
func ExecuteOnPlan(task ITask) {
for _, exec := range task.getPlans() {
for _, exec := range task.GetPlans() {
if exec.TimeTo() >= 0 {
task.Execute() // 事件 在这里变化
exec.CalculateTrigger()