DG MS; queue still working. half-way finished cleaning up code.

This commit is contained in:
danielvincent 2010-06-17 10:36:54 -07:00
parent d91cec0881
commit 4cecb522b6
3 changed files with 57 additions and 90 deletions

View file

@ -1,4 +1,5 @@
class Post class Post
require 'lib/common'
require 'lib/message_handler' require 'lib/message_handler'
@ -7,6 +8,7 @@ class Post
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps include Mongoid::Timestamps
include ROXML include ROXML
include Diaspora::Hookey
xml_accessor :owner xml_accessor :owner
xml_accessor :snippet xml_accessor :snippet
@ -17,32 +19,6 @@ class Post
field :snippet field :snippet
before_create :set_defaults 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"] @@models = ["StatusMessage", "Bookmark", "Blog"]
@ -65,7 +41,5 @@ class Post
self.source ||= user_email self.source ||= user_email
self.snippet ||= user_email self.snippet ||= user_email
end end
end end

View file

@ -22,14 +22,12 @@ module Diaspora
def self.included(klass) def self.included(klass)
klass.class_eval do klass.class_eval do
include EventQueue::MessageHandler
before_save :notify_friends before_save :notify_friends
def notify_friends @@queue = MessageHandler.new
puts "hello"
def notify_friends
xml = prep_webhook xml = prep_webhook
#friends_with_permissions.each{ |friend| puts friend; Curl.post( "\"" + xml + "\" " + friend) }
@@queue.add_post_request( friends_with_permissions, xml ) @@queue.add_post_request( friends_with_permissions, xml )
@@queue.process @@queue.process
end end
@ -39,10 +37,7 @@ module Diaspora
end end
def friends_with_permissions def friends_with_permissions
#Friend.only(:url).map{|x| x = x.url + "/receive/"} Friend.only(:url).map{|x| x = x.url + "/receive/"}
#googles = []
#5.times{ googles <<"http://google.com/"} #"http://localhost:4567/receive/"} #"http://google.com/"}
googles
end end
end end
end end

View file

@ -5,9 +5,7 @@ require 'dm-core'
require 'eventmachine' require 'eventmachine'
require 'em-http' require 'em-http'
class MessageHandler
class MessageHandler
NUM_TRIES = 3 NUM_TRIES = 3
TIMEOUT = 5 #seconds TIMEOUT = 5 #seconds
@ -64,4 +62,4 @@ require 'em-http'
@try_count = 0 @try_count = 0
end end
end end
end end