添加ADInfo的方法到任务结构
This commit is contained in:
parent
8aa804db7f
commit
c3de0210c6
|
@ -10,10 +10,9 @@ import (
|
|||
func TestNewYaml(t *testing.T) {
|
||||
test := NewConfig("test.yaml")
|
||||
data := spew.Sdump(test)
|
||||
if !(regexp.MustCompile(`Device: \(string\) \(len=12\) "eson-OnePlus"`).MatchString(data) && regexp.MustCompile(`http://is.snssdk.com/2/article/information/v24/\?`).MatchString(data)) {
|
||||
if !regexp.MustCompile(`Device: \(string\) \(len=12\) "eson-OnePlus"`).MatchString(data) {
|
||||
t.Error(data)
|
||||
}
|
||||
t.Error(data)
|
||||
}
|
||||
|
||||
func TestCase(t *testing.T) {
|
||||
|
|
|
@ -28,6 +28,9 @@ type ITask interface {
|
|||
GetProxies() *clinked.CircularLinked
|
||||
AddProxies(proxy string)
|
||||
|
||||
SetADInfo(adinfo ADInfo)
|
||||
GetADInfo() *ADInfo
|
||||
|
||||
TimeUp() bool
|
||||
NextTime() time.Time
|
||||
}
|
||||
|
@ -95,6 +98,7 @@ func splitTasks(conf *Config) []ITask {
|
|||
switch conf.Mode {
|
||||
case 0:
|
||||
initTask(conf, task, curl)
|
||||
// 初始化代理
|
||||
if proxies != nil {
|
||||
for _, cnode := range proxies.GetLoopValues() {
|
||||
proxy := cnode.GetValue().(string)
|
||||
|
@ -143,7 +147,6 @@ func (person *Person) Execute() {
|
|||
for t := range result {
|
||||
log.Println(t)
|
||||
taskLen--
|
||||
|
||||
if taskLen <= 0 {
|
||||
close(result)
|
||||
}
|
||||
|
@ -155,7 +158,6 @@ func (person *Person) Execute() {
|
|||
|
||||
// initTask 生成一个新任务
|
||||
func initTask(conf *Config, task ITask, curl *curl2info.CURL) {
|
||||
task.Init()
|
||||
|
||||
if curl.Crontab != "" {
|
||||
task.SetCrontab(curl.Crontab)
|
||||
|
@ -163,7 +165,10 @@ func initTask(conf *Config, task ITask, curl *curl2info.CURL) {
|
|||
task.SetCrontab(conf.Crontab)
|
||||
}
|
||||
|
||||
task.SetADInfo(conf.ADInfo)
|
||||
task.SetCurl(curl)
|
||||
|
||||
task.Init()
|
||||
}
|
||||
|
||||
// ExecuteOnPlan 按照计划执行任务并返回结果
|
||||
|
|
11
task.go
11
task.go
|
@ -20,6 +20,7 @@ type Task struct {
|
|||
workflow *requests.Workflow
|
||||
session *requests.Session
|
||||
proxies clinked.CircularLinked
|
||||
adinfo ADInfo
|
||||
}
|
||||
|
||||
// Init 初始化, 会被Persion默认调用, 可以用来覆盖
|
||||
|
@ -57,6 +58,16 @@ func (task *Task) GetProxies() *clinked.CircularLinked {
|
|||
return &task.proxies
|
||||
}
|
||||
|
||||
// SetADInfo 设置广告的信息结构
|
||||
func (task *Task) SetADInfo(adinfo ADInfo) {
|
||||
task.adinfo = adinfo
|
||||
}
|
||||
|
||||
// GetADInfo 获取广告的信息结构
|
||||
func (task *Task) GetADInfo() *ADInfo {
|
||||
return &task.adinfo
|
||||
}
|
||||
|
||||
// SetCrontab 设置crontab的控制规则字符串
|
||||
func (task *Task) SetCrontab(cron string) {
|
||||
task.crontab = crontab.NewCrontab(cron)
|
||||
|
|
11
task_test.go
11
task_test.go
|
@ -15,11 +15,9 @@ func TestExecute(t *testing.T) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
resp, err := u.CreateWorkflow(nil).Execute()
|
||||
_, err = u.CreateWorkflow(nil).Execute()
|
||||
if err != nil {
|
||||
t.Error("TestExecute")
|
||||
} else {
|
||||
log.Println(resp.Content())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +27,11 @@ type Toutiao struct {
|
|||
|
||||
func (tt *Toutiao) Execute(data interface{}) ITask {
|
||||
resp, err := tt.Request()
|
||||
log.Println(resp.Content()[0:20], err)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
log.Println(resp.Content()[0:20], err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -40,7 +42,6 @@ func TestExecutePlan(t *testing.T) {
|
|||
person.Config("test.yaml")
|
||||
person.Execute()
|
||||
|
||||
t.Error("")
|
||||
// for _, task := range person.Tasks.GetLoopValues() {
|
||||
// task.GetValue().(*Task).ExecuteOnPlan()
|
||||
// }
|
||||
|
|
Loading…
Reference in New Issue
Block a user