GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Don't fail if feed has not changed · stringer-rss/stringer@4765c1a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • app/tasks
    • fetch_feed.rb
  • spec/tasks
    • fetch_feed_spec.rb
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎app/tasks/fetch_feed.rb‎

Copy file name to clipboardExpand all lines: app/tasks/fetch_feed.rb
+9-5Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@ def fetch
1515
begin
1616
raw_feed = @parser.fetch_and_parse(@feed.url, user_agent: "Stringer", if_modified_since: @feed.last_fetched)
1717

18-
new_entries_from(raw_feed).each do |entry|
19-
StoryRepository.add(entry, @feed)
18+
if raw_feed == 304
19+
@logger.info "Feed has not been modified since last fetch"
20+
else
21+
new_entries_from(raw_feed).each do |entry|
22+
StoryRepository.add(entry, @feed)
23+
end
24+
25+
FeedRepository.update_last_fetched(@feed, raw_feed.last_modified)
26+
FeedRepository.set_status(:green, @feed)
2027
end
21-
22-
FeedRepository.update_last_fetched(@feed, raw_feed.last_modified)
23-
FeedRepository.set_status(:green, @feed)
2428
rescue Exception => ex
2529
FeedRepository.set_status(:red, @feed)
2630

Collapse file

‎spec/tasks/fetch_feed_spec.rb‎

Copy file name to clipboardExpand all lines: spec/tasks/fetch_feed_spec.rb
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
FeedRepository.stub(:set_status)
1616
end
1717

18+
context "when feed has not been modified" do
19+
it "should not try to fetch posts" do
20+
parser = stub(fetch_and_parse: 304)
21+
22+
StoryRepository.should_not_receive(:add)
23+
24+
FetchFeed.new(daring_fireball, parser)
25+
end
26+
end
27+
1828
context "when no new posts have been added" do
1929
it "should not add any new posts" do
2030
fake_feed = stub(last_modified: Time.new(2012, 12, 31))

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.