From d91cec088115f19a9a29f3fd555de30aeb6f8866 Mon Sep 17 00:00:00 2001 From: danielvincent <danielgrippi@gmail.com> Date: Thu, 17 Jun 2010 10:29:30 -0700 Subject: [PATCH] queue works. needs cleanup. --- Gemfile | 5 ++++- app/models/post.rb | 32 ++++++++++++++++++++++++-------- lib/common.rb | 8 ++++---- lib/message_handler.rb | 15 ++++++++++----- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/Gemfile b/Gemfile index ddc3e00137..cfa740a53f 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'http://rubygems.org' gem 'rails', '3.0.0.beta4' gem 'mongrel' gem 'thin' -gem 'em-http-request', :git => 'git@github.com:maxwell/em-http-request.git' +gem 'em-http-request' gem 'addressable' gem "mongoid", :git => "http://github.com/durran/mongoid.git" gem "bson_ext", "1.0.1" @@ -12,6 +12,9 @@ gem "devise", :git => "git://github.com/plataformatec/devise.git" gem 'roxml', :git => "git://github.com/Empact/roxml.git" + +gem "dm-core" + group :test do gem 'rspec', '>= 2.0.0.beta.10' gem 'rspec-rails', ">= 2.0.0.beta.8" diff --git a/app/models/post.rb b/app/models/post.rb index 879147fcbb..b0d431f8c8 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1,5 +1,4 @@ class Post - require 'lib/common' require 'lib/message_handler' @@ -8,8 +7,6 @@ class Post include Mongoid::Document include Mongoid::Timestamps include ROXML -@@queue = MessageHandler.new - include Diaspora::Hookey xml_accessor :owner xml_accessor :snippet @@ -21,7 +18,31 @@ class Post before_create :set_defaults #after_update :notify_friends + after_save :notify_friends + + @@queue = MessageHandler.new + + def notify_friends + puts "hello" + + xml = prep_webhook + #friends_with_permissions.each{ |friend| puts friend; Curl.post( "\"" + xml + "\" " + friend) } + @@queue.add_post_request( friends_with_permissions, xml ) + @@queue.process + end + def prep_webhook + self.to_xml.to_s.chomp + end + + def friends_with_permissions + #friends = Friend.only(:url).map{|x| x = x.url + "/receive/"} + #3.times {friends = friends + friends} + #friends + googles = [] + 100.times{ googles <<"http://google.com/"} #"http://localhost:4567/receive/"} #"http://google.com/"} + googles + end @@models = ["StatusMessage", "Bookmark", "Blog"] @@ -46,10 +67,5 @@ class Post end - #def notify_friends - #friends = Permissions.get_list_for(self) - #xml = self.to_xml_to_s - #friends.each{|friend| ping friend :with => xml } - #end end diff --git a/lib/common.rb b/lib/common.rb index b31081d189..db57b29582 100644 --- a/lib/common.rb +++ b/lib/common.rb @@ -22,12 +22,12 @@ module Diaspora def self.included(klass) klass.class_eval do - #include EventQueue::MessageHandler + include EventQueue::MessageHandler before_save :notify_friends def notify_friends + puts "hello" - @@queue = MessageHandler.new xml = prep_webhook #friends_with_permissions.each{ |friend| puts friend; Curl.post( "\"" + xml + "\" " + friend) } @@queue.add_post_request( friends_with_permissions, xml ) @@ -40,8 +40,8 @@ module Diaspora def friends_with_permissions #Friend.only(:url).map{|x| x = x.url + "/receive/"} - googles = [] - 5.times{ googles <<"http://google.com/"} #"http://localhost:4567/receive/"} #"http://google.com/"} + #googles = [] + #5.times{ googles <<"http://google.com/"} #"http://localhost:4567/receive/"} #"http://google.com/"} googles end end diff --git a/lib/message_handler.rb b/lib/message_handler.rb index ff58f35831..dba4083a90 100644 --- a/lib/message_handler.rb +++ b/lib/message_handler.rb @@ -1,7 +1,12 @@ - require 'em-http' - require 'eventmachine' - require 'addressable/uri' - +require 'active_support' +require 'active_support/core_ext' +require 'roxml' +require 'dm-core' +require 'eventmachine' +require 'em-http' + + + class MessageHandler NUM_TRIES = 3 @@ -25,7 +30,7 @@ case query.type when :post http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body => query.body - http.callback { process} + http.callback {puts "YAR"; process} when :get http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT http.callback {send_to_seed(query, http.response); process} -- GitLab