Skip to content

Commit

Permalink
Add endpoint to enqueue index jobs, will only work on indexer instanc…
Browse files Browse the repository at this point in the history
…e though
  • Loading branch information
ericvolp12 committed Sep 23, 2023
1 parent 7f365fd commit 7a3a5d5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions search/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,59 @@ func (s *Server) handleSearchActorsSkeleton(e echo.Context) error {
return e.JSON(200, out)
}

type IndexError struct {
DID string `json:"did"`
Err string `json:"err"`
}

func (s *Server) handleIndexRepos(e echo.Context) error {
ctx, span := otel.Tracer("search").Start(e.Request().Context(), "handleIndexRepos")
defer span.End()

dids, ok := e.QueryParams()["did"]
if !ok {
return e.JSON(400, map[string]any{
"error": "must pass at least one did to index",
})
}

for _, did := range dids {
_, err := syntax.ParseDID(did)
if err != nil {
return e.JSON(400, map[string]any{
"error": fmt.Sprintf("invalid DID (%s): %s", did, err),
})
}
}

errs := []IndexError{}
successes := 0
skipped := 0
for _, did := range dids {
job, err := s.bfs.GetJob(ctx, did)
if job == nil && err == nil {
err := s.bfs.EnqueueJob(did)
if err != nil {
errs = append(errs, IndexError{
DID: did,
Err: err.Error(),
})
continue
}
successes++
continue
}
skipped++
}

return e.JSON(200, map[string]any{
"numEnqueued": successes,
"numSkipped": skipped,
"numErrored": len(errs),
"errors": errs,
})
}

func (s *Server) SearchPosts(ctx context.Context, q string, offset, size int) (*SearchPostsSkeletonResp, error) {
resp, err := DoSearchPosts(ctx, s.dir, s.escli, s.postIndex, q, offset, size)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions search/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (s *Server) RunAPI(listen string) error {
e.GET("/metrics", echoprometheus.NewHandler())
e.GET("/xrpc/app.bsky.unspecced.searchPostsSkeleton", s.handleSearchPostsSkeleton)
e.GET("/xrpc/app.bsky.unspecced.searchActorsSkeleton", s.handleSearchActorsSkeleton)
e.GET("/xrpc/app.bsky.unspecced.indexRepos", s.handleIndexRepos)
s.echo = e

s.logger.Info("starting search API daemon", "bind", listen)
Expand Down

0 comments on commit 7a3a5d5

Please sign in to comment.