feat(log): add the log of label,tid
This commit is contained in:
parent
741cf154fe
commit
4a60282e7e
|
@ -19,7 +19,7 @@ func CallbackServer(task *Task) {
|
||||||
defer task.lock.Unlock()
|
defer task.lock.Unlock()
|
||||||
if callback, ok := task.data["callback"]; ok {
|
if callback, ok := task.data["callback"]; ok {
|
||||||
cburl := callback.(string)
|
cburl := callback.(string)
|
||||||
log.Println(cburl)
|
// log.Println(cburl)
|
||||||
_, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute()
|
_, err := requests.NewSession().Post(cburl).SetBodyAuto(task.data, requests.TypeFormData).Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bwmarrin/snowflake"
|
"github.com/bwmarrin/snowflake"
|
||||||
|
@ -70,9 +69,12 @@ func PutTask(c *gin.Context) {
|
||||||
data := NewTask()
|
data := NewTask()
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
tid := snowNode.Generate().Base64()
|
tid := snowNode.Generate().Base64()
|
||||||
|
label := c.PostForm("label")
|
||||||
data.Store("taskid", tid)
|
data.Store("taskid", tid)
|
||||||
data.Store("url", u)
|
data.Store("url", u)
|
||||||
data.Store("ts", now.UnixNano())
|
data.Store("ts", now.UnixNano())
|
||||||
|
data.Store("label", label)
|
||||||
|
|
||||||
if callback := c.PostForm("callback"); callback != "" {
|
if callback := c.PostForm("callback"); callback != "" {
|
||||||
data.Store("callback", callback)
|
data.Store("callback", callback)
|
||||||
}
|
}
|
||||||
|
@ -88,10 +90,7 @@ func PutTask(c *gin.Context) {
|
||||||
|
|
||||||
// ContentTask 把一条任务放入队列
|
// ContentTask 把一条任务放入队列
|
||||||
func ContentTask(c *gin.Context) {
|
func ContentTask(c *gin.Context) {
|
||||||
pc, _, _, _ := runtime.Caller(0)
|
|
||||||
log.Println(runtime.FuncForPC(pc).Name())
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
tid, ok := c.GetPostForm("taskid")
|
tid, ok := c.GetPostForm("taskid")
|
||||||
if !ok {
|
if !ok {
|
||||||
c.JSON(http.StatusOK, Response{Code: 404, Message: "taskid is not set"})
|
c.JSON(http.StatusOK, Response{Code: 404, Message: "taskid is not set"})
|
||||||
|
@ -104,7 +103,10 @@ func ContentTask(c *gin.Context) {
|
||||||
task.Store("status", "ready")
|
task.Store("status", "ready")
|
||||||
readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化
|
readyQueue.Push(tid, task) // 进入回调发送队列.TODO: 内容持久化
|
||||||
c.JSON(200, Response{Code: 200, Data: task})
|
c.JSON(200, Response{Code: 200, Data: task})
|
||||||
log.Println("start callback")
|
// log.Println("start callback")
|
||||||
|
if label, ok := task.Load("label"); ok {
|
||||||
|
log.Println(label.(string), tid)
|
||||||
|
}
|
||||||
go CallbackServer(task)
|
go CallbackServer(task)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
12
proxyserver/utils.go
Normal file
12
proxyserver/utils.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 打印当前函数名
|
||||||
|
func logFunctionName() {
|
||||||
|
pc, _, _, _ := runtime.Caller(0)
|
||||||
|
log.Println(runtime.FuncForPC(pc).Name())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user