5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-27 02: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] # @param initial_state [Symbol]
def process!(initial_state) 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 end
end end

View file

@ -3,15 +3,16 @@
class ActivityPub class ActivityPub
# Procesar las actividades a medida que llegan # Procesar las actividades a medida que llegan
class ProcessJob < ApplicationJob class ProcessJob < ApplicationJob
attr_reader :body attr_reader :body, :initial_state
# Procesa la actividad en segundo plano # Procesa la actividad en segundo plano
# #
# @param :body [String] # @param :body [String]
# @param :initial_state [Symbol,String] # @param :initial_state [Symbol,String]
def perform(site:, body:, initial_state: :paused) def perform(site:, body:, initial_state: :paused)
@body = body
@site = site @site = site
@body = body
@initial_state = initial_state
ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.connection_pool.with_connection do
::ActivityPub.transaction do ::ActivityPub.transaction do
@ -25,10 +26,24 @@ class ActivityPub
activity.update_activity_pub_state! activity.update_activity_pub_state!
end end
end end
end
# Al generar una excepción, en lugar de seguir intentando, enviamos # Al generar una excepción, en lugar de seguir intentando, enviamos
# el reporte. # el reporte.
rescue Exception => e def handle_error(error)
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.' }) 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 end
private private

View file

@ -4,6 +4,17 @@
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
include Que::ActiveJob::JobExtensions 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 private
def site def site

View file

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

View file

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