mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-11 13:53:35 +08:00
用户端刷新预热缓存超过5分钟自动认为已完成
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HTTPCacheTaskService 缓存任务管理
|
// HTTPCacheTaskService 缓存任务管理
|
||||||
@@ -196,6 +197,8 @@ func (this *HTTPCacheTaskService) ListHTTPCacheTasks(ctx context.Context, req *p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isFromUser = userId > 0
|
||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
tasks, err := models.SharedHTTPCacheTaskDAO.ListTasks(tx, userId, req.Offset, req.Size)
|
tasks, err := models.SharedHTTPCacheTaskDAO.ListTasks(tx, userId, req.Offset, req.Size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -232,6 +235,14 @@ func (this *HTTPCacheTaskService) ListHTTPCacheTasks(ctx context.Context, req *p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对用户而言,超过Ns自动认为已完成
|
||||||
|
const timeoutSeconds = 300
|
||||||
|
if isFromUser && !task.IsDone && time.Now().Unix()-int64(task.CreatedAt) > timeoutSeconds {
|
||||||
|
task.IsOk = true
|
||||||
|
task.IsDone = true
|
||||||
|
task.DoneAt = task.CreatedAt + timeoutSeconds
|
||||||
|
}
|
||||||
|
|
||||||
pbTasks = append(pbTasks, &pb.HTTPCacheTask{
|
pbTasks = append(pbTasks, &pb.HTTPCacheTask{
|
||||||
Id: taskId,
|
Id: taskId,
|
||||||
UserId: int64(task.UserId),
|
UserId: int64(task.UserId),
|
||||||
@@ -257,6 +268,7 @@ func (this *HTTPCacheTaskService) FindEnabledHTTPCacheTask(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
var isFromUser = userId > 0
|
||||||
|
|
||||||
var tx = this.NullTx()
|
var tx = this.NullTx()
|
||||||
if userId > 0 {
|
if userId > 0 {
|
||||||
@@ -274,6 +286,14 @@ func (this *HTTPCacheTaskService) FindEnabledHTTPCacheTask(ctx context.Context,
|
|||||||
return &pb.FindEnabledHTTPCacheTaskResponse{HttpCacheTask: nil}, nil
|
return &pb.FindEnabledHTTPCacheTaskResponse{HttpCacheTask: nil}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 对用户而言,超过Ns自动认为已完成
|
||||||
|
const timeoutSeconds = 300
|
||||||
|
if isFromUser && !task.IsDone && time.Now().Unix()-int64(task.CreatedAt) > timeoutSeconds {
|
||||||
|
task.IsOk = true
|
||||||
|
task.IsDone = true
|
||||||
|
task.DoneAt = task.CreatedAt + timeoutSeconds
|
||||||
|
}
|
||||||
|
|
||||||
// 查询所属用户
|
// 查询所属用户
|
||||||
var pbUser = &pb.User{}
|
var pbUser = &pb.User{}
|
||||||
if task.UserId > 0 {
|
if task.UserId > 0 {
|
||||||
@@ -306,6 +326,11 @@ func (this *HTTPCacheTaskService) FindEnabledHTTPCacheTask(ctx context.Context,
|
|||||||
}
|
}
|
||||||
var pbKeys = []*pb.HTTPCacheTaskKey{}
|
var pbKeys = []*pb.HTTPCacheTaskKey{}
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
|
// 对用户而言,超过Ns自动认为已完成
|
||||||
|
if isFromUser && task.IsDone {
|
||||||
|
key.IsDone = true
|
||||||
|
key.Errors = nil
|
||||||
|
}
|
||||||
|
|
||||||
pbKeys = append(pbKeys, &pb.HTTPCacheTaskKey{
|
pbKeys = append(pbKeys, &pb.HTTPCacheTaskKey{
|
||||||
Id: int64(key.Id),
|
Id: int64(key.Id),
|
||||||
|
|||||||
Reference in New Issue
Block a user