Skip to content

Instantly share code, notes, and snippets.

@dachev
Created March 2, 2012 03:49
Show Gist options
  • Save dachev/1955467 to your computer and use it in GitHub Desktop.
Save dachev/1955467 to your computer and use it in GitHub Desktop.
Search
class << ActiveRecord::Base
def each(chunk_size=100)
(0..self.last.id / chunk_size).each do |offset|
self.find(:all, :limit => chunk_size, :conditions => ['id > ?', offset * chunk_size]).each do |i|
yield i
end
end
end
end
class PageNode
def send_search_engine_update
payload = {
:id => self.id,
:action => 'add',
:node => {
:host => self.url[:host],
:controller => self.url[:controller],
:action => self.url[:action],
:page_title => self[:page_title],
:node_type => self[:node_type]
}
}
payload[:action] = 'remove' if self[:display_status] !='public'
req = Net::HTTP::Post.new('/api/job', initheader = {'Content-Type' =>'application/json'})
req.body = {:job=>payload}.to_json
#response = Net::HTTP.new('74.208.174.75', '8007').start {|http| http.request(req) }
#response = Net::HTTP.new('localhost', '8007').start {|http| http.request(req) }
response = Net::HTTP.new('blago.dachev.com', '80').start {|http| http.request(req) }
#puts payload.to_json
puts "Response #{response.code}"
end
end
PageNode.each {|n| n.send_search_engine_update }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment