]> git.giacomolli.uk - onechat/blobdiff - turn.go
Give the rebuild its own call limit
[onechat] / turn.go
diff --git a/turn.go b/turn.go
index e490068659da9fc4194a4f6eeb04a851ac464dee..42886049ffb934582fea0259145aa85e054d4863 100644 (file)
--- a/turn.go
+++ b/turn.go
@@ -112,6 +112,7 @@ func (l *TurnLoop) Submit(source, text string) (Message, error) {
        }
 
        l.mutex.Lock()
        }
 
        l.mutex.Lock()
+
        l.pending = append(l.pending, message)
        l.mutex.Unlock()
 
        l.pending = append(l.pending, message)
        l.mutex.Unlock()
 
@@ -167,6 +168,7 @@ func (l *TurnLoop) Wake(messages ...Message) {
        }
 
        l.mutex.Lock()
        }
 
        l.mutex.Lock()
+
        l.pending = append(l.pending, messages...)
        l.mutex.Unlock()
 
        l.pending = append(l.pending, messages...)
        l.mutex.Unlock()
 
@@ -285,6 +287,7 @@ func (l *TurnLoop) waiting() bool {
 // fail stops the loop with err.
 func (l *TurnLoop) fail(err error) {
        l.mutex.Lock()
 // fail stops the loop with err.
 func (l *TurnLoop) fail(err error) {
        l.mutex.Lock()
+
        l.failure = errors.Join(l.failure, err)
        l.mutex.Unlock()
 
        l.failure = errors.Join(l.failure, err)
        l.mutex.Unlock()
 
@@ -313,11 +316,13 @@ func (l *TurnLoop) turn(ctx context.Context) error {
        defer cancel()
 
        l.mutex.Lock()
        defer cancel()
 
        l.mutex.Lock()
+
        l.cancel = cancel
        l.mutex.Unlock()
 
        defer func() {
                l.mutex.Lock()
        l.cancel = cancel
        l.mutex.Unlock()
 
        defer func() {
                l.mutex.Lock()
+
                l.cancel = nil
                l.mutex.Unlock()
        }()
                l.cancel = nil
                l.mutex.Unlock()
        }()
@@ -329,7 +334,7 @@ func (l *TurnLoop) turn(ctx context.Context) error {
        err := l.chain(ctx)
        if err != nil && !errors.Is(err, errChainLogWrite) {
                if ctx.Err() == nil {
        err := l.chain(ctx)
        if err != nil && !errors.Is(err, errChainLogWrite) {
                if ctx.Err() == nil {
-                       l.logger.Printf("the turn stops before its end, and the agent waits for the next message: %v", err)
+                       l.logger.Printf("turn failed: %v", err)
                }
 
                l.notify(Event{
                }
 
                l.notify(Event{