5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-05-17 05:50:48 +00:00

Merge branch 'issue-12958' into 'rails'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

Issue 12958

See merge request sutty/sutty!146
This commit is contained in:
fauno 2023-04-10 21:03:28 +00:00
commit 95d0c35d14
8 changed files with 35 additions and 12 deletions

View file

@ -18,7 +18,7 @@ module Api
# Si todo salió bien, enviar los correos y redirigir al sitio.
# El sitio nos dice a dónde tenemos que ir.
ContactJob.perform_async site.id,
ContactJob.perform_later site.id,
params[:form],
contact_params.to_h.symbolize_keys,
params[:redirect]

View file

@ -4,9 +4,21 @@
class DeployJob < ApplicationJob
class DeployException < StandardError; end
class DeployTimedOutException < DeployException; end
class DeployAlreadyRunningException < DeployException; end
discard_on ActiveRecord::RecordNotFound
# Lanzar lo antes posible
self.priority = 10
def handle_error(error)
case error
when DeployAlreadyRunningException then retry_in 1.minute
when DeployTimedOutException then expire
else super
end
end
# rubocop:disable Metrics/MethodLength
def perform(site, notify: true, time: Time.now, output: false)
@output = output
@ -20,14 +32,14 @@ class DeployJob < ApplicationJob
# Como el trabajo actual se aplaza al siguiente, arrastrar la
# hora original para poder ir haciendo timeouts.
if @site.building?
notify = false
if 10.minutes.ago >= time
notify = false
raise DeployTimedOutException,
"#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original"
else
raise DeployAlreadyRunningException
end
DeployJob.perform_in(60, site, notify: notify, time: time, output: output)
return
end
@deployed = {}
@ -67,8 +79,6 @@ class DeployJob < ApplicationJob
t << ([type.to_s] + row.values)
end
end)
rescue DeployTimedOutException => e
notify_exception e
ensure
if @site.present?
@site.update status: 'waiting'

View file

@ -10,7 +10,7 @@
# bundle exec rails c
# m = Maintenance.create message_en: 'reason', message_es: 'razón',
# estimated_from: Time.now, estimated_to: Time.now + 1.hour
# MaintenanceJob.perform_async(maintenance_id: m.id)
# MaintenanceJob.perform_later(maintenance_id: m.id)
#
# Lo mismo para salir de mantenimiento, agregando el atributo
# are_we_back: true al crear el Maintenance.

View file

@ -11,7 +11,12 @@ module ExceptionNotifier
# @param [Exception]
# @param [Hash]
def call(exception, **options)
GitlabNotifierJob.perform_async(exception, **options)
case exception
when BacktraceJob::BacktraceException
GitlabNotifierJob.perform_later(exception, **options)
else
GitlabNotifierJob.perform_now(exception, **options)
end
end
end
end

View file

@ -11,7 +11,7 @@ class LogEntry < ApplicationRecord
def resend
return if sent
ContactJob.perform_async site_id, params[:form], params
ContactJob.perform_later site_id, params[:form], params
end
def params

View file

@ -5,7 +5,7 @@
SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
def deploy
site.enqueue!
DeployJob.perform_async site.id
DeployJob.perform_later site.id
end
# Crea un sitio, agrega un rol nuevo y guarda los cambios a la

View file

@ -147,7 +147,7 @@ Rails.application.configure do
}
config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', "noreply@sutty.nl") }
config.middleware.use ExceptionNotification::Rack, gitlab: {}
config.middleware.use ExceptionNotification::Rack, gitlab: {}, ignore_exceptions: (['DeployJob::DeployAlreadyRunningException'] + ExceptionNotifier.ignored_exceptions)
Rails.application.routes.default_url_options[:host] = "panel.#{ENV.fetch('SUTTY', 'sutty.nl')}"
Rails.application.routes.default_url_options[:protocol] = 'https'

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
ActiveJob::Serializers.add_serializers ActiveJob::Serializers::ExceptionSerializer
# Notificar los errores
Que.error_notifier = proc do |error, job|
ExceptionNotifier.notify_exception(error, data: (job || {}))
end