mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-16 22:48:19 +00:00
Merge branch 'issue-15109-1' into production.panel.sutty.nl
This commit is contained in:
commit
bb13d2edfd
1 changed files with 30 additions and 4 deletions
|
@ -11,14 +11,42 @@ class ActivityPub
|
|||
class FetchJob < ApplicationJob
|
||||
self.priority = 50
|
||||
|
||||
attr_reader :site, :object, :response
|
||||
|
||||
# Notificar errores de JSON con el contenido, tomar los errores de
|
||||
# validación y conexión como errores temporales y notificar todo lo
|
||||
# demás sin reintentar.
|
||||
#
|
||||
# @param error [Exception]
|
||||
# @return [Bool]
|
||||
def handle_error(error)
|
||||
case error
|
||||
when FastJsonparser::ParseError
|
||||
expire
|
||||
|
||||
ExceptionNotifier.notify_exception(error, data: { site: site.name, object: object.uri, body: response.body })
|
||||
|
||||
false
|
||||
when ActiveRecord::RecordInvalid, SocketError, SystemCallError, Net::OpenTimeout, OpenSSL::OpenSSLError
|
||||
retry_in(ApplicationJob.random_wait)
|
||||
|
||||
false
|
||||
else
|
||||
expire
|
||||
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def perform(site:, object_id:)
|
||||
ActivityPub::Object.transaction do
|
||||
object = ::ActivityPub::Object.find(object_id)
|
||||
@site = site
|
||||
@object = ::ActivityPub::Object.find(object_id)
|
||||
|
||||
return if object.blank?
|
||||
return if object.activity_pubs.where(aasm_state: 'removed').count.positive?
|
||||
|
||||
response = site.social_inbox.dereferencer.get(uri: object.uri)
|
||||
@response = site.social_inbox.dereferencer.get(uri: object.uri)
|
||||
|
||||
# @todo Fallar cuando la respuesta no funcione?
|
||||
# @todo Eliminar en 410 Gone
|
||||
|
@ -39,8 +67,6 @@ class ActivityPub
|
|||
|
||||
# Arreglar las relaciones con actividades también
|
||||
ActivityPub.where(object_id: object.id).update_all(object_type: object.type, updated_at: Time.now)
|
||||
rescue FastJsonparser::ParseError => e
|
||||
ExceptionNotifier.notify_exception(e, data: { site: site.name, object: object.uri, body: response.body })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue