5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 22:36:21 +00:00

Merge branch 'issue-15109-1' into panel.testing.sutty.nl

This commit is contained in:
f 2024-03-26 11:44:29 -03:00
commit e0a0681b54
No known key found for this signature in database
5 changed files with 35 additions and 12 deletions

View file

@ -49,7 +49,9 @@ module Api
#
# @param initial_state [Symbol]
def process!(initial_state)
::ActivityPub::ProcessJob.perform_later(site: site, body: request.raw_post, initial_state: initial_state)
::ActivityPub::ProcessJob
.set(wait: ApplicationJob.random_wait)
.perform_later(site: site, body: request.raw_post, initial_state: initial_state)
end
end
end

View file

@ -3,15 +3,16 @@
class ActivityPub
# Procesar las actividades a medida que llegan
class ProcessJob < ApplicationJob
attr_reader :body
attr_reader :body, :initial_state
# Procesa la actividad en segundo plano
#
# @param :body [String]
# @param :initial_state [Symbol,String]
def perform(site:, body:, initial_state: :paused)
@body = body
@site = site
@body = body
@initial_state = initial_state
ActiveRecord::Base.connection_pool.with_connection do
::ActivityPub.transaction do
@ -25,10 +26,24 @@ class ActivityPub
activity.update_activity_pub_state!
end
end
end
# Al generar una excepción, en lugar de seguir intentando, enviamos
# el reporte.
rescue Exception => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, body: body, initial_state: initial_state, activity: original_activity, message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.' })
def handle_error(error)
case error
when ActiveRecord::RecordInvalid then retry_in(ApplicationJob.random_wait)
else
ExceptionNotifier.notify_exception(
error,
data: {
site: site.name,
body: body,
initial_state: initial_state,
activity: original_activity,
message: 'Esta acción se canceló automáticamente, para regenerarla, volver a correr el proceso con los mismos parámetros.'
})
end
end
private

View file

@ -4,6 +4,17 @@
class ApplicationJob < ActiveJob::Base
include Que::ActiveJob::JobExtensions
# Esperar una cantidad random de segundos primos, para que no se
# superpongan tareas
#
# @return [Array<Integer>]
RANDOM_WAIT = [3, 5, 7, 11, 13]
# @return [ActiveSupport::Duration]
def self.random_wait
RANDOM_WAIT.sample.seconds
end
private
def site

View file

@ -767,10 +767,7 @@ en:
categories: 'Everything'
index:
search: 'Search'
edit_post: 'Edit'
edit:
moderation_queue: Moderation Queue
post: Post
edit: Edit
preview:
btn: 'Preliminary version'
alert: 'Not every article type has a preliminary version'

View file

@ -708,9 +708,7 @@ es:
en: 'inglés'
ar: 'árabe'
posts:
edit:
moderation_queue: Comentarios
post: Contenido
edit: Editar
prev: Página anterior
next: Página siguiente
empty: No hay artículos con estos parámetros de búsqueda.