Commit 545a2041 by 朱继来

调整任务脚本

parent c6bad599
...@@ -8,7 +8,6 @@ package main ...@@ -8,7 +8,6 @@ package main
*/ */
import ( import (
"crm-server/cmd/task/common" "crm-server/cmd/task/common"
_"crm-server/cmd/task/common"
"crm-server/configs" "crm-server/configs"
"crm-server/internal/dao" "crm-server/internal/dao"
"crm-server/internal/model" "crm-server/internal/model"
...@@ -17,9 +16,7 @@ import ( ...@@ -17,9 +16,7 @@ import (
"fmt" "fmt"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/robfig/cron"
) )
// 日志目录 // 日志目录
...@@ -42,25 +39,28 @@ func main () { ...@@ -42,25 +39,28 @@ func main () {
// 查看未下单任务是否开启 // 查看未下单任务是否开启
task_setup := common.GetTaskSetup(4) task_setup := common.GetTaskSetup(4)
task_setup_details := common.GetTaskSetupDetails(task_setup.Id) //task_setup_details := common.GetTaskSetupDetails(task_setup.Id)
var cron_time string //var cron_time string
if task_setup_details.TaskExecTimeType == 1 { //if task_setup_details.TaskExecTimeType == 1 {
str := strings.Split(task_setup_details.TsakExecTime, ":") // str := strings.Split(task_setup_details.TsakExecTime, ":")
cron_time = "0 " + str[1] + " " + str[0] + " * * *" // cron_time = "0 " + str[1] + " " + str[0] + " * * *"
} else { //} else {
cron_time = "0 " + task_setup_details.TsakExecTime + " * * * *" // cron_time = "0 " + task_setup_details.TsakExecTime + " * * * *"
} //}
//
c := cron.New() //c := cron.New()
c.AddFunc(cron_time, func() { //c.AddFunc(cron_time, func() {
fmt.Println(cron_time) // fmt.Println(cron_time)
go setFindGoods(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree) // go setFindGoods(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree)
}) //})
c.Start() //c.Start()
defer c.Stop() //defer c.Stop()
select { //select {
} //}
setFindGoods(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree)
fmt.Println("任务执行完成")
} }
func setFindGoods(status, task_id, task_type, task_display_degree int) { func setFindGoods(status, task_id, task_type, task_display_degree int) {
...@@ -70,7 +70,7 @@ func setFindGoods(status, task_id, task_type, task_display_degree int) { ...@@ -70,7 +70,7 @@ func setFindGoods(status, task_id, task_type, task_display_degree int) {
db := dao.GetNewDb() db := dao.GetNewDb()
// 获取快速找料的用户 // 获取快速找料的用户
row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 7, 0) row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc", 7, 0)
defer db.Close() defer db.Close()
if err != nil { if err != nil {
......
...@@ -38,21 +38,24 @@ func main () { ...@@ -38,21 +38,24 @@ func main () {
task_setup_details := common.GetTaskSetupDetails(task_setup.Id) task_setup_details := common.GetTaskSetupDetails(task_setup.Id)
// 定时执行 // 定时执行
task_exec_time, _ := strconv.Atoi(task_setup_details.TsakExecTime) //task_exec_time, _ := strconv.Atoi(task_setup_details.TsakExecTime)
ticker := time.NewTicker(time.Minute * time.Duration(task_exec_time)) //ticker := time.NewTicker(time.Minute * time.Duration(task_exec_time))
//ticker := time.NewTicker(time.Second * 5) //ticker := time.NewTicker(time.Second * 5)
for { //for {
select { // select {
case <- ticker.C: // case <- ticker.C:
fmt.Println("ticker...") // fmt.Println("ticker...")
//
go setHaveOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime) // go setHaveOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime)
default: // default:
time.Sleep(time.Microsecond * 100) // time.Sleep(time.Microsecond * 100)
} // }
} //}
setHaveOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime)
fmt.Println("任务执行完成")
} }
func setHaveOrderTask(status, task_id, task_type, task_display_degree int, task_end_time int64) { func setHaveOrderTask(status, task_id, task_type, task_display_degree int, task_end_time int64) {
......
...@@ -14,9 +14,7 @@ import ( ...@@ -14,9 +14,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"github.com/ichunt2019/logger" "github.com/ichunt2019/logger"
"github.com/robfig/cron"
"strconv" "strconv"
"strings"
"time" "time"
) )
...@@ -40,25 +38,28 @@ func main () { ...@@ -40,25 +38,28 @@ func main () {
// 查看未下单任务是否开启 // 查看未下单任务是否开启
task_setup := common.GetTaskSetup(5) task_setup := common.GetTaskSetup(5)
task_setup_details := common.GetTaskSetupDetails(task_setup.Id) //task_setup_details := common.GetTaskSetupDetails(task_setup.Id)
//
var cron_time string //var cron_time string
if task_setup_details.TaskExecTimeType == 1 { //if task_setup_details.TaskExecTimeType == 1 {
str := strings.Split(task_setup_details.TsakExecTime, ":") // str := strings.Split(task_setup_details.TsakExecTime, ":")
cron_time = "0 " + str[1] + " " + str[0] + " * * *" // cron_time = "0 " + str[1] + " " + str[0] + " * * *"
} else { //} else {
cron_time = "0 " + task_setup_details.TsakExecTime + " * * * *" // cron_time = "0 " + task_setup_details.TsakExecTime + " * * * *"
} //}
//
c := cron.New() //c := cron.New()
c.AddFunc(cron_time, func() { //c.AddFunc(cron_time, func() {
fmt.Println(cron_time) // fmt.Println(cron_time)
go setMultiSearch(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree) // go setMultiSearch(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree)
}) //})
c.Start() //c.Start()
defer c.Stop() //defer c.Stop()
select { //select {
} //}
setMultiSearch(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree)
fmt.Println("任务执行完成")
} }
func setMultiSearch(status, task_id, task_type, task_display_degree int) { func setMultiSearch(status, task_id, task_type, task_display_degree int) {
...@@ -68,7 +69,7 @@ func setMultiSearch(status, task_id, task_type, task_display_degree int) { ...@@ -68,7 +69,7 @@ func setMultiSearch(status, task_id, task_type, task_display_degree int) {
db := dao.GetNewDb() db := dao.GetNewDb()
// 获取快速找料的用户 // 获取快速找料的用户
row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc limit 100", 6, 0) row, err := db.Queryx("select * from lie_feedback where type = ? and is_add_task = ? order by id desc", 6, 0)
defer db.Close() defer db.Close()
if err != nil { if err != nil {
......
...@@ -38,21 +38,24 @@ func main () { ...@@ -38,21 +38,24 @@ func main () {
task_setup_details := common.GetTaskSetupDetails(task_setup.Id) task_setup_details := common.GetTaskSetupDetails(task_setup.Id)
// 定时执行 // 定时执行
task_exec_time, _ := strconv.Atoi(task_setup_details.TsakExecTime) //task_exec_time, _ := strconv.Atoi(task_setup_details.TsakExecTime)
ticker := time.NewTicker(time.Minute * time.Duration(task_exec_time)) //ticker := time.NewTicker(time.Minute * time.Duration(task_exec_time))
//ticker := time.NewTicker(time.Second * 3) //ticker := time.NewTicker(time.Second * 3)
for { //for {
select { // select {
case <- ticker.C: // case <- ticker.C:
fmt.Println("ticker...") // fmt.Println("ticker...")
//
go setNoOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime) // go setNoOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime)
default: // default:
time.Sleep(time.Microsecond * 100) // time.Sleep(time.Microsecond * 100)
} // }
} //}
setNoOrderTask(task_setup.Status, task_setup.Id, task_setup.TaskType, task_setup.TaskDisplayDegree, task_setup_details.TaskEndTime)
fmt.Println("任务执行完成")
} }
func setNoOrderTask(status, task_id, task_type, task_display_degree int, task_end_time int64) { func setNoOrderTask(status, task_id, task_type, task_display_degree int, task_end_time int64) {
......
...@@ -51,8 +51,9 @@ func main() { ...@@ -51,8 +51,9 @@ func main() {
} }
func updateOverTime() { func updateOverTime() {
db := dao.GetDb() db := dao.GetNewDb()
row, err := db.Queryx("select * from lie_task_info where status = 1 limit 100") // 查询有截止时间且待处理的任务记录(1-领取分配, 2-未成交释放(30), 3-已成交释放(180))
row, err := db.Queryx("select * from lie_task_info where task_type in (1, 2, 3) and status = 1 limit 10")
defer db.Close() defer db.Close()
if err != nil { if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment