TODO: 多态
This commit is contained in:
parent
0f8201566c
commit
9744128544
36
task.go
36
task.go
|
@ -1,6 +1,8 @@
|
||||||
package imitate
|
package imitate
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
"474420502.top/eson/curl2info"
|
"474420502.top/eson/curl2info"
|
||||||
"474420502.top/eson/requests"
|
"474420502.top/eson/requests"
|
||||||
)
|
)
|
||||||
|
@ -59,6 +61,11 @@ func NewPerson(conf string) *Person {
|
||||||
return person
|
return person
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute 人的执行所有任务
|
||||||
|
func (person *Person) Execute() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Task 任务
|
// Task 任务
|
||||||
type Task struct {
|
type Task struct {
|
||||||
Curl *curl2info.CURL
|
Curl *curl2info.CURL
|
||||||
|
@ -67,14 +74,6 @@ type Task struct {
|
||||||
Proxies *CircularLinked
|
Proxies *CircularLinked
|
||||||
}
|
}
|
||||||
|
|
||||||
// PlanResult 执行计划后返回的结果
|
|
||||||
type PlanResult struct {
|
|
||||||
OK bool
|
|
||||||
Error error
|
|
||||||
CallBack string
|
|
||||||
Response *requests.Response
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewTask 生成一个新任务
|
// NewTask 生成一个新任务
|
||||||
func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task {
|
func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task {
|
||||||
|
|
||||||
|
@ -94,27 +93,18 @@ func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteOnPlan 按照计划执行任务并返回结果
|
// ExecuteOnPlan 按照计划执行任务并返回结果
|
||||||
func (task *Task) ExecuteOnPlan() []*PlanResult {
|
func (task *Task) ExecuteOnPlan() {
|
||||||
var PRList []*PlanResult
|
|
||||||
for _, exec := range task.Plan.GetLoopValues() {
|
for _, exec := range task.Plan.GetLoopValues() {
|
||||||
pr := &PlanResult{Error: nil, OK: false}
|
|
||||||
iexec := exec.GetValue().(IExecute)
|
iexec := exec.GetValue().(IExecute)
|
||||||
if iexec.TimeTo() >= 0 {
|
if iexec.TimeTo() >= 0 {
|
||||||
resp, err := task.Execute()
|
|
||||||
if err != nil {
|
|
||||||
pr.Error = err
|
|
||||||
} else {
|
|
||||||
pr.OK = true
|
|
||||||
pr.Response = resp
|
|
||||||
}
|
|
||||||
iexec.CalculateTrigger()
|
iexec.CalculateTrigger()
|
||||||
|
task.Execute()
|
||||||
}
|
}
|
||||||
PRList = append(PRList, pr)
|
|
||||||
}
|
}
|
||||||
return PRList
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute 根据curl信息执行, TODO: 超时设置
|
// Execute 根据curl信息执行, TODO: 通用方法设置, 多太实现
|
||||||
func (task *Task) Execute() (*requests.Response, error) {
|
func (task *Task) Execute() {
|
||||||
return task.Curl.CreateWorkflow(nil).Execute()
|
resp, err := task.Curl.CreateWorkflow(nil).Execute()
|
||||||
|
log.Println(resp, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user