重构通道管理逻辑,支持通过任务删除不同类型通道;引入 Asynq 处理异步任务;更新数据库结构以支持通道类型区分
This commit is contained in:
22
web/globals/asynq.go
Normal file
22
web/globals/asynq.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package globals
|
||||
|
||||
import (
|
||||
"github.com/hibiken/asynq"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
var Asynq *asynq.Client
|
||||
|
||||
func InitAsynq() {
|
||||
var client = asynq.NewClientFromRedisClient(Redis)
|
||||
Asynq = client
|
||||
}
|
||||
|
||||
func CloseAsynq() {
|
||||
if Asynq != nil {
|
||||
err := Asynq.Close()
|
||||
if err != nil {
|
||||
slog.Error("关闭 Asynq 客户端失败", "error", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,5 @@ func Init() {
|
||||
initRedis()
|
||||
initOrm()
|
||||
initProxy()
|
||||
InitAsynq()
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -42,6 +43,7 @@ func (p *ProxyClient) Permit(host string, secret string, config []*ProxyPermitCo
|
||||
return fmt.Errorf("加密请求失败: %w", err)
|
||||
}
|
||||
|
||||
//goland:noinspection HttpUrlsUsage
|
||||
resp, err := http.Post(
|
||||
fmt.Sprintf("http://%s:8848%s", host, PermitEndpoint),
|
||||
"application/json",
|
||||
@@ -50,7 +52,9 @@ func (p *ProxyClient) Permit(host string, secret string, config []*ProxyPermitCo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer func(Body io.ReadCloser) {
|
||||
_ = Body.Close()
|
||||
}(resp.Body)
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("配置端口许可失败: %s", resp.Status)
|
||||
|
||||
Reference in New Issue
Block a user