FEATURE: Setting to poll feeds more frequently
This commit is contained in:
parent
5be7a2dad4
commit
4db76796b9
|
@ -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}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -8,6 +8,10 @@ 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
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue