mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-04-21 09:19:32 -05:00
1407594902
* fix: move rate limited queue items off the main queue * preserve FIFO behavior on queues * fix unit tests, address pr comments * fix: generated * rename table
68 lines
1.0 KiB
Go
68 lines
1.0 KiB
Go
package v1
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type debugMu struct {
|
|
l *zerolog.Logger
|
|
}
|
|
|
|
func (d debugMu) print(start time.Time) {
|
|
if since := time.Since(start); since > 50*time.Millisecond {
|
|
// get the line number of the caller
|
|
_, file, line, ok := runtime.Caller(2)
|
|
|
|
caller := "unknown"
|
|
if ok {
|
|
caller = fmt.Sprintf("%s:%d", file, line)
|
|
}
|
|
|
|
d.l.Warn().Dur("duration", since).Msgf("long lock %s", caller)
|
|
}
|
|
}
|
|
|
|
type mutex struct {
|
|
*sync.Mutex
|
|
debugMu
|
|
}
|
|
|
|
func newMu(l *zerolog.Logger) mutex {
|
|
return mutex{
|
|
Mutex: &sync.Mutex{},
|
|
debugMu: debugMu{l: l},
|
|
}
|
|
}
|
|
|
|
func (m mutex) Lock() {
|
|
defer m.debugMu.print(time.Now())
|
|
m.Mutex.Lock()
|
|
}
|
|
|
|
type rwMutex struct {
|
|
*sync.RWMutex
|
|
debugMu
|
|
}
|
|
|
|
func newRWMu(l *zerolog.Logger) rwMutex {
|
|
return rwMutex{
|
|
RWMutex: &sync.RWMutex{},
|
|
debugMu: debugMu{l: l},
|
|
}
|
|
}
|
|
|
|
func (m rwMutex) Lock() {
|
|
defer m.debugMu.print(time.Now())
|
|
m.RWMutex.Lock()
|
|
}
|
|
|
|
func (m rwMutex) RLock() {
|
|
defer m.debugMu.print(time.Now())
|
|
m.RWMutex.RLock()
|
|
}
|