Skip to content
Snippets Groups Projects
Unverified Commit c0e4c587 authored by dd-Rebecca's avatar dd-Rebecca Committed by GitHub
Browse files

fix(eventbus): eventbus lock with nowait (#20)


Co-authored-by: default avatardaijiaqi <daijiaqi@bytedance.com>
parent 4e7fc05f
No related branches found
No related tags found
No related merge requests found
...@@ -325,7 +325,7 @@ func (e *EventBus) initService() error { ...@@ -325,7 +325,7 @@ func (e *EventBus) initService() error {
func (e *EventBus) lockService(tx *gorm.DB) (*ServicePO, error) { func (e *EventBus) lockService(tx *gorm.DB) (*ServicePO, error) {
service := &ServicePO{} service := &ServicePO{}
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}). if err := tx.Clauses(clause.Locking{Strength: "UPDATE", Options: "NOWAIT"}).
Where("name = ?", e.serviceName). Where("name = ?", e.serviceName).
First(service).Error; err != nil { First(service).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
...@@ -504,7 +504,7 @@ func (e *EventBus) handleTransactions() error { ...@@ -504,7 +504,7 @@ func (e *EventBus) handleTransactions() error {
ctx := e.ctxWithDB(context.TODO(), db) ctx := e.ctxWithDB(context.TODO(), db)
trans := make([]*Transaction, 0) trans := make([]*Transaction, 0)
if err := db.Clauses(clause.Locking{Strength: "UPDATE"}).Where( if err := db.Clauses(clause.Locking{Strength: "UPDATE", Options: "NOWAIT"}).Where(
"service = ? and due_time < ?", e.serviceName, time.Now(), "service = ? and due_time < ?", e.serviceName, time.Now(),
).Find(&trans).Error; err != nil { ).Find(&trans).Error; err != nil {
return err return err
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment