Files
libr-2/app/workers/post_content_worker.rb

15 lines
439 B
Ruby

class PostContentWorker
include Sidekiq::Worker
sidekiq_options queue: :post, retry: 3
def perform id, url, css_selector
post = Post.find id
page = Nokogiri::HTML RestClient.get(url)
content_html = page.css(css_selector)[0].try(:to_html)
post.title = page.css("title").text.try(:strip) if post.title.nil?
post.content = content_html
post.good_format = true if post.type != 'WebPage'
post.save!
end
end