1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +00:00

Tentative fix for mutex killing strimertul

This commit is contained in:
Ash Keel 2022-02-08 15:13:13 +01:00
parent 8ba3c3fbc0
commit f3f85622bd
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
2 changed files with 62 additions and 57 deletions

View file

@ -117,7 +117,8 @@ func Register(manager *modules.Manager) error {
} }
func (m *Manager) Status() modules.ModuleStatus { func (m *Manager) Status() modules.ModuleStatus {
if !m.config.Enabled { config := m.Config()
if !config.Enabled {
return modules.ModuleStatus{ return modules.ModuleStatus{
Enabled: false, Enabled: false,
} }

View file

@ -15,8 +15,8 @@ import (
) )
func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) { func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
config := loyalty.Config()
b.Loyalty = loyalty b.Loyalty = loyalty
config := loyalty.Config()
b.SetBanList(config.BanList) b.SetBanList(config.BanList)
// Add loyalty-based commands // Add loyalty-based commands
@ -55,13 +55,14 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
var statusMux sync.Mutex var statusMux sync.Mutex
streamOnline := true streamOnline := true
go func() { go func() {
defer statusMux.Unlock()
for { for {
// Wait for next poll // Wait for next poll
time.Sleep(60 * time.Second) time.Sleep(60 * time.Second)
// Check if streamer is online, if possible // Check if streamer is online, if possible
func() {
statusMux.Lock() statusMux.Lock()
defer statusMux.Unlock()
streamOnline = true streamOnline = true
status, err := b.api.API.GetStreams(&helix.StreamsParams{ status, err := b.api.API.GetStreams(&helix.StreamsParams{
UserLogins: []string{b.config.Channel}, UserLogins: []string{b.config.Channel},
@ -71,17 +72,20 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
} else { } else {
streamOnline = len(status.Data.Streams) > 0 streamOnline = len(status.Data.Streams) > 0
} }
statusMux.Unlock()
err = b.api.db.PutJSON(StreamInfoKey, status.Data.Streams) err = b.api.db.PutJSON(StreamInfoKey, status.Data.Streams)
if err != nil { if err != nil {
b.logger.Warn("Error saving stream info", zap.Error(err)) b.logger.Warn("Error saving stream info", zap.Error(err))
} }
}()
} }
}() }()
go func() { go func() {
defer statusMux.Unlock()
for { for {
status := loyalty.Status()
if status.Enabled {
config := loyalty.Config()
if config.Points.Interval > 0 {
// Wait for next poll // Wait for next poll
time.Sleep(time.Duration(config.Points.Interval) * time.Second) time.Sleep(time.Duration(config.Points.Interval) * time.Second)
@ -93,7 +97,6 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
continue continue
} }
if config.Points.Interval > 0 {
b.logger.Debug("awarding points") b.logger.Debug("awarding points")
// Get user list // Get user list
@ -132,6 +135,7 @@ func (b *Bot) SetupLoyalty(loyalty *loyalty.Manager) {
} }
} }
} }
}
}() }()
}) })
} }