mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 16:36:23 +00:00
Merge branch 'informative-deploys' into panel.sutty.nl
This commit is contained in:
commit
d0368e7d42
3 changed files with 90 additions and 45 deletions
|
@ -40,12 +40,16 @@ class DeployJob < ApplicationJob
|
|||
}
|
||||
|
||||
# No es opcional
|
||||
unless @deployed[:deploy_local]
|
||||
unless @deployed[:deploy_local][:status]
|
||||
# Hacer fallar la tarea
|
||||
raise DeployException, deploy_local.build_stats.last.log
|
||||
raise DeployException, "#{@site.name}: Falló la compilación"
|
||||
end
|
||||
|
||||
deploy_others
|
||||
rescue DeployTimedOutException => e
|
||||
notify_exception e
|
||||
rescue DeployException => e
|
||||
notify_exception e, deploy_local
|
||||
ensure
|
||||
@site&.update status: 'waiting'
|
||||
|
||||
|
@ -56,6 +60,18 @@ class DeployJob < ApplicationJob
|
|||
|
||||
private
|
||||
|
||||
# @param :exception [StandardError]
|
||||
# @param :deploy [Deploy]
|
||||
def notify_exception(exception, deploy = nil)
|
||||
data = {
|
||||
site: @site.id,
|
||||
deploy: deploy&.type,
|
||||
log: deploy&.build_stats&.last&.log
|
||||
}
|
||||
|
||||
ExceptionNotifier.notify_exception(exception, data: data)
|
||||
end
|
||||
|
||||
def deploy_local
|
||||
@deploy_local ||= @site.deploys.find_by(type: 'DeployLocal')
|
||||
end
|
||||
|
@ -66,14 +82,21 @@ class DeployJob < ApplicationJob
|
|||
|
||||
def deploy_others
|
||||
@site.deploys.where.not(type: 'DeployLocal').find_each do |d|
|
||||
begin
|
||||
status = d.deploy(output: @output)
|
||||
build_stat = d.build_stats.last
|
||||
seconds = d.build_stats.last.try(:seconds)
|
||||
rescue StandardError => e
|
||||
status = false
|
||||
seconds = 0
|
||||
|
||||
notify_exception e, d
|
||||
end
|
||||
|
||||
@deployed[d.type.underscore.to_sym] = {
|
||||
status: status,
|
||||
seconds: build_stat.try(:seconds) || 0,
|
||||
seconds: seconds || 0,
|
||||
size: d.size,
|
||||
urls: d.respond_to?(:urls) ? d.urls : [d.url]
|
||||
urls: d.respond_to?(:urls) ? d.urls : [d.url].compact
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
# Notifica excepciones a una instancia de Gitlab, como incidencias
|
||||
# nuevas o como comentarios a las incidencias pre-existentes.
|
||||
class GitlabNotifierJob < ApplicationJob
|
||||
class GitlabNotifierError < StandardError; end
|
||||
|
||||
include ExceptionNotifier::BacktraceCleaner
|
||||
|
||||
# Variables que vamos a acceder luego
|
||||
|
@ -18,22 +20,28 @@ class GitlabNotifierJob < ApplicationJob
|
|||
@issue_data = { count: 1 }
|
||||
# Necesitamos saber si el issue ya existía
|
||||
@cached = false
|
||||
@issue = {}
|
||||
|
||||
# Traemos los datos desde la caché si existen, sino generamos un
|
||||
# issue nuevo e inicializamos la caché
|
||||
@issue_data = Rails.cache.fetch(cache_key) do
|
||||
issue = client.new_issue confidential: true, title: title, description: description, issue_type: 'incident'
|
||||
@issue = client.new_issue confidential: true, title: title, description: description, issue_type: 'incident'
|
||||
@cached = true
|
||||
|
||||
{
|
||||
count: 1,
|
||||
issue: issue['iid'],
|
||||
issue: @issue['iid'],
|
||||
user_agents: [user_agent].compact,
|
||||
params: [request&.filtered_parameters].compact,
|
||||
urls: [url].compact
|
||||
}
|
||||
end
|
||||
|
||||
unless @issue['iid']
|
||||
Rails.cache.delete(cache_key)
|
||||
raise GitlabNotifierError, @issue.dig('message', 'title')&.join(', ')
|
||||
end
|
||||
|
||||
# No seguimos actualizando si acabamos de generar el issue
|
||||
return if cached
|
||||
|
||||
|
@ -104,6 +112,7 @@ class GitlabNotifierJob < ApplicationJob
|
|||
# @return [String]
|
||||
def description
|
||||
@description ||= ''.dup.tap do |d|
|
||||
d << log_section
|
||||
d << request_section
|
||||
d << javascript_section
|
||||
d << javascript_footer
|
||||
|
@ -151,6 +160,19 @@ class GitlabNotifierJob < ApplicationJob
|
|||
@client ||= GitlabApiClient.new
|
||||
end
|
||||
|
||||
# @return [String]
|
||||
def log_section
|
||||
return '' unless options[:log]
|
||||
|
||||
<<~LOG
|
||||
# Log
|
||||
|
||||
```
|
||||
#{options[:log]}
|
||||
```
|
||||
LOG
|
||||
end
|
||||
|
||||
# Muestra información de la petición
|
||||
#
|
||||
# @return [String]
|
||||
|
|
|
@ -18,6 +18,9 @@ class DeployMailer < ApplicationMailer
|
|||
subject = t('.subject', site: site.name)
|
||||
hostname = site.hostname
|
||||
|
||||
# Informamos a cada quien en su idioma y damos una dirección de
|
||||
# respuesta porque a veces les usuaries nos escriben
|
||||
I18n.with_locale(usuarie.lang) do
|
||||
@hi = t('.hi')
|
||||
@explanation = t('.explanation', fqdn: hostname)
|
||||
@help = t('.help')
|
||||
|
@ -55,9 +58,6 @@ class DeployMailer < ApplicationMailer
|
|||
end
|
||||
end
|
||||
|
||||
# Informamos a cada quien en su idioma y damos una dirección de
|
||||
# respuesta porque a veces les usuaries nos escriben
|
||||
I18n.with_locale(usuarie.lang) do
|
||||
mail(to: usuarie.email, reply_to: "sutty@#{Site.domain}", subject: subject)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue