fix: 在 PullCodeHandler、BuildBotHandler 和 RestartBotHandler 中使用 TryLock 以避免并发请求导致的错误响应
This commit is contained in:
parent
d4038a568e
commit
8759a2ce65
@ -173,7 +173,10 @@ func buildBot() error {
|
||||
}
|
||||
|
||||
func PullCodeHandler(c *gin.Context) {
|
||||
stuffMutex.Lock()
|
||||
if !stuffMutex.TryLock() {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "有其他请求正在运行,请稍后再试"})
|
||||
return
|
||||
}
|
||||
defer stuffMutex.Unlock()
|
||||
err := util.GitPull()
|
||||
log.Println("拉取代码...")
|
||||
@ -186,7 +189,10 @@ func PullCodeHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
func BuildBotHandler(c *gin.Context) {
|
||||
stuffMutex.Lock()
|
||||
if !stuffMutex.TryLock() {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "有其他请求正在运行,请稍后再试"})
|
||||
return
|
||||
}
|
||||
defer stuffMutex.Unlock()
|
||||
err := buildBot()
|
||||
log.Println("构建程序...")
|
||||
@ -204,7 +210,10 @@ func RestartBotHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
stuffMutex.Lock()
|
||||
if !stuffMutex.TryLock() {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "有其他请求正在运行,请稍后再试"})
|
||||
return
|
||||
}
|
||||
defer stuffMutex.Unlock()
|
||||
err := restartProgram()
|
||||
log.Println("重启程序...")
|
||||
|
Loading…
x
Reference in New Issue
Block a user