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