我认为这是我在这里的第一个问题,希望尽可能清楚。我有闲置代码。
def index_service_name
@currentService = Feed.where("name = '#{params[:name]}'").first
serviceId = @currentService['id']
serviceName = @currentService['name']
serviceFeedUrl = @currentService['feedUrl']
feed = Feedzirra::Feed.fetch_and_parse(serviceFeedUrl)
feed.entries.reverse.each do |entry|
case serviceName
when 'service1', 'service2'
uniqueId = entry.url.match(/\d+$/)[0]
postContent = Nokogiri::HTML( entry.content ).css('img').map{ |i| i['src'] }.first # this would be an array.
else
uniqueId = entry.url
postContent = entry.content
end
isIndexed = Post.where("post_unique_id = '#{uniqueId}' AND post_service = '#{serviceId}'")
if postContent =~ %r{\Ahttps?://.+\.(?:jpe?g|png|gif)\z}i
isImage = true
elsif postContent =~ %r{http?s://(.*)/maxW500/}i
isImage = true
end
if isIndexed.empty? && isImage
sleep 1.seconds
Post.create(post_service: serviceId, post_service_name: serviceName, title: entry.title, content: postContent, url: entry.url, post_unique_id: uniqueId)
end
end
我使用常规 URL(/something/service/service1、/something/service/service2)触发服务。如果我同时触发它们,似乎它们中的每一个都在等待另一个结束(因此在我的数据库中,数据首先从 service1 存储,然后从 service2 存储)。我认为这与多线程有关,据我所知,ROR 尚不支持它。
我是 ROR 的新手,所以请温柔一点。任何帮助深表感谢。