Skip to content

Commit

Permalink
try fixing cpu capping
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantspace committed May 24, 2024
1 parent 448ba55 commit 9b72b34
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/app/ai/sse/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (c *Client) SubscribeWithContext(ctx context.Context, stream string, handle
case msg := <-eventChan:
handler(msg)
}
time.Sleep(200 * time.Millisecond)
}
}

Expand Down Expand Up @@ -268,7 +269,6 @@ func (c *Client) readLoop(reader *EventStreamReader, outCh chan *Event, erChan c
c.connectedcb(c)
}

// If we get an error, ignore it.
var msg *Event
if msg, err = c.processEvent(event); err == nil {
if len(msg.ID) > 0 {
Expand All @@ -281,6 +281,8 @@ func (c *Client) readLoop(reader *EventStreamReader, outCh chan *Event, erChan c
if msg.hasContent() {
outCh <- msg
}
} else {
erChan <- err
}
}
}
Expand Down Expand Up @@ -397,6 +399,7 @@ func (c *Client) processEvent(msg []byte) (event *Event, err error) {
n, err := base64.StdEncoding.Decode(buf, e.Data)
if err != nil {
err = fmt.Errorf("failed to decode event message: %s", err)
log.Error(err)
}
e.Data = buf[:n]
}
Expand Down

0 comments on commit 9b72b34

Please sign in to comment.