Commit 9e58d5ac authored by Bess严根旺's avatar Bess严根旺

全局捕获异常

parent 01859617
...@@ -7,14 +7,22 @@ import ( ...@@ -7,14 +7,22 @@ import (
service2 "doc-service/domain/repository" service2 "doc-service/domain/repository"
"doc-service/infra/db" "doc-service/infra/db"
"fmt" "fmt"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
"gitlab.galaxy-immi.com/Backend-group/go-com/third/log" "gitlab.galaxy-immi.com/Backend-group/go-com/third/log"
"os" "os"
"strings" "strings"
"time" "time"
) )
func recoverPanicToPro() {
if r := recover(); r != nil {
logger.Error("执行转换异常", r)
}
}
// 执行文件转换 // 执行文件转换
func DoAliData() { func DoAliData() {
defer recoverPanicToPro()
fmt.Println("开始刷新请求...") fmt.Println("开始刷新请求...")
ctx := context.Background() ctx := context.Background()
// 启动一个协程来执行定时任务 20秒一次 // 启动一个协程来执行定时任务 20秒一次
...@@ -49,6 +57,7 @@ func DoAliData() { ...@@ -49,6 +57,7 @@ func DoAliData() {
//获取数据 //获取数据
func toDoData(c context.Context) int8 { func toDoData(c context.Context) int8 {
defer recoverPanicToPro()
projectData, err := db.GetServerSiteMicrosDB().DocServerProject.Query().Where( projectData, err := db.GetServerSiteMicrosDB().DocServerProject.Query().Where(
docserverproject.StatusEQ(0), docserverproject.StatusEQ(0),
).All(c) ).All(c)
...@@ -78,6 +87,7 @@ func toDoData(c context.Context) int8 { ...@@ -78,6 +87,7 @@ func toDoData(c context.Context) int8 {
// 执行文件转换(脚本使用) // 执行文件转换(脚本使用)
func DoConversionToAli(c context.Context, projectId int32) bool { func DoConversionToAli(c context.Context, projectId int32) bool {
defer recoverPanicToPro()
ConversionInfo, infoErr := db.GetServerSiteMicrosDB().DocServerProject.Get(c, projectId) ConversionInfo, infoErr := db.GetServerSiteMicrosDB().DocServerProject.Get(c, projectId)
if infoErr != nil { if infoErr != nil {
return false return false
......
...@@ -15,8 +15,15 @@ import ( ...@@ -15,8 +15,15 @@ import (
"time" "time"
) )
func recoverPanicGetPro() {
if r := recover(); r != nil {
logger.Error("获取转换进度异常", r)
}
}
// 获取转换进度 // 获取转换进度
func GetConvert() { func GetConvert() {
defer recoverPanicGetPro()
fmt.Println("开始获取进度...") fmt.Println("开始获取进度...")
ctx := context.Background() ctx := context.Background()
// 启动一个协程来执行定时任务 // 启动一个协程来执行定时任务
...@@ -49,6 +56,8 @@ func GetConvert() { ...@@ -49,6 +56,8 @@ func GetConvert() {
} }
func getConvertDoData(ctx context.Context) int8 { func getConvertDoData(ctx context.Context) int8 {
defer recoverPanicGetPro()
list, err := db.GetServerSiteMicrosDB().DocServerProject.Query().Where( list, err := db.GetServerSiteMicrosDB().DocServerProject.Query().Where(
docserverproject.StatusEQ(1), docserverproject.StatusEQ(1),
).All(ctx) ).All(ctx)
...@@ -76,6 +85,8 @@ func getConvertDoData(ctx context.Context) int8 { ...@@ -76,6 +85,8 @@ func getConvertDoData(ctx context.Context) int8 {
} }
func GetProjectInfo(c context.Context, projectId int32) int8 { func GetProjectInfo(c context.Context, projectId int32) int8 {
defer recoverPanicGetPro()
projectInfo, infoErr := db.GetServerSiteMicrosDB().DocServerProject.Get(c, projectId) projectInfo, infoErr := db.GetServerSiteMicrosDB().DocServerProject.Get(c, projectId)
if infoErr != nil { if infoErr != nil {
return 0 return 0
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
service "doc-service/domain/repository" service "doc-service/domain/repository"
"doc-service/infra/db" "doc-service/infra/db"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
pb "gitlab.galaxy-immi.com/Backend-group/proto/pb/docservice" pb "gitlab.galaxy-immi.com/Backend-group/proto/pb/docservice"
"strings" "strings"
"time" "time"
...@@ -13,9 +14,16 @@ type DocServiceService struct { ...@@ -13,9 +14,16 @@ type DocServiceService struct {
pb.UnimplementedDocServiceServiceServer pb.UnimplementedDocServiceServiceServer
} }
func recoverPanic() {
if r := recover(); r != nil {
logger.Error("异常了", r)
}
}
// 发起文件转换 // 发起文件转换
func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversionRequest) (resp *pb.DoConversionResponse, err error) { func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversionRequest) (resp *pb.DoConversionResponse, err error) {
defer recoverPanic()
resp = &pb.DoConversionResponse{} resp = &pb.DoConversionResponse{}
request := &service.DoConversionRequest{ request := &service.DoConversionRequest{
ProjectName: req.ProjectName, ProjectName: req.ProjectName,
...@@ -88,6 +96,7 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi ...@@ -88,6 +96,7 @@ func (doc *DocServiceService) DoConversion(c context.Context, req *pb.DoConversi
// 获取转换结果 // 获取转换结果
func (doc *DocServiceService) GetProjectInfo(c context.Context, req *pb.GetProjectRequest) (resp *pb.GetProjectResponse, err error) { func (doc *DocServiceService) GetProjectInfo(c context.Context, req *pb.GetProjectRequest) (resp *pb.GetProjectResponse, err error) {
defer recoverPanic()
resp = &pb.GetProjectResponse{} resp = &pb.GetProjectResponse{}
ConversionInfo := &pb.DoConversionInfo{} ConversionInfo := &pb.DoConversionInfo{}
......
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 to comment