rolled back some message handler nonsense
This commit is contained in:
parent
0c00e6a512
commit
11d4a9e2c7
4 changed files with 8 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
|||
development:
|
||||
debug: true
|
||||
debug: false
|
||||
socket_port: 8080
|
||||
|
||||
test:
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ module Diaspora
|
|||
module Webhooks
|
||||
def self.included(klass)
|
||||
klass.class_eval do
|
||||
@@queue = MessageHandler.instance
|
||||
@@queue = MessageHandler.new
|
||||
|
||||
def notify_people
|
||||
if self.person_id == User.first.id
|
||||
|
|
@ -75,6 +75,7 @@ module Diaspora
|
|||
end
|
||||
|
||||
def push_to_url(url)
|
||||
puts "bonedog"
|
||||
if url
|
||||
xml = self.class.build_xml_for([self])
|
||||
@@queue.add_post_request( [url], xml )
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
class MessageHandler
|
||||
include Singleton
|
||||
|
||||
NUM_TRIES = 3
|
||||
TIMEOUT = 5 #seconds
|
||||
|
|
@ -8,17 +7,13 @@ class MessageHandler
|
|||
@queue = EM::Queue.new
|
||||
end
|
||||
|
||||
def clear
|
||||
@queue = EM::Queue.new
|
||||
end
|
||||
|
||||
def add_get_request(destinations)
|
||||
destinations.each{ |dest| @queue.push(Message.new(:get, dest))}
|
||||
end
|
||||
|
||||
|
||||
def add_post_request(destinations, body)
|
||||
b = CGI::escape(body)
|
||||
b = body
|
||||
destinations.each{|dest| @queue.push(Message.new(:post, dest, b))}
|
||||
end
|
||||
|
||||
|
|
@ -26,8 +21,9 @@ class MessageHandler
|
|||
@queue.pop{ |query|
|
||||
case query.type
|
||||
when :post
|
||||
puts "sending: #{query.body} to #{query.destination}"
|
||||
http = EventMachine::HttpRequest.new(query.destination).post :timeout => TIMEOUT, :body =>{:xml => query.body}
|
||||
http.callback {puts "processing"; process}
|
||||
http.callback {puts "success from: to #{query.destination}"; process}
|
||||
when :get
|
||||
http = EventMachine::HttpRequest.new(query.destination).get :timeout => TIMEOUT
|
||||
http.callback {send_to_seed(query, http.response); process}
|
||||
|
|
@ -36,6 +32,7 @@ class MessageHandler
|
|||
end
|
||||
|
||||
http.errback {
|
||||
puts "fauilure from #{query.destination}, retrying"
|
||||
query.try_count +=1
|
||||
@queue.push query unless query.try_count >= NUM_TRIES
|
||||
process
|
||||
|
|
|
|||
|
|
@ -2,16 +2,12 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|||
|
||||
describe MessageHandler do
|
||||
before do
|
||||
@handler = MessageHandler.instance
|
||||
@handler = MessageHandler.new
|
||||
@message_body = "I want to pump you up"
|
||||
@message_urls = ["http://www.google.com/", "http://yahoo.com/", "http://foo.com/"]
|
||||
|
||||
end
|
||||
|
||||
after do
|
||||
@handler.clear
|
||||
end
|
||||
|
||||
describe 'GET messages' do
|
||||
describe 'creating a GET query' do
|
||||
it 'should be able to add a GET query to the queue with required destinations' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue