package main
|
|
import (
|
"data_msg_push_server/config"
|
"data_msg_push_server/service"
|
"flag"
|
"fmt"
|
"time"
|
)
|
|
var env = flag.String("config", "config", "read storage info")
|
|
func init() {
|
config.Init(*env)
|
}
|
|
func main() {
|
fmt.Println("hello!!!")
|
done := make(chan bool)
|
|
go runEvery(done)
|
//result,err := service.GetData()
|
//if err != nil {
|
// fmt.Println(err)
|
//}
|
//if result != nil{
|
//
|
//}
|
<-done
|
fmt.Println("程序已退出")
|
//fmt.Println(res)
|
//fmt.Println(err)
|
|
}
|
|
func runEvery(done chan<- bool){
|
ticker := time.NewTicker(10 * time.Second)
|
defer ticker.Stop()
|
|
for{
|
select {
|
case <-ticker.C:
|
fmt.Println("开始执行函数。。。")
|
doServer()
|
fmt.Println("本次执行完毕, 当前所有数据已发送!!!")
|
time.Sleep(10 * time.Second)
|
}
|
}
|
}
|
|
func doServer() {
|
total := 0
|
for {
|
t,err := service.GetTotal()
|
if err != nil {
|
fmt.Println(err)
|
}
|
total = t
|
fmt.Println("未发送的数据总量:", total)
|
if total == 0 {
|
break
|
} else {
|
for {
|
connectStatus := service.ConnectControl()
|
fmt.Println("connectStatus: ",connectStatus)
|
if connectStatus == true {
|
url := config.ServUrls.ServerUrl
|
result, err1 := service.GetData()
|
if err1 != nil {
|
fmt.Println(err1)
|
}
|
id, errs2 := service.SendData(result, url)
|
fmt.Println("data id is: ",id)
|
if errs2 == nil{
|
//delStatus := service.DeleteData(id)
|
markStatus := service.MarkData(id)
|
fmt.Println(markStatus)
|
}
|
break
|
} else {
|
fmt.Println("5秒后尝试重新连接。。。")
|
time.Sleep(5 * time.Second)
|
}
|
}
|
}
|
}
|
}
|