From 87cdba9bec0a45ab48802c409830478ca045ff6e Mon Sep 17 00:00:00 2001 From: f Date: Wed, 6 Apr 2022 20:07:14 -0300 Subject: [PATCH 01/21] =?UTF-8?q?enviar=20m=C3=A1s=20informaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 14 ++++++++++++-- app/models/deploy.rb | 4 ++++ app/models/deploy_alternative_domain.rb | 6 +++++- app/models/deploy_hidden_service.rb | 2 +- app/models/deploy_local.rb | 4 ++++ app/models/deploy_private.rb | 4 ++++ app/models/deploy_www.rb | 4 ++++ app/models/deploy_zip.rb | 4 ++++ app/views/deploy_mailer/deployed.html.haml | 9 +++++++-- app/views/deploy_mailer/deployed.text.haml | 7 +++---- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 12 files changed, 52 insertions(+), 10 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 70997ce1..db91672b 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -27,7 +27,13 @@ class DeployJob < ApplicationJob @site.update status: 'building' # Asegurarse que DeployLocal sea el primero! - @deployed = { deploy_local: deploy_locally } + @deployed = { + deploy_local: { + status: deploy_locally, + seconds: deploy_local.build_stats.last.seconds, + url: site.url + } + } # No es opcional unless @deployed[:deploy_local] @@ -60,7 +66,11 @@ class DeployJob < ApplicationJob def deploy_others @site.deploys.where.not(type: 'DeployLocal').find_each do |d| - @deployed[d.type.underscore.to_sym] = d.deploy + @deployed[d.type.underscore.to_sym] = { + status: d.deploy, + seconds: d.build_stats.last.seconds, + url: d.url + } end end diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 3f034ad5..1aefe126 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -15,6 +15,10 @@ class Deploy < ApplicationRecord raise NotImplementedError end + def url + raise NotImplementedError + end + def limit raise NotImplementedError end diff --git a/app/models/deploy_alternative_domain.rb b/app/models/deploy_alternative_domain.rb index e4960e65..d245ac21 100644 --- a/app/models/deploy_alternative_domain.rb +++ b/app/models/deploy_alternative_domain.rb @@ -18,6 +18,10 @@ class DeployAlternativeDomain < Deploy end def destination - File.join(Rails.root, '_deploy', hostname.gsub(/\.\z/, '')) + @destination ||= File.join(Rails.root, '_deploy', hostname.gsub(/\.\z/, '')) + end + + def url + "https://#{File.basename destination}" end end diff --git a/app/models/deploy_hidden_service.rb b/app/models/deploy_hidden_service.rb index d4d2b822..8df46c2e 100644 --- a/app/models/deploy_hidden_service.rb +++ b/app/models/deploy_hidden_service.rb @@ -13,6 +13,6 @@ class DeployHiddenService < DeployWww end def url - 'http://' + fqdn + "http://#{fqdn}" end end diff --git a/app/models/deploy_local.rb b/app/models/deploy_local.rb index 4fa588f5..b6fa407f 100644 --- a/app/models/deploy_local.rb +++ b/app/models/deploy_local.rb @@ -25,6 +25,10 @@ class DeployLocal < Deploy 1 end + def url + site.url + end + # Obtener el tamaño de todos los archivos y directorios (los # directorios son archivos :) def size diff --git a/app/models/deploy_private.rb b/app/models/deploy_private.rb index 3a6595f9..0d79811d 100644 --- a/app/models/deploy_private.rb +++ b/app/models/deploy_private.rb @@ -16,6 +16,10 @@ class DeployPrivate < DeployLocal File.join(Rails.root, '_private', site.name) end + def url + "#{ENV['PANEL_URL']}/sites/private/#{site.name}" + end + # No usar recursos en compresión y habilitar los datos privados def env @env ||= super.merge({ diff --git a/app/models/deploy_www.rb b/app/models/deploy_www.rb index 5602b0fc..3c9feb3b 100644 --- a/app/models/deploy_www.rb +++ b/app/models/deploy_www.rb @@ -27,6 +27,10 @@ class DeployWww < Deploy "www.#{site.hostname}" end + def url + "https://www.#{site.hostname}/" + end + private def remove_destination! diff --git a/app/models/deploy_zip.rb b/app/models/deploy_zip.rb index ec8973d1..0a66b602 100644 --- a/app/models/deploy_zip.rb +++ b/app/models/deploy_zip.rb @@ -49,6 +49,10 @@ class DeployZip < Deploy "#{site.hostname}.zip" end + def url + "#{site.url}#{file}" + end + def path File.join(destination, file) end diff --git a/app/views/deploy_mailer/deployed.html.haml b/app/views/deploy_mailer/deployed.html.haml index e8b2e7af..23e99469 100644 --- a/app/views/deploy_mailer/deployed.html.haml +++ b/app/views/deploy_mailer/deployed.html.haml @@ -8,10 +8,15 @@ %tr %th= t('.th.type') %th= t('.th.status') + %th= t('.th.url') + %th= t('.th.seconds') %tbody - - @deploys.each do |deploy, value| + - @deploys.each_pair do |deploy, value| %tr %td= t(".#{deploy}.title") - %td= value ? t(".#{deploy}.success") : t(".#{deploy}.error") + %td= value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error") + %td= link_to value[:url], value[:url] + %td + %time{ datetime: "PT#{value[:seconds]}S" }= distance_of_time_in_words value[:seconds].seconds = sanitize_markdown t('.help'), tags: %w[p a strong em] diff --git a/app/views/deploy_mailer/deployed.text.haml b/app/views/deploy_mailer/deployed.text.haml index 53a9b008..a3073a61 100644 --- a/app/views/deploy_mailer/deployed.text.haml +++ b/app/views/deploy_mailer/deployed.text.haml @@ -3,10 +3,9 @@ = t('.explanation', fqdn: @deploy_local.site.hostname) \ = Terminal::Table.new do |table| - - table << [t('.th.type'), t('.th.status')] + - table << [t('.th.type'), t('.th.status'), t('.th.url'), t('.th.seconds')] - table.add_separator - - @deploys.each do |deploy, value| - - table << [t(".#{deploy}.title"), - value ? t(".#{deploy}.success") : t(".#{deploy}.error")] + - @deploys.each_pair do |deploy, value| + - table << [ t(".#{deploy}.title"), value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error"), value[:url], distance_of_time_in_words(value[:seconds].seconds) ] \ = t('.help') diff --git a/config/locales/en.yml b/config/locales/en.yml index b814796d..c8df9150 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -76,6 +76,8 @@ en: th: type: Type status: Status + seconds: Duration + url: Address deploy_local: title: Build the site success: Success! diff --git a/config/locales/es.yml b/config/locales/es.yml index a6fbd407..e94f623a 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -76,6 +76,8 @@ es: th: type: Tipo status: Estado + seconds: Duración + url: Dirección deploy_local: title: Generar el sitio success: ¡Éxito! From c47b4f179cfa07b492edd3834c162508e2c198dc Mon Sep 17 00:00:00 2001 From: f Date: Wed, 6 Apr 2022 20:16:31 -0300 Subject: [PATCH 02/21] =?UTF-8?q?fixup!=20enviar=20m=C3=A1s=20informaci?= =?UTF-8?q?=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index db91672b..79cfa134 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -31,7 +31,7 @@ class DeployJob < ApplicationJob deploy_local: { status: deploy_locally, seconds: deploy_local.build_stats.last.seconds, - url: site.url + url: deploy_local.url } } From 92866704249f0fa8d8156557e5e8e8365bab5b79 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 6 Apr 2022 20:42:40 -0300 Subject: [PATCH 03/21] mostrar espacio utilizado --- app/jobs/deploy_job.rb | 2 ++ app/views/deploy_mailer/deployed.html.haml | 2 ++ app/views/deploy_mailer/deployed.text.haml | 2 +- config/locales/en.yml | 1 + config/locales/es.yml | 1 + 5 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 79cfa134..38bb0429 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -31,6 +31,7 @@ class DeployJob < ApplicationJob deploy_local: { status: deploy_locally, seconds: deploy_local.build_stats.last.seconds, + size: deploy_local.build_stats.last.size, url: deploy_local.url } } @@ -69,6 +70,7 @@ class DeployJob < ApplicationJob @deployed[d.type.underscore.to_sym] = { status: d.deploy, seconds: d.build_stats.last.seconds, + size: d.build_stats.last.size, url: d.url } end diff --git a/app/views/deploy_mailer/deployed.html.haml b/app/views/deploy_mailer/deployed.html.haml index 23e99469..0053accf 100644 --- a/app/views/deploy_mailer/deployed.html.haml +++ b/app/views/deploy_mailer/deployed.html.haml @@ -10,6 +10,7 @@ %th= t('.th.status') %th= t('.th.url') %th= t('.th.seconds') + %th= t('.th.size') %tbody - @deploys.each_pair do |deploy, value| %tr @@ -18,5 +19,6 @@ %td= link_to value[:url], value[:url] %td %time{ datetime: "PT#{value[:seconds]}S" }= distance_of_time_in_words value[:seconds].seconds + %td= number_to_human_size value[:size], precision: 2 = sanitize_markdown t('.help'), tags: %w[p a strong em] diff --git a/app/views/deploy_mailer/deployed.text.haml b/app/views/deploy_mailer/deployed.text.haml index a3073a61..0188c303 100644 --- a/app/views/deploy_mailer/deployed.text.haml +++ b/app/views/deploy_mailer/deployed.text.haml @@ -6,6 +6,6 @@ - table << [t('.th.type'), t('.th.status'), t('.th.url'), t('.th.seconds')] - table.add_separator - @deploys.each_pair do |deploy, value| - - table << [ t(".#{deploy}.title"), value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error"), value[:url], distance_of_time_in_words(value[:seconds].seconds) ] + - table << [t(".#{deploy}.title"), value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error"), value[:url], distance_of_time_in_words(value[:seconds].seconds), number_to_human_size(value[:size], precision: 2)] \ = t('.help') diff --git a/config/locales/en.yml b/config/locales/en.yml index c8df9150..75fbcc94 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -77,6 +77,7 @@ en: type: Type status: Status seconds: Duration + size: Space used url: Address deploy_local: title: Build the site diff --git a/config/locales/es.yml b/config/locales/es.yml index e94f623a..73467149 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -77,6 +77,7 @@ es: type: Tipo status: Estado seconds: Duración + size: Espacio ocupado url: Dirección deploy_local: title: Generar el sitio From 9024a13490288013f852a57e2a546161d9e47420 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 6 Apr 2022 20:48:14 -0300 Subject: [PATCH 04/21] algunos deploys no generan build_stats --- app/jobs/deploy_job.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 38bb0429..97438650 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -67,10 +67,13 @@ class DeployJob < ApplicationJob def deploy_others @site.deploys.where.not(type: 'DeployLocal').find_each do |d| + status = d.deploy + build_stat = d.build_stats.last + @deployed[d.type.underscore.to_sym] = { - status: d.deploy, - seconds: d.build_stats.last.seconds, - size: d.build_stats.last.size, + status: status, + seconds: build_stat.try(:seconds) || 0, + size: build_stat.try(:size) || 0, url: d.url } end From ef2589a4f162552d7903f98005cb43303fbdcf65 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 6 Apr 2022 20:51:45 -0300 Subject: [PATCH 05/21] =?UTF-8?q?no=20es=20necesario=20traer=20el=20tama?= =?UTF-8?q?=C3=B1o=20de=20los=20build=5Fstats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 97438650..ae6cb279 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -31,7 +31,7 @@ class DeployJob < ApplicationJob deploy_local: { status: deploy_locally, seconds: deploy_local.build_stats.last.seconds, - size: deploy_local.build_stats.last.size, + size: deploy_local.size, url: deploy_local.url } } @@ -73,7 +73,7 @@ class DeployJob < ApplicationJob @deployed[d.type.underscore.to_sym] = { status: status, seconds: build_stat.try(:seconds) || 0, - size: build_stat.try(:size) || 0, + size: d.size, url: d.url } end From 106029b48f4bba2576e92928dfb9cba857d99de3 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 7 Apr 2022 13:34:12 -0300 Subject: [PATCH 06/21] header --- app/views/deploy_mailer/deployed.text.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/deploy_mailer/deployed.text.haml b/app/views/deploy_mailer/deployed.text.haml index 0188c303..48e8000c 100644 --- a/app/views/deploy_mailer/deployed.text.haml +++ b/app/views/deploy_mailer/deployed.text.haml @@ -3,7 +3,7 @@ = t('.explanation', fqdn: @deploy_local.site.hostname) \ = Terminal::Table.new do |table| - - table << [t('.th.type'), t('.th.status'), t('.th.url'), t('.th.seconds')] + - table << [t('.th.type'), t('.th.status'), t('.th.url'), t('.th.seconds'), t('.th.size')] - table.add_separator - @deploys.each_pair do |deploy, value| - table << [t(".#{deploy}.title"), value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error"), value[:url], distance_of_time_in_words(value[:seconds].seconds), number_to_human_size(value[:size], precision: 2)] From b091b3212a71fa182be5ddb884f700faec05f3ae Mon Sep 17 00:00:00 2001 From: f Date: Wed, 8 Feb 2023 18:55:05 -0300 Subject: [PATCH 07/21] feat: refactorizar mailer para que use menos recursors y soporte varias urls --- app/jobs/deploy_job.rb | 4 +- app/mailers/deploy_mailer.rb | 63 ++++++++++++++++++---- app/views/deploy_mailer/deployed.html.haml | 31 +++++------ app/views/deploy_mailer/deployed.text.haml | 12 ++--- 4 files changed, 73 insertions(+), 37 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index ae6cb279..6250cf73 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -32,7 +32,7 @@ class DeployJob < ApplicationJob status: deploy_locally, seconds: deploy_local.build_stats.last.seconds, size: deploy_local.size, - url: deploy_local.url + urls: [deploy_local.url] } } @@ -74,7 +74,7 @@ class DeployJob < ApplicationJob status: status, seconds: build_stat.try(:seconds) || 0, size: d.size, - url: d.url + urls: d.respond_to?(:urls) ? d.urls : [d.url] } end end diff --git a/app/mailers/deploy_mailer.rb b/app/mailers/deploy_mailer.rb index 1d0c7308..aeb13676 100644 --- a/app/mailers/deploy_mailer.rb +++ b/app/mailers/deploy_mailer.rb @@ -8,21 +8,64 @@ # TODO: Agregar firma GPG y header Autocrypt # TODO: Cifrar con GPG si le usuarie nos dio su llave class DeployMailer < ApplicationMailer + include ActionView::Helpers::NumberHelper + include ActionView::Helpers::DateHelper + # rubocop:disable Metrics/AbcSize - def deployed(which_ones) - @usuarie = Usuarie.find(params[:usuarie]) - @site = @usuarie.sites.find(params[:site]) - @deploys = which_ones - @deploy_local = @site.deploys.find_by(type: 'DeployLocal') + def deployed(deploys) + usuarie = Usuarie.find(params[:usuarie]) + site = usuarie.sites.find(params[:site]) + subject = t('.subject', site: site.name) + hostname = site.hostname + + @hi = t('.hi') + @explanation = t('.explanation', fqdn: hostname) + @help = t('.help') + + @headers = %w[type status url seconds size].map do |header| + t(".th.#{header}") + end + + @table = deploys.each_pair.map do |deploy, value| + { + title: t(".#{deploy}.title"), + status: t(".#{deploy}.#{value[:status] ? 'success' : 'error'}"), + urls: value[:urls], + seconds: { + human: distance_of_time_in_words(value[:seconds].seconds), + machine: "PT#{value[:seconds]}S" + }, + size: number_to_human_size(value[:size], precision: 2) + } + end + + @terminal_table = Terminal::Table.new do |t| + t << @headers + t.add_separator + @table.each do |row| + row[:urls].each do |url| + t << (row.map do |k, v| + case k + when :seconds then v[:human] + when :urls then url + else v + end + end) + end + 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: I18n.t('deploy_mailer.deployed.subject', - site: @site.name)) + I18n.with_locale(usuarie.lang) do + mail(to: usuarie.email, reply_to: "sutty@#{Site.domain}", subject: subject) end end # rubocop:enable Metrics/AbcSize + + private + + def t(key, **args) + I18n.t("deploy_mailer.deployed#{key}", **args) + end end diff --git a/app/views/deploy_mailer/deployed.html.haml b/app/views/deploy_mailer/deployed.html.haml index 0053accf..20548f16 100644 --- a/app/views/deploy_mailer/deployed.html.haml +++ b/app/views/deploy_mailer/deployed.html.haml @@ -1,24 +1,21 @@ -%h1= t('.hi') +%h1= @hi -= sanitize_markdown t('.explanation', fqdn: @deploy_local.site.hostname), - tags: %w[p a strong em] += sanitize_markdown @explanation, tags: %w[p a strong em] %table %thead %tr - %th= t('.th.type') - %th= t('.th.status') - %th= t('.th.url') - %th= t('.th.seconds') - %th= t('.th.size') + - @headers.each do |header| + %th= header %tbody - - @deploys.each_pair do |deploy, value| - %tr - %td= t(".#{deploy}.title") - %td= value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error") - %td= link_to value[:url], value[:url] - %td - %time{ datetime: "PT#{value[:seconds]}S" }= distance_of_time_in_words value[:seconds].seconds - %td= number_to_human_size value[:size], precision: 2 + - @table.each do |row| + - row[:urls].each do |url| + %tr + %td= row[:title] + %td= row[:status] + %td= link_to url, url + %td + %time{ datetime: row[:seconds][:machine] }= row[:seconds][:human] + %td= row[:size] -= sanitize_markdown t('.help'), tags: %w[p a strong em] += sanitize_markdown @help, tags: %w[p a strong em] diff --git a/app/views/deploy_mailer/deployed.text.haml b/app/views/deploy_mailer/deployed.text.haml index 48e8000c..b2d0416f 100644 --- a/app/views/deploy_mailer/deployed.text.haml +++ b/app/views/deploy_mailer/deployed.text.haml @@ -1,11 +1,7 @@ -= '# ' + t('.hi') += "# #{@hi}" \ -= t('.explanation', fqdn: @deploy_local.site.hostname) += @explanation \ -= Terminal::Table.new do |table| - - table << [t('.th.type'), t('.th.status'), t('.th.url'), t('.th.seconds'), t('.th.size')] - - table.add_separator - - @deploys.each_pair do |deploy, value| - - table << [t(".#{deploy}.title"), value[:status] ? t(".#{deploy}.success") : t(".#{deploy}.error"), value[:url], distance_of_time_in_words(value[:seconds].seconds), number_to_human_size(value[:size], precision: 2)] += @terminal_table \ -= t('.help') += @help From e81f188147e062400721dcd609eef5d62d8f089c Mon Sep 17 00:00:00 2001 From: f Date: Wed, 8 Feb 2023 19:30:05 -0300 Subject: [PATCH 08/21] =?UTF-8?q?fix:=20no=20generar=20links=20si=20la=20u?= =?UTF-8?q?rl=20viene=20vac=C3=ADa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/deploy_mailer/deployed.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/deploy_mailer/deployed.html.haml b/app/views/deploy_mailer/deployed.html.haml index 20548f16..f5afe5de 100644 --- a/app/views/deploy_mailer/deployed.html.haml +++ b/app/views/deploy_mailer/deployed.html.haml @@ -13,7 +13,7 @@ %tr %td= row[:title] %td= row[:status] - %td= link_to url, url + %td= link_to_if url.present?, url, url %td %time{ datetime: row[:seconds][:machine] }= row[:seconds][:human] %td= row[:size] From 866b11ff74ff3eba6095389340f62761029cff2a Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 17:29:13 -0300 Subject: [PATCH 09/21] fix: poder distinguir entre errores de deploy --- app/jobs/deploy_job.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 70997ce1..84119416 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -3,6 +3,7 @@ # Realiza el deploy de un sitio class DeployJob < ApplicationJob class DeployException < StandardError; end + class DeployTimedOutException < DeployException; end # rubocop:disable Metrics/MethodLength def perform(site, notify = true, time = Time.now) @@ -17,7 +18,7 @@ class DeployJob < ApplicationJob if @site.building? if 10.minutes.ago >= time @site.update status: 'waiting' - raise DeployException, + raise DeployTimedOutException, "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" end From e62172e37a188effecdf1319f9e76991dbaa3192 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 18:46:22 -0300 Subject: [PATCH 10/21] =?UTF-8?q?chore:=20secar=20el=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit la primera hipótesis sobre #10031 es que las excepciones cancelan la actualización de la información, como si fueran una transacción, pero haciendo pruebas manuales no pasa. con este cambio al menos el código queda más limpio. --- app/jobs/deploy_job.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 84119416..9c0ed1dd 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -17,7 +17,6 @@ class DeployJob < ApplicationJob # hora original para poder ir haciendo timeouts. if @site.building? if 10.minutes.ago >= time - @site.update status: 'waiting' raise DeployTimedOutException, "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" end @@ -32,17 +31,13 @@ class DeployJob < ApplicationJob # No es opcional unless @deployed[:deploy_local] - @site.update status: 'waiting' - notify_usuaries if notify - # Hacer fallar la tarea raise DeployException, deploy_local.build_stats.last.log end deploy_others - - # Volver a la espera - @site.update status: 'waiting' + ensure + @site&.update status: 'waiting' notify_usuaries if notify end From 6a7a0dddda284fde2e2eb9f6c8b493e45b407d50 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 18:46:56 -0300 Subject: [PATCH 11/21] fix: no notificar al liberar la tarea --- app/jobs/deploy_job.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 9c0ed1dd..2165ed11 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -17,6 +17,7 @@ class DeployJob < ApplicationJob # hora original para poder ir haciendo timeouts. if @site.building? if 10.minutes.ago >= time + notify = false raise DeployTimedOutException, "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" end From 955786be0e6a48a88e55510b0e16de595b7680ea Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 18:52:15 -0300 Subject: [PATCH 12/21] =?UTF-8?q?fix:=20cancelar=20la=20compilaci=C3=B3n?= =?UTF-8?q?=20al=20primer=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Recupera el comportamiento de #1716 #1730 #1735 #1738 #1739 #1740 #1741 #1743 #1744 #1746 #1832 #1952 #2057 #2058 #2059 #2062 #1104 #1124 #1152 #1153 #1154 #1175 #1191 #1230 #1303 #1461 #1478 #1609 #1610 #1667 #504 --- app/jobs/deploy_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 2165ed11..9f58e3a1 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -31,7 +31,7 @@ class DeployJob < ApplicationJob @deployed = { deploy_local: deploy_locally } # No es opcional - unless @deployed[:deploy_local] + unless @deployed[:deploy_local][:status] # Hacer fallar la tarea raise DeployException, deploy_local.build_stats.last.log end From 1d08b3fdcd080c28702b6a692827399a1c828bd8 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 19:04:55 -0300 Subject: [PATCH 13/21] fix: llegar hasta el final aunque fallen algunos metodos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit al usar ensure en el commit anterior, podemos garantizar que cualquier excepción en otros deploys no deja la compilación en estado de compilación permanente, pero no se notifica a les usuaries. --- app/jobs/deploy_job.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 9f58e3a1..2dacf08e 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -58,6 +58,10 @@ class DeployJob < ApplicationJob def deploy_others @site.deploys.where.not(type: 'DeployLocal').find_each do |d| @deployed[d.type.underscore.to_sym] = d.deploy + rescue StandardError => e + @deployed[d.type.underscore.to_sym] = false + + ExceptionNotifier.notify_exception(e, data: { site: site.id, deploy: d.type }) end end From efe3474f5f4db5bb0b47ab9c4bab6db84691022f Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 19:14:36 -0300 Subject: [PATCH 14/21] fix: hay deploys sin url --- app/jobs/deploy_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 48366bb9..6dd93129 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -78,7 +78,7 @@ class DeployJob < ApplicationJob status: status, 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 From e0a7232643bbad491887d121bb7a237ac95b6923 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 19:27:03 -0300 Subject: [PATCH 15/21] fix: notificar las excepciones manualmente MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit por alguna razón sucker punch dejó de enviarlas! --- app/jobs/deploy_job.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index 2dacf08e..e187b6bd 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -37,6 +37,8 @@ class DeployJob < ApplicationJob end deploy_others + rescue DeployException => e + notify_exception e ensure @site&.update status: 'waiting' @@ -47,6 +49,12 @@ class DeployJob < ApplicationJob private + # @param :exception [StandardError] + # @param :deploy [Deploy] + def notify_exception(exception, deploy = nil) + ExceptionNotifier.notify_exception(exception, data: { site: @site.id, deploy: deploy&.type }) + end + def deploy_local @deploy_local ||= @site.deploys.find_by(type: 'DeployLocal') end From 8c5a1096107d7fb904ba327d83e3af12f2f4743d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:04:18 -0300 Subject: [PATCH 16/21] fix: informar cuando no se puede procesar un issue --- app/jobs/gitlab_notifier_job.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 7218f68a..129697ba 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -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 From a0263ad3fbaed7238a9e017e29a89665e009d6aa Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:04:53 -0300 Subject: [PATCH 17/21] =?UTF-8?q?fix:=20el=20log=20completo=20hace=20un=20?= =?UTF-8?q?t=C3=ADtulo=20demasiado=20largo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 10 ++++++++-- app/jobs/gitlab_notifier_job.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index e187b6bd..b411568e 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -33,7 +33,7 @@ class DeployJob < ApplicationJob # No es opcional unless @deployed[:deploy_local][:status] # Hacer fallar la tarea - raise DeployException, deploy_local.build_stats.last.log + raise DeployException, 'Falló la compilación' end deploy_others @@ -52,7 +52,13 @@ class DeployJob < ApplicationJob # @param :exception [StandardError] # @param :deploy [Deploy] def notify_exception(exception, deploy = nil) - ExceptionNotifier.notify_exception(exception, data: { site: @site.id, deploy: deploy&.type }) + data = { + site: @site.id, + deploy: deploy&.type, + log: deploy&.build_stats&.last&.log + } + + ExceptionNotifier.notify_exception(exception, data: data) end def deploy_local diff --git a/app/jobs/gitlab_notifier_job.rb b/app/jobs/gitlab_notifier_job.rb index 129697ba..701c6789 100644 --- a/app/jobs/gitlab_notifier_job.rb +++ b/app/jobs/gitlab_notifier_job.rb @@ -112,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 @@ -159,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] From 6bac8ed65dbb413715631a9477bbd2abc038f8b3 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 13 Mar 2023 20:11:12 -0300 Subject: [PATCH 18/21] fix: agrupar por sitio y enviar el log --- app/jobs/deploy_job.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index b411568e..961f8d69 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -33,12 +33,14 @@ class DeployJob < ApplicationJob # No es opcional unless @deployed[:deploy_local][:status] # Hacer fallar la tarea - raise DeployException, 'Falló la compilación' + raise DeployException, "#{@site.name}: Falló la compilación" end deploy_others - rescue DeployException => e + rescue DeployTimedOutException => e notify_exception e + rescue DeployException => e + notify_exception e, deploy_local ensure @site&.update status: 'waiting' From 222cc8f62656486c08d6f48e1e3a95c164053f4d Mon Sep 17 00:00:00 2001 From: f Date: Tue, 14 Mar 2023 16:45:39 -0300 Subject: [PATCH 19/21] fix: volver a traducir los correos #9941 --- app/mailers/deploy_mailer.rb | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/app/mailers/deploy_mailer.rb b/app/mailers/deploy_mailer.rb index aeb13676..7d939940 100644 --- a/app/mailers/deploy_mailer.rb +++ b/app/mailers/deploy_mailer.rb @@ -18,46 +18,46 @@ class DeployMailer < ApplicationMailer subject = t('.subject', site: site.name) hostname = site.hostname - @hi = t('.hi') - @explanation = t('.explanation', fqdn: hostname) - @help = t('.help') - - @headers = %w[type status url seconds size].map do |header| - t(".th.#{header}") - end - - @table = deploys.each_pair.map do |deploy, value| - { - title: t(".#{deploy}.title"), - status: t(".#{deploy}.#{value[:status] ? 'success' : 'error'}"), - urls: value[:urls], - seconds: { - human: distance_of_time_in_words(value[:seconds].seconds), - machine: "PT#{value[:seconds]}S" - }, - size: number_to_human_size(value[:size], precision: 2) - } - end - - @terminal_table = Terminal::Table.new do |t| - t << @headers - t.add_separator - @table.each do |row| - row[:urls].each do |url| - t << (row.map do |k, v| - case k - when :seconds then v[:human] - when :urls then url - else v - end - end) - end - 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 + @hi = t('.hi') + @explanation = t('.explanation', fqdn: hostname) + @help = t('.help') + + @headers = %w[type status url seconds size].map do |header| + t(".th.#{header}") + end + + @table = deploys.each_pair.map do |deploy, value| + { + title: t(".#{deploy}.title"), + status: t(".#{deploy}.#{value[:status] ? 'success' : 'error'}"), + urls: value[:urls], + seconds: { + human: distance_of_time_in_words(value[:seconds].seconds), + machine: "PT#{value[:seconds]}S" + }, + size: number_to_human_size(value[:size], precision: 2) + } + end + + @terminal_table = Terminal::Table.new do |t| + t << @headers + t.add_separator + @table.each do |row| + row[:urls].each do |url| + t << (row.map do |k, v| + case k + when :seconds then v[:human] + when :urls then url + else v + end + end) + end + end + end + mail(to: usuarie.email, reply_to: "sutty@#{Site.domain}", subject: subject) end end From 77e209ac9704185fad57271df9a5f058e0583f4e Mon Sep 17 00:00:00 2001 From: f Date: Tue, 14 Mar 2023 19:23:17 -0300 Subject: [PATCH 20/21] fix: traducir el asunto #9941 --- app/mailers/deploy_mailer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/mailers/deploy_mailer.rb b/app/mailers/deploy_mailer.rb index 7d939940..25efb18d 100644 --- a/app/mailers/deploy_mailer.rb +++ b/app/mailers/deploy_mailer.rb @@ -15,12 +15,13 @@ class DeployMailer < ApplicationMailer def deployed(deploys) usuarie = Usuarie.find(params[:usuarie]) site = usuarie.sites.find(params[:site]) - 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 + subject = t('.subject', site: site.name) + @hi = t('.hi') @explanation = t('.explanation', fqdn: hostname) @help = t('.help') From 1496a6f04bb6ce3c0842bb1791057ee91ce8d1f7 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 23 Mar 2023 11:59:27 -0300 Subject: [PATCH 21/21] fix: a veces no se puede deployear nada closes ##12735 closes ##12733 closes ##12722 closes ##12719 closes ##12716 closes ##10417 --- app/mailers/deploy_mailer.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/mailers/deploy_mailer.rb b/app/mailers/deploy_mailer.rb index 25efb18d..b7b464cb 100644 --- a/app/mailers/deploy_mailer.rb +++ b/app/mailers/deploy_mailer.rb @@ -12,10 +12,11 @@ class DeployMailer < ApplicationMailer include ActionView::Helpers::DateHelper # rubocop:disable Metrics/AbcSize - def deployed(deploys) + def deployed(deploys = {}) usuarie = Usuarie.find(params[:usuarie]) site = usuarie.sites.find(params[:site]) hostname = site.hostname + deploys ||= {} # Informamos a cada quien en su idioma y damos una dirección de # respuesta porque a veces les usuaries nos escriben