fix(search): reindex on a fresh Meilisearch
Deleting a missing <uid>_next index is accepted with 202 and fails inside the task with index_not_found. That error was not treated as not-found, so the first reindex aborted and search stayed unavailable until indexes existed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
58bd14ef38
commit
e250837de9
2 files changed
+33
No files matched your search
@@ -77,6 +77,7 @@ func (m *Meili) wait(ctx context.Context, t taskRef) error {
|
|||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Error *struct {
|
Error *struct {
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
|
Code string `json:"code"`
|
||||||
} `json:"error"`
|
} `json:"error"`
|
||||||
}
|
}
|
||||||
if err := m.do(ctx, http.MethodGet, fmt.Sprintf("/tasks/%d", t.TaskUID), nil, &task); err != nil {
|
if err := m.do(ctx, http.MethodGet, fmt.Sprintf("/tasks/%d", t.TaskUID), nil, &task); err != nil {
|
||||||
@@ -88,6 +89,10 @@ func (m *Meili) wait(ctx context.Context, t taskRef) error {
|
|||||||
case "failed", "canceled":
|
case "failed", "canceled":
|
||||||
msg := task.Status
|
msg := task.Status
|
||||||
if task.Error != nil {
|
if task.Error != nil {
|
||||||
|
// Удаление отсутствующего индекса принимается (202) и падает уже в задаче.
|
||||||
|
if task.Error.Code == "index_not_found" {
|
||||||
|
return fmt.Errorf("%w: task %d: %s", ErrMeiliNotFound, t.TaskUID, task.Error.Message)
|
||||||
|
}
|
||||||
msg = task.Error.Message
|
msg = task.Error.Message
|
||||||
}
|
}
|
||||||
return fmt.Errorf("meilisearch: task %d: %s", t.TaskUID, msg)
|
return fmt.Errorf("meilisearch: task %d: %s", t.TaskUID, msg)
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package search
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// На чистом Meilisearch удаление несуществующего индекса падает в задаче, а не ответом 404.
|
||||||
|
func TestCallMapsFailedIndexTaskToNotFound(t *testing.T) {
|
||||||
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
if r.Method == http.MethodDelete {
|
||||||
|
w.WriteHeader(http.StatusAccepted)
|
||||||
|
_, _ = w.Write([]byte(`{"taskUid":0}`))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(`{"status":"failed","error":{"code":"index_not_found","message":"Index ` + "`x`" + ` not found."}}`))
|
||||||
|
}))
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
err := NewMeili(srv.URL, "").call(context.Background(), http.MethodDelete, "/indexes/x", nil)
|
||||||
|
if !errors.Is(err, ErrMeiliNotFound) {
|
||||||
|
t.Fatalf("err = %v, want ErrMeiliNotFound", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user