mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 05:06:22 +00:00
fix: reintentar en algunos errores
closes #15351 closes #15352 closes #15612 closes #15618 closes #15621 closes #15622 closes #15623 closes #15729 closes #15730 closes #15731 closes #15735 closes #15736 closes #15776 closes #15824 closes #15827 closes #15828 closes #15829 closes #15830 closes #15831 closes #15832 closes #15838 closes #15839 closes #15882
This commit is contained in:
parent
c501107856
commit
142962160a
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