5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 15:56:20 +00:00
panel/app/jobs/activity_pub/instance_fetch_job.rb

39 lines
1.1 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
class ActivityPub
2024-02-27 19:54:09 +00:00
# Obtiene o actualiza los datos de una instancia. Usamos un cliente
# de ActivityPub porque la instancia podría estar en federación
# limitada.
class InstanceFetchJob < ApplicationJob
self.priority = 100
def perform(site:, instance:)
%w[/api/v2/instance /api/v1/instance].each do |api|
uri = SocialInbox.generate_uri(instance.hostname) do |u|
u.path = api
end
response = site.social_inbox.dereferencer.get(uri: uri)
next unless response.success?
2024-02-27 19:54:09 +00:00
# @todo Validate schema
next unless response.parsed_response.is_a?(DistributedPress::V1::Social::ReferencedObject)
2024-02-27 19:54:09 +00:00
instance.update(content: response.parsed_response.object)
break
rescue BRS::BaseError,
Errno::ECONNREFUSED,
HTTParty::Error,
JSON::JSONError,
Net::OpenTimeout,
OpenSSL::OpenSSLError,
SocketError,
Errno::ENETUNREACH => e
ExceptionNotifier.notify_exception(e, data: { instance: uri })
break
end
end
end
end