Skip to content

Commit

Permalink
func ptr -> interface
Browse files Browse the repository at this point in the history
  • Loading branch information
brianolson committed Dec 18, 2024
1 parent 805ae5b commit d709ae9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions indexer/crawler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
)

type CrawlDispatcher struct {
// from Crawl()
ingest chan *models.ActorInfo

repoSync chan *crawlWork

// from AddToCatchupQueue()
catchup chan *crawlWork

complete chan models.Uid
Expand All @@ -26,7 +28,7 @@ type CrawlDispatcher struct {
todo map[models.Uid]*crawlWork
inProgress map[models.Uid]*crawlWork

doRepoCrawl func(context.Context, *crawlWork) error
repoFetcher CrawlRepoFetcher

concurrency int

Expand All @@ -35,7 +37,12 @@ type CrawlDispatcher struct {
done chan struct{}
}

func NewCrawlDispatcher(repoFn func(context.Context, *crawlWork) error, concurrency int, log *slog.Logger) (*CrawlDispatcher, error) {
// this is what we need of RepoFetcher
type CrawlRepoFetcher interface {
FetchAndIndexRepo(ctx context.Context, job *crawlWork) error
}

func NewCrawlDispatcher(repoFetcher CrawlRepoFetcher, concurrency int, log *slog.Logger) (*CrawlDispatcher, error) {
if concurrency < 1 {
return nil, fmt.Errorf("must specify a non-zero positive integer for crawl dispatcher concurrency")
}
Expand All @@ -45,7 +52,7 @@ func NewCrawlDispatcher(repoFn func(context.Context, *crawlWork) error, concurre
repoSync: make(chan *crawlWork),
complete: make(chan models.Uid),
catchup: make(chan *crawlWork),
doRepoCrawl: repoFn,
repoFetcher: repoFetcher,
concurrency: concurrency,
todo: make(map[models.Uid]*crawlWork),
inProgress: make(map[models.Uid]*crawlWork),
Expand Down Expand Up @@ -221,7 +228,7 @@ func (c *CrawlDispatcher) fetchWorker() {
for {
select {
case job := <-c.repoSync:
if err := c.doRepoCrawl(context.TODO(), job); err != nil {
if err := c.repoFetcher.FetchAndIndexRepo(context.TODO(), job); err != nil {
c.log.Error("failed to perform repo crawl", "did", job.act.Did, "err", err)
}

Expand Down
2 changes: 1 addition & 1 deletion indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func NewIndexer(db *gorm.DB, notifman notifs.NotificationManager, evtman *events
}

if crawl {
c, err := NewCrawlDispatcher(fetcher.FetchAndIndexRepo, fetcher.MaxConcurrency, ix.log)
c, err := NewCrawlDispatcher(fetcher, fetcher.MaxConcurrency, ix.log)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit d709ae9

Please sign in to comment.