package cron import ( "log" "time" "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" "git.jamestombleson.com/jtom38/newsbot-api/internal/services/input" ) func (c *Cron) CheckRssSources() { log.Println("Starting ") sources, err := c.repo.Sources.ListBySource(*c.ctx, 0, 1000, domain.SourceCollectorRss) if err != nil { log.Println(err) } for sourceIndex, source := range sources { if !source.Enabled { continue } rssClient := input.NewRssClient(source) articles, err := rssClient.GetArticles() if err != nil { log.Println(err) } for _, article := range articles { _, err := c.repo.Articles.GetByUrl(*c.ctx, article.Url) if err == nil { continue } rowsCreated, err := c.repo.Articles.CreateFromEntity(*c.ctx, article) if err != nil { log.Println(err) } if rowsCreated != 1 { log.Println("Got back the wrong number of rows") } } if sourceIndex != len(sources) { time.Sleep(time.Second * 30) } } } func (c *Cron) ListAllSourceRecords(sourceType string) ([]domain.SourceEntity, error) { var records []domain.SourceEntity sources, err := c.repo.Sources.ListBySource(*c.ctx, 0, 1000, sourceType) if err != nil { return records, err } return sources, nil }