From b880cdea36c16516cc01fa604bc56b59567cf943 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 25 Sep 2019 19:34:39 -0300 Subject: [PATCH] =?UTF-8?q?informar=20cuando=20falla=20la=20generaci=C3=B3?= =?UTF-8?q?n=20del=20sitio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 45 ++++++++++++++++++++++++------------------ app/models/deploy.rb | 2 +- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index de50bd1..608b485 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -2,43 +2,50 @@ # Realiza el deploy de un sitio class DeployJob < ApplicationJob + class DeployException < StandardError; end + + # rubocop:disable Metrics/MethodLength def perform(site) ActiveRecord::Base.connection_pool.with_connection do - site = Site.find(site) - site.update_attribute :status, 'building' + @site = Site.find(site) + @site.update_attribute :status, 'building' # Asegurarse que DeployLocal sea el primero! - deployed = { deploy_local: deploy_local(site) } + @deployed = { deploy_local: deploy_locally } # No es opcional - unless deployed[:deploy_local] - site.update_attribute :status, 'waiting' - raise + unless @deployed[:deploy_local] + @site.update_attribute :status, 'waiting' + raise DeployException, deploy_local.build_stats.last.log end - deploy_others site, deployed - notify_usuaries site, deployed - - site.update_attribute :status, 'waiting' + deploy_others + notify_usuaries + @site.update_attribute :status, 'waiting' end end + # rubocop:enable Metrics/MethodLength private - def deploy_local(site) - site.deploys.find_by(type: 'DeployLocal').deploy + def deploy_local + @deploy_local ||= @site.deploys.find_by(type: 'DeployLocal') end - def deploy_others(site, deployed) - site.deploys.where.not(type: 'DeployLocal').find_each do |d| - deployed[d.type.underscore.to_sym] = d.deploy + def deploy_locally + deploy_local.deploy + end + + def deploy_others + @site.deploys.where.not(type: 'DeployLocal').find_each do |d| + @deployed[d.type.underscore.to_sym] = d.deploy end end - def notify_usuaries(site, deployed) + def notify_usuaries # TODO: existe site.usuaries_ids? - site.usuaries.find_each do |usuarie| - DeployMailer.with(usuarie: usuarie.id, site: site.id) - .deployed(deployed) + @site.usuaries.find_each do |usuarie| + DeployMailer.with(usuarie: usuarie.id, site: @site.id) + .deployed(@deployed) .deliver_now end end diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 81e47e4..6f1f737 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -65,7 +65,7 @@ class Deploy < ApplicationRecord stat.bytes = size stat.save - r.try :exited? + r.try :success? end # rubocop:enable Metrics/MethodLength end