go 的设计上的问题, 需要改task和person结构
This commit is contained in:
parent
4877177010
commit
a0c18f4736
17
task.go
17
task.go
|
@ -9,14 +9,13 @@ import (
|
|||
|
||||
// Person 以人为单位
|
||||
type Person struct {
|
||||
Tasks *CircularLinked
|
||||
Tasks []*Task
|
||||
Conf *Config
|
||||
}
|
||||
|
||||
// NewPerson 创建一个人实例
|
||||
func NewPerson(conf string) *Person {
|
||||
person := &Person{}
|
||||
person.Tasks = NewCircularLinked()
|
||||
person.Conf = NewConfig(conf)
|
||||
|
||||
for _, scurl := range person.Conf.Curls {
|
||||
|
@ -32,7 +31,7 @@ func NewPerson(conf string) *Person {
|
|||
switch person.Conf.Mode {
|
||||
case 0:
|
||||
task.Proxies.Append(person.Conf.Proxies)
|
||||
person.Tasks.Append(task)
|
||||
person.Tasks = append(person.Tasks, task)
|
||||
case 1:
|
||||
for _, proxy := range person.Conf.Proxies {
|
||||
ncurl, err := curl2info.ParseRawCURL(scurl)
|
||||
|
@ -53,7 +52,7 @@ func NewPerson(conf string) *Person {
|
|||
}
|
||||
|
||||
ptask.Proxies.Append(proxy)
|
||||
person.Tasks.Append(ptask)
|
||||
person.Tasks = append(person.Tasks, task)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +62,13 @@ func NewPerson(conf string) *Person {
|
|||
|
||||
// Execute 人的执行所有任务
|
||||
func (person *Person) Execute() {
|
||||
for _, task := range person.Tasks {
|
||||
task.ExecuteOnPlan(task)
|
||||
}
|
||||
}
|
||||
|
||||
type ITask interface {
|
||||
Execute()
|
||||
}
|
||||
|
||||
// Task 任务
|
||||
|
@ -93,11 +98,11 @@ func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task {
|
|||
}
|
||||
|
||||
// ExecuteOnPlan 按照计划执行任务并返回结果
|
||||
func (task *Task) ExecuteOnPlan() {
|
||||
func (task *Task) ExecuteOnPlan(itask ITask) {
|
||||
for _, exec := range task.Plan.GetLoopValues() {
|
||||
iexec := exec.GetValue().(IExecute)
|
||||
if iexec.TimeTo() >= 0 {
|
||||
task.Execute()
|
||||
itask.Execute() // 事件 在这里变化
|
||||
iexec.CalculateTrigger()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,14 @@ func TestExecute(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
type Toutiao struct {
|
||||
Task
|
||||
}
|
||||
|
||||
func (tt *Toutiao) Execute() {
|
||||
|
||||
}
|
||||
|
||||
func TestExecutePlan(t *testing.T) {
|
||||
person := NewPerson("test.yaml")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user