From 7f42baaa235a38101bbbf5b788fdc06dba29cceb Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sat, 22 Dec 2018 02:11:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=86=8DTimeUp=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=89=8D=E7=9A=84NextTime=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- person.go | 5 ++++- structure.go | 1 - structure_test.go | 1 - task.go | 32 +++++++++++++++++++++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) delete mode 100644 structure.go delete mode 100644 structure_test.go diff --git a/person.go b/person.go index 6265b8e..3416720 100644 --- a/person.go +++ b/person.go @@ -6,6 +6,8 @@ import ( "reflect" "time" + "474420502.top/eson/crontabex" + "474420502.top/eson/structure/circular_linked" "474420502.top/eson/curl2info" @@ -17,7 +19,7 @@ type ITask interface { Init() SetCrontab(cron string) - SetLastStatus(status bool) + GetCrontab() *crontab.Crontab SetName(name string) GetName() string @@ -172,6 +174,7 @@ func ExecuteOnPlan(task ITask, result chan string) { taskname := task.GetName() urlname := task.GetCurl().Name + task.NextTime() // 必须调用NextTime 才能触发TimeUp for { interval := time.Second * 2 if task.TimeUp() { diff --git a/structure.go b/structure.go deleted file mode 100644 index 47efed7..0000000 --- a/structure.go +++ /dev/null @@ -1 +0,0 @@ -package imitater diff --git a/structure_test.go b/structure_test.go deleted file mode 100644 index 47efed7..0000000 --- a/structure_test.go +++ /dev/null @@ -1 +0,0 @@ -package imitater diff --git a/task.go b/task.go index b0d5114..592cb89 100644 --- a/task.go +++ b/task.go @@ -1,9 +1,14 @@ package imitater import ( + "encoding/json" + "log" "time" + "474420502.top/test/logdb" + "474420502.top/eson/structure/circular_linked" + uuid "github.com/satori/go.uuid" "474420502.top/eson/crontabex" "474420502.top/eson/curl2info" @@ -73,9 +78,9 @@ func (task *Task) SetCrontab(cron string) { task.crontab = crontab.NewCrontab(cron) } -// SetLastStatus 设置上次执行的状态 成功true 失败false -func (task *Task) SetLastStatus(status bool) { - task.crontab.SetStatus(status) +// GetCrontab 设置上次执行的状态 成功true 失败false +func (task *Task) GetCrontab() *crontab.Crontab { + return task.crontab } // TimeUp 判断是否到了下次执行的时间点 @@ -125,3 +130,24 @@ func (task *Task) Session() *requests.Session { return task.session } + +// ADDataSave 公众存储数据的接口 +func ADDataSave(task ITask, db *logdb.LogDB, adDataList []string) { + if len(adDataList) != 0 { + adDataStore, err := json.Marshal(adDataList) + if err != nil { + panic(err) + } + // log.Println(string(adDataStore)) + uid, err := uuid.NewV4() + if err != nil { + panic(err) + } + + log.Println(uid.String()) + + adinfo := task.GetADInfo() + db.ADInsert(uid.String(), adinfo.Device, adinfo.Platform, adinfo.AreaCC, "", + string(adDataStore), adinfo.SpiderID, adinfo.Channel, adinfo.Media, adinfo.CatchAccountID, 0, adinfo.Priority, time.Now()) + } +}