mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-10 22:06:01 +10:00
15 lines
439 B
Ruby
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 |