mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-18 11:32:24 -05:00
e1f293ad66
Removed sidetiq, introduced new scheduler - add basic UI - add schedule discover - add scheduling in initializer
44 lines
1.1 KiB
Ruby
44 lines
1.1 KiB
Ruby
#
|
|
# Creates and Updates Topics based on an RSS or ATOM feed.
|
|
#
|
|
require 'digest/sha1'
|
|
require_dependency 'post_creator'
|
|
require_dependency 'post_revisor'
|
|
require 'open-uri'
|
|
|
|
module Jobs
|
|
class PollFeed < Jobs::Scheduled
|
|
every 1.hour
|
|
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
poll_feed if SiteSetting.feed_polling_enabled? &&
|
|
SiteSetting.feed_polling_url.present? &&
|
|
SiteSetting.embed_by_username.present?
|
|
end
|
|
|
|
def feed_key
|
|
@feed_key ||= "feed-modified:#{Digest::SHA1.hexdigest(SiteSetting.feed_polling_url)}"
|
|
end
|
|
|
|
def poll_feed
|
|
user = User.where(username_lower: SiteSetting.embed_by_username.downcase).first
|
|
return if user.blank?
|
|
|
|
require 'simple-rss'
|
|
rss = SimpleRSS.parse open(SiteSetting.feed_polling_url)
|
|
|
|
rss.items.each do |i|
|
|
url = i.link
|
|
url = i.id if url.blank? || url !~ /^https?\:\/\//
|
|
|
|
content = i.content || i.description
|
|
if content
|
|
TopicEmbed.import(user, url, i.title, CGI.unescapeHTML(content.scrub))
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|