mirror of
https://0xacab.org/sutty/sutty
synced 2025-01-19 14:03:39 +00:00
Merge branch 'issue-12958' into 'rails'
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Issue 12958 See merge request sutty/sutty!146
This commit is contained in:
commit
95d0c35d14
8 changed files with 35 additions and 12 deletions
|
@ -18,7 +18,7 @@ module Api
|
||||||
|
|
||||||
# Si todo salió bien, enviar los correos y redirigir al sitio.
|
# Si todo salió bien, enviar los correos y redirigir al sitio.
|
||||||
# El sitio nos dice a dónde tenemos que ir.
|
# El sitio nos dice a dónde tenemos que ir.
|
||||||
ContactJob.perform_async site.id,
|
ContactJob.perform_later site.id,
|
||||||
params[:form],
|
params[:form],
|
||||||
contact_params.to_h.symbolize_keys,
|
contact_params.to_h.symbolize_keys,
|
||||||
params[:redirect]
|
params[:redirect]
|
||||||
|
|
|
@ -4,9 +4,21 @@
|
||||||
class DeployJob < ApplicationJob
|
class DeployJob < ApplicationJob
|
||||||
class DeployException < StandardError; end
|
class DeployException < StandardError; end
|
||||||
class DeployTimedOutException < DeployException; end
|
class DeployTimedOutException < DeployException; end
|
||||||
|
class DeployAlreadyRunningException < DeployException; end
|
||||||
|
|
||||||
discard_on ActiveRecord::RecordNotFound
|
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
|
# rubocop:disable Metrics/MethodLength
|
||||||
def perform(site, notify: true, time: Time.now, output: false)
|
def perform(site, notify: true, time: Time.now, output: false)
|
||||||
@output = output
|
@output = output
|
||||||
|
@ -20,14 +32,14 @@ class DeployJob < ApplicationJob
|
||||||
# Como el trabajo actual se aplaza al siguiente, arrastrar la
|
# Como el trabajo actual se aplaza al siguiente, arrastrar la
|
||||||
# hora original para poder ir haciendo timeouts.
|
# hora original para poder ir haciendo timeouts.
|
||||||
if @site.building?
|
if @site.building?
|
||||||
|
notify = false
|
||||||
|
|
||||||
if 10.minutes.ago >= time
|
if 10.minutes.ago >= time
|
||||||
notify = false
|
|
||||||
raise DeployTimedOutException,
|
raise DeployTimedOutException,
|
||||||
"#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original"
|
"#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original"
|
||||||
|
else
|
||||||
|
raise DeployAlreadyRunningException
|
||||||
end
|
end
|
||||||
|
|
||||||
DeployJob.perform_in(60, site, notify: notify, time: time, output: output)
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@deployed = {}
|
@deployed = {}
|
||||||
|
@ -67,8 +79,6 @@ class DeployJob < ApplicationJob
|
||||||
t << ([type.to_s] + row.values)
|
t << ([type.to_s] + row.values)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
rescue DeployTimedOutException => e
|
|
||||||
notify_exception e
|
|
||||||
ensure
|
ensure
|
||||||
if @site.present?
|
if @site.present?
|
||||||
@site.update status: 'waiting'
|
@site.update status: 'waiting'
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
# bundle exec rails c
|
# bundle exec rails c
|
||||||
# m = Maintenance.create message_en: 'reason', message_es: 'razón',
|
# m = Maintenance.create message_en: 'reason', message_es: 'razón',
|
||||||
# estimated_from: Time.now, estimated_to: Time.now + 1.hour
|
# 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
|
# Lo mismo para salir de mantenimiento, agregando el atributo
|
||||||
# are_we_back: true al crear el Maintenance.
|
# are_we_back: true al crear el Maintenance.
|
||||||
|
|
|
@ -11,7 +11,12 @@ module ExceptionNotifier
|
||||||
# @param [Exception]
|
# @param [Exception]
|
||||||
# @param [Hash]
|
# @param [Hash]
|
||||||
def call(exception, **options)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ class LogEntry < ApplicationRecord
|
||||||
def resend
|
def resend
|
||||||
return if sent
|
return if sent
|
||||||
|
|
||||||
ContactJob.perform_async site_id, params[:form], params
|
ContactJob.perform_later site_id, params[:form], params
|
||||||
end
|
end
|
||||||
|
|
||||||
def params
|
def params
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
SiteService = Struct.new(:site, :usuarie, :params, keyword_init: true) do
|
||||||
def deploy
|
def deploy
|
||||||
site.enqueue!
|
site.enqueue!
|
||||||
DeployJob.perform_async site.id
|
DeployJob.perform_later site.id
|
||||||
end
|
end
|
||||||
|
|
||||||
# Crea un sitio, agrega un rol nuevo y guarda los cambios a la
|
# Crea un sitio, agrega un rol nuevo y guarda los cambios a la
|
||||||
|
|
|
@ -147,7 +147,7 @@ Rails.application.configure do
|
||||||
}
|
}
|
||||||
config.action_mailer.default_options = { from: ENV.fetch('DEFAULT_FROM', "noreply@sutty.nl") }
|
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[:host] = "panel.#{ENV.fetch('SUTTY', 'sutty.nl')}"
|
||||||
Rails.application.routes.default_url_options[:protocol] = 'https'
|
Rails.application.routes.default_url_options[:protocol] = 'https'
|
||||||
|
|
8
config/initializers/que.rb
Normal file
8
config/initializers/que.rb
Normal 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
|
Loading…
Reference in a new issue