mirror of
https://gitee.com/blackfox/geekai.git
synced 2024-12-04 05:09:12 +08:00
opt: add lock for mj task callback
This commit is contained in:
parent
b676f80110
commit
18c033d57f
@ -13,6 +13,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -41,6 +42,7 @@ type MidJourneyHandler struct {
|
||||
db *gorm.DB
|
||||
mjFunc function.FuncMidJourney
|
||||
uploaderManager *oss.UploaderManager
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func NewMidJourneyHandler(
|
||||
@ -53,6 +55,7 @@ func NewMidJourneyHandler(
|
||||
leveldb: leveldb,
|
||||
db: db,
|
||||
uploaderManager: manager,
|
||||
lock: sync.Mutex{},
|
||||
mjFunc: functions[types.FuncMidJourney].(function.FuncMidJourney)}
|
||||
h.App = app
|
||||
return &h
|
||||
@ -80,7 +83,9 @@ func (h *MidJourneyHandler) Notify(c *gin.Context) {
|
||||
}
|
||||
|
||||
logger.Debugf("收到 MidJourney 回调请求:%+v", data)
|
||||
|
||||
h.lock.Lock()
|
||||
defer h.lock.Unlock()
|
||||
|
||||
// the job is saved
|
||||
var job model.MidJourneyJob
|
||||
res := h.db.Where("message_id = ?", data.MessageId).First(&job)
|
||||
|
Loading…
Reference in New Issue
Block a user