Skip to content

Commit

Permalink
Add retry logic to getFilenameForCall call (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Jan 9, 2024
1 parent dff1b90 commit d9fa87a
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/transcriber/call/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,20 @@ func getModelsDir() string {
}

func (t *Transcriber) publishTranscription(tr transcribe.Transcription) (err error) {
fname, err := t.getFilenameForCall()
var fname string
for i := 0; i < maxUploadRetryAttempts; i++ {
if i > 0 {
slog.Error("getFilenameForCall failed",
slog.String("err", err.Error()),
slog.Duration("reattempt_time", uploadRetryAttemptWaitTime))
time.Sleep(uploadRetryAttemptWaitTime)
}

fname, err = t.getFilenameForCall()
if err == nil {
break
}
}
if err != nil {
return fmt.Errorf("failed to get filename for call: %w", err)
}
Expand Down
62 changes: 62 additions & 0 deletions cmd/transcriber/call/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,66 @@ All right, we should be recording. Welcome everyone, developers meeting for Dece
err := tr.publishTranscription(transcribe.Transcription{})
require.NoError(t, err)
})

t.Run("should re-attempt in case of failure to get filename", func(t *testing.T) {
var failures int
middlewares = []middleware{
func(w http.ResponseWriter, r *http.Request) bool {
if r.URL.Path == "/plugins/com.mattermost.calls/bot/calls/8w8jorhr7j83uqr6y1st894hqe/filename" && r.Method == http.MethodGet {
if failures == 0 {
w.WriteHeader(400)
failures++
} else {
w.WriteHeader(200)
fmt.Fprintln(w, `{"filename": "Call_Test"}`)
}

return true
}

return false
},
func(w http.ResponseWriter, r *http.Request) bool {
if r.URL.Path == "/plugins/com.mattermost.calls/bot/uploads" && r.Method == http.MethodPost {
var us model.UploadSession

err := json.NewDecoder(r.Body).Decode(&us)
require.NoError(t, err)

us.Id = "jpanyqdipffrpmxxst3kzdjaah"

w.WriteHeader(200)
err = json.NewEncoder(w).Encode(&us)
require.NoError(t, err)

return true
}

return false
},
func(w http.ResponseWriter, r *http.Request) bool {
if r.URL.Path == "/plugins/com.mattermost.calls/bot/uploads/jpanyqdipffrpmxxst3kzdjaah" && r.Method == http.MethodPost {
var fi model.FileInfo
w.WriteHeader(200)
err = json.NewEncoder(w).Encode(&fi)
require.NoError(t, err)

return true
}

return false
},
func(w http.ResponseWriter, r *http.Request) bool {
if r.URL.Path == "/plugins/com.mattermost.calls/bot/calls/8w8jorhr7j83uqr6y1st894hqe/transcriptions" && r.Method == http.MethodPost {
w.WriteHeader(200)
return true
}

return false
},
}

err := tr.publishTranscription(transcribe.Transcription{})
require.NoError(t, err)
})
}

0 comments on commit d9fa87a

Please sign in to comment.