FEATURE: Setting to poll feeds more frequently

This commit is contained in:
Robin Ward 2017-05-10 14:28:16 -04:00
parent 5be7a2dad4
commit 4db76796b9
7 changed files with 42 additions and 10 deletions

View File

@ -43,6 +43,7 @@
{{embedding-setting field="feed_polling_enabled" value=embedding.feed_polling_enabled type="checkbox"}} {{embedding-setting field="feed_polling_enabled" value=embedding.feed_polling_enabled type="checkbox"}}
{{embedding-setting field="feed_polling_url" value=embedding.feed_polling_url}} {{embedding-setting field="feed_polling_url" value=embedding.feed_polling_url}}
{{embedding-setting field="feed_polling_frequency_mins" value=embedding.feed_polling_frequency_mins}}
{{embedding-setting field="embed_username_key_from_feed" value=embedding.embed_username_key_from_feed}} {{embedding-setting field="embed_username_key_from_feed" value=embedding.embed_username_key_from_feed}}
</div> </div>

View File

@ -8,13 +8,14 @@ require 'open-uri'
module Jobs module Jobs
class PollFeed < Jobs::Scheduled class PollFeed < Jobs::Scheduled
every 1.hour every 5.minutes
sidekiq_options retry: false sidekiq_options retry: false
def execute(args) def execute(args)
poll_feed if SiteSetting.feed_polling_enabled? && poll_feed if SiteSetting.feed_polling_enabled? &&
SiteSetting.feed_polling_url.present? SiteSetting.feed_polling_url.present? &&
not_polled_recently?
end end
def feed_key def feed_key
@ -28,6 +29,15 @@ module Jobs
private private
def not_polled_recently?
$redis.set(
'feed-polled-recently',
"1",
ex: SiteSetting.feed_polling_frequency_mins.minutes - 10.seconds,
nx: true
)
end
def import_topics(feed_topics) def import_topics(feed_topics)
feed_topics.each do |topic| feed_topics.each do |topic|
import_topic(topic) import_topic(topic)

View File

@ -13,6 +13,7 @@ class Embedding < OpenStruct
embed_classname_whitelist embed_classname_whitelist
feed_polling_enabled feed_polling_enabled
feed_polling_url feed_polling_url
feed_polling_frequency_mins
embed_username_key_from_feed) embed_username_key_from_feed)
end end

View File

@ -3473,6 +3473,7 @@ en:
embed_classname_whitelist: "Allowed CSS class names" embed_classname_whitelist: "Allowed CSS class names"
feed_polling_enabled: "Import posts via RSS/ATOM" feed_polling_enabled: "Import posts via RSS/ATOM"
feed_polling_url: "URL of RSS/ATOM feed to crawl" feed_polling_url: "URL of RSS/ATOM feed to crawl"
feed_polling_frequency_mins: "Frequency of feed polling (in minutes)"
save: "Save Embedding Settings" save: "Save Embedding Settings"
permalink: permalink:

View File

@ -1440,6 +1440,7 @@ en:
feed_polling_enabled: "EMBEDDING ONLY: Whether to embed a RSS/ATOM feed as posts." feed_polling_enabled: "EMBEDDING ONLY: Whether to embed a RSS/ATOM feed as posts."
feed_polling_url: "EMBEDDING ONLY: URL of RSS/ATOM feed to embed." feed_polling_url: "EMBEDDING ONLY: URL of RSS/ATOM feed to embed."
feed_polling_frequency_mins: "EMBEDDING ONLY: Frequency of polling"
embed_by_username: "Discourse username of the user who creates the embedded topics." embed_by_username: "Discourse username of the user who creates the embedded topics."
embed_username_key_from_feed: "Key to pull discourse username from feed." embed_username_key_from_feed: "Key to pull discourse username from feed."
embed_title_scrubber: "Regular expression for scrubbing embeddable titles." embed_title_scrubber: "Regular expression for scrubbing embeddable titles."

View File

@ -1044,6 +1044,11 @@ embedding:
feed_polling_url: feed_polling_url:
default: '' default: ''
hidden: true hidden: true
feed_polling_frequency_mins:
min: 5
max: 180
default: 60
hidden: true
embed_by_username: embed_by_username:
default: '' default: ''
type: username type: username

View File

@ -8,18 +8,22 @@ describe Jobs::PollFeed do
let(:url) { "http://eviltrout.com" } let(:url) { "http://eviltrout.com" }
let(:embed_by_username) { "eviltrout" } let(:embed_by_username) { "eviltrout" }
before do
$redis.del("feed-polled-recently")
end
it "requires feed_polling_enabled?" do it "requires feed_polling_enabled?" do
SiteSetting.feed_polling_enabled = true SiteSetting.feed_polling_enabled = true
SiteSetting.feed_polling_url = nil SiteSetting.feed_polling_url = nil
poller.expects(:poll_feed).never poller.expects(:poll_feed).never
poller.execute({}) poller.execute({})
end end
it "requires feed_polling_url" do it "requires feed_polling_url" do
SiteSetting.feed_polling_enabled = false SiteSetting.feed_polling_enabled = false
SiteSetting.feed_polling_url = nil SiteSetting.feed_polling_url = nil
poller.expects(:poll_feed).never poller.expects(:poll_feed).never
poller.execute({}) poller.execute({})
end end
it "delegates to poll_feed" do it "delegates to poll_feed" do
@ -28,6 +32,15 @@ describe Jobs::PollFeed do
poller.expects(:poll_feed).once poller.expects(:poll_feed).once
poller.execute({}) poller.execute({})
end end
it "won't poll if it has polled recently" do
SiteSetting.feed_polling_enabled = true
SiteSetting.feed_polling_url = url
poller.expects(:poll_feed).once
poller.execute({})
poller.execute({})
end
end end
end end