Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/yl 70 feed detail #32

Merged
merged 2 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions batch-service/cmd/usecase/article.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (au *ArticleUsecase) BatchCreateArticles(ctx context.Context) error {
// get rss
rss, err := GetRSS(f.RSSURL)
if err != nil {
log.Printf("【error get rss】: %s", f.Name)
log.Printf("【error get rss】: %s, %v", f.Name, err)
continue
}
wg := new(sync.WaitGroup)
Expand All @@ -54,7 +54,6 @@ func (au *ArticleUsecase) BatchCreateArticles(ctx context.Context) error {
defer wg.Done()
// transaction
tx, err := au.db.BeginTx(ctx, nil)
log.Printf("【begin transaction】:feed: %s, article: %s", f.Name, r.Title)
if err != nil {
log.Printf("【error begin transaction】: %s", err)
return
Expand All @@ -79,7 +78,6 @@ func (au *ArticleUsecase) BatchCreateArticles(ctx context.Context) error {
if res.isCreatedFeedArticleRelation {
farCount++
}
log.Printf("【commit transaction】:feed: %s, article: %s", f.Name, r.Title)
//commit
err := tx.Commit()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions batch-service/cmd/usecase/rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func GetRSS(rssURL string) ([]RSS, error) {

feed, err := fp.ParseURLWithContext(rssURL, ctx)
if err != nil {
println(fmt.Sprintf("error: %s\n", err))
return nil, err
}
items := feed.Items
Expand Down
15 changes: 12 additions & 3 deletions batch-service/cmd/usecase/rss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ func TestGetRss(t *testing.T) {
}{
{
name: "Success: GetRss",
rssURL: "https://www.toptal.com/blog.rss",
rssURL: "https://menthas.com/javascript/rss",
siteURL: "https://menthas.com/javascript/rss",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
//GetRSS(tt.rssURL)
//getFavicon(tt.siteURL)
rss, err := GetRSS(tt.rssURL)
if err != nil {
t.Errorf("failed to get rss: %v", err)
}
if len(rss) == 0 {
t.Errorf("failed to get rss: %v", rss)
}

if rss[0].Link != tt.siteURL {
t.Errorf("failed to get rss: %v", rss)
}
})
}
}
Loading
Loading