Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Commit

Permalink
Record status.
Browse files Browse the repository at this point in the history
  • Loading branch information
benubois committed Feb 22, 2018
1 parent 2990bea commit 412f81f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/boot.rb
Expand Up @@ -22,6 +22,7 @@
require 'lib/librato'
require 'lib/worker_stat'
require 'lib/sidekiq'
require 'lib/record_status'

require 'app/models/fetched'
require 'app/models/formatted_entries'
Expand Down
7 changes: 7 additions & 0 deletions app/models/fetched.rb
Expand Up @@ -33,6 +33,9 @@ def parsed_feed
end
rescue Feedjira::NoParserAvailable
@parsed_feed = false
@message = "ParseError"
rescue Curl => e
@message = e.class.to_s
end

def request
Expand All @@ -43,6 +46,10 @@ def status
@status || request.status
end

def status_message
@message || status
end

private

def request_options
Expand Down
6 changes: 5 additions & 1 deletion app/workers/feed_refresher_fetcher.rb
@@ -1,8 +1,9 @@
class FeedRefresherFetcher
include Sidekiq::Worker
include RecordStatus
sidekiq_options queue: :feed_refresher_fetcher

# Options: etag, last_modified, subscriptions_count, xml, push_callback, hub_secret, push_mode
# Options: etag, last_modified, subscriptions_count, xml, push_callback, hub_secret, push_mode, record_status
def perform(feed_id, feed_url, options = {})
feed = { id: feed_id }
if options["xml"]
Expand All @@ -11,6 +12,9 @@ def perform(feed_id, feed_url, options = {})
fetched = Fetched.new(feed_id, feed_url, options)
entries = fetched.entries
feed = feed.merge(fetched.feed)
if options["record_status"]
record_status(feed_id, fetched.status_message)
end
if fetched.parsed_feed && options["push_callback"] && options["hub_secret"]
push = PubSubHubbub.new(
fetched.parsed_feed.hubs,
Expand Down
17 changes: 17 additions & 0 deletions lib/record_status.rb
@@ -0,0 +1,17 @@
module RecordStatus

def record_status(feed_id, status)
$redis.with do |connection|
connection.pipelined do
connection.lpush(list_name(feed_id), status)
connection.ltrim(list_name(feed_id), 0, 99)
connection.lrange(list_name(feed_id), 0, 99)
end
end
end

def list_name(feed_id)
"feed:#{feed_id}:status"
end

end
5 changes: 5 additions & 0 deletions test/fetched_test.rb
Expand Up @@ -45,4 +45,9 @@ def test_should_get_status
assert_equal 200, @fetched_json.status
end

def test_should_get_status_message
assert_equal 200, @fetched.status_message
assert_equal 200, @fetched_json.status_message
end

end

0 comments on commit 412f81f

Please sign in to comment.