Gracefully handle unrecognized federated objects so failed Resque jobs don't pile up.

Conflicts:

	lib/postzord/receiver/public.rb
This commit is contained in:
Pistos 2012-02-10 18:57:42 -05:00 committed by Maxwell Salzberg
parent 6f3fb6ee67
commit 376bc4184f
3 changed files with 11 additions and 3 deletions

View file

@ -8,7 +8,14 @@ module Diaspora
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
return unless body = doc.xpath("/XML/post").children.first
class_name = body.name.gsub('-', '/')
class_name.camelize.constantize.from_xml body.to_s
begin
class_name.camelize.constantize.from_xml body.to_s
rescue NameError => e
# A pods is trying to federate an object we don't recognize.
# i.e. their codebase is different from ours. Quietly discard
# so that no Resque job failure is created
nil
end
end
end
end

View file

@ -29,6 +29,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
def parse_and_receive(xml)
@object ||= Diaspora::Parser.from_xml(xml)
return if @object.nil?
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")

View file

@ -7,7 +7,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
attr_accessor :salmon, :author
def initialize(xml)
@salmon = Salmon::Slap.from_xml(xml)
@salmon = Salmon::Slap.from_xml(xml)
@author = Webfinger.new(@salmon.author_id).fetch
end
@ -47,7 +47,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
def save_object
@object = Diaspora::Parser::from_xml(@salmon.parsed_data)
raise "Object is not public" if object_can_be_public_and_it_is_not?
@object.save
@object.save if @object
end
# @return [Array<Integer>] User ids