Gracefully handle unrecognized federated objects so failed Resque jobs don't pile up.
Conflicts: lib/postzord/receiver/public.rb
This commit is contained in:
parent
6f3fb6ee67
commit
376bc4184f
3 changed files with 11 additions and 3 deletions
|
|
@ -8,7 +8,14 @@ module Diaspora
|
||||||
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
|
||||||
return unless body = doc.xpath("/XML/post").children.first
|
return unless body = doc.xpath("/XML/post").children.first
|
||||||
class_name = body.name.gsub('-', '/')
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class Postzord::Receiver::Private < Postzord::Receiver
|
||||||
|
|
||||||
def parse_and_receive(xml)
|
def parse_and_receive(xml)
|
||||||
@object ||= Diaspora::Parser.from_xml(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}")
|
Rails.logger.info("event=receive status=start recipient=#{@user_person.diaspora_handle} payload_type=#{@object.class} sender=#{@sender.diaspora_handle}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
|
||||||
attr_accessor :salmon, :author
|
attr_accessor :salmon, :author
|
||||||
|
|
||||||
def initialize(xml)
|
def initialize(xml)
|
||||||
@salmon = Salmon::Slap.from_xml(xml)
|
@salmon = Salmon::Slap.from_xml(xml)
|
||||||
@author = Webfinger.new(@salmon.author_id).fetch
|
@author = Webfinger.new(@salmon.author_id).fetch
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ class Postzord::Receiver::Public < Postzord::Receiver
|
||||||
def save_object
|
def save_object
|
||||||
@object = Diaspora::Parser::from_xml(@salmon.parsed_data)
|
@object = Diaspora::Parser::from_xml(@salmon.parsed_data)
|
||||||
raise "Object is not public" if object_can_be_public_and_it_is_not?
|
raise "Object is not public" if object_can_be_public_and_it_is_not?
|
||||||
@object.save
|
@object.save if @object
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Array<Integer>] User ids
|
# @return [Array<Integer>] User ids
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue