diff --git a/app/assets/javascripts/admin/templates/embedding.hbs b/app/assets/javascripts/admin/templates/embedding.hbs index 5db5cb6bfa8..965e663c776 100644 --- a/app/assets/javascripts/admin/templates/embedding.hbs +++ b/app/assets/javascripts/admin/templates/embedding.hbs @@ -43,6 +43,7 @@ {{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_frequency_mins" value=embedding.feed_polling_frequency_mins}} {{embedding-setting field="embed_username_key_from_feed" value=embedding.embed_username_key_from_feed}} diff --git a/app/jobs/scheduled/poll_feed.rb b/app/jobs/scheduled/poll_feed.rb index fe5ef403fcd..c30f68cd2d1 100644 --- a/app/jobs/scheduled/poll_feed.rb +++ b/app/jobs/scheduled/poll_feed.rb @@ -8,13 +8,14 @@ require 'open-uri' module Jobs class PollFeed < Jobs::Scheduled - every 1.hour + every 5.minutes sidekiq_options retry: false def execute(args) poll_feed if SiteSetting.feed_polling_enabled? && - SiteSetting.feed_polling_url.present? + SiteSetting.feed_polling_url.present? && + not_polled_recently? end def feed_key @@ -28,6 +29,15 @@ module Jobs 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) feed_topics.each do |topic| import_topic(topic) diff --git a/app/models/embedding.rb b/app/models/embedding.rb index 7e28a7694f9..f11de96f4f3 100644 --- a/app/models/embedding.rb +++ b/app/models/embedding.rb @@ -13,6 +13,7 @@ class Embedding < OpenStruct embed_classname_whitelist feed_polling_enabled feed_polling_url + feed_polling_frequency_mins embed_username_key_from_feed) end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 609a3e1e458..afb445a3939 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3473,6 +3473,7 @@ en: embed_classname_whitelist: "Allowed CSS class names" feed_polling_enabled: "Import posts via RSS/ATOM" feed_polling_url: "URL of RSS/ATOM feed to crawl" + feed_polling_frequency_mins: "Frequency of feed polling (in minutes)" save: "Save Embedding Settings" permalink: diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 3804b3bf535..2cf3c6740b0 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1440,6 +1440,7 @@ en: 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_frequency_mins: "EMBEDDING ONLY: Frequency of polling" 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_title_scrubber: "Regular expression for scrubbing embeddable titles." diff --git a/config/site_settings.yml b/config/site_settings.yml index edc4f37a2bd..84a409ef6b1 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1044,6 +1044,11 @@ embedding: feed_polling_url: default: '' hidden: true + feed_polling_frequency_mins: + min: 5 + max: 180 + default: 60 + hidden: true embed_by_username: default: '' type: username diff --git a/spec/jobs/poll_feed_spec.rb b/spec/jobs/poll_feed_spec.rb index b222991cb0e..0fcfa7d02cb 100644 --- a/spec/jobs/poll_feed_spec.rb +++ b/spec/jobs/poll_feed_spec.rb @@ -8,18 +8,22 @@ describe Jobs::PollFeed do let(:url) { "http://eviltrout.com" } let(:embed_by_username) { "eviltrout" } + before do + $redis.del("feed-polled-recently") + end + it "requires feed_polling_enabled?" do - SiteSetting.feed_polling_enabled = true - SiteSetting.feed_polling_url = nil - poller.expects(:poll_feed).never - poller.execute({}) + SiteSetting.feed_polling_enabled = true + SiteSetting.feed_polling_url = nil + poller.expects(:poll_feed).never + poller.execute({}) end it "requires feed_polling_url" do - SiteSetting.feed_polling_enabled = false - SiteSetting.feed_polling_url = nil - poller.expects(:poll_feed).never - poller.execute({}) + SiteSetting.feed_polling_enabled = false + SiteSetting.feed_polling_url = nil + poller.expects(:poll_feed).never + poller.execute({}) end it "delegates to poll_feed" do @@ -28,6 +32,15 @@ describe Jobs::PollFeed do poller.expects(:poll_feed).once poller.execute({}) 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