mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 02:21:42 +00:00
informar cuando falla la generación del sitio
This commit is contained in:
parent
5c3bdbe4ee
commit
b880cdea36
2 changed files with 27 additions and 20 deletions
|
@ -2,43 +2,50 @@
|
||||||
|
|
||||||
# Realiza el deploy de un sitio
|
# Realiza el deploy de un sitio
|
||||||
class DeployJob < ApplicationJob
|
class DeployJob < ApplicationJob
|
||||||
|
class DeployException < StandardError; end
|
||||||
|
|
||||||
|
# rubocop:disable Metrics/MethodLength
|
||||||
def perform(site)
|
def perform(site)
|
||||||
ActiveRecord::Base.connection_pool.with_connection do
|
ActiveRecord::Base.connection_pool.with_connection do
|
||||||
site = Site.find(site)
|
@site = Site.find(site)
|
||||||
site.update_attribute :status, 'building'
|
@site.update_attribute :status, 'building'
|
||||||
# Asegurarse que DeployLocal sea el primero!
|
# Asegurarse que DeployLocal sea el primero!
|
||||||
deployed = { deploy_local: deploy_local(site) }
|
@deployed = { deploy_local: deploy_locally }
|
||||||
|
|
||||||
# No es opcional
|
# No es opcional
|
||||||
unless deployed[:deploy_local]
|
unless @deployed[:deploy_local]
|
||||||
site.update_attribute :status, 'waiting'
|
@site.update_attribute :status, 'waiting'
|
||||||
raise
|
raise DeployException, deploy_local.build_stats.last.log
|
||||||
end
|
end
|
||||||
|
|
||||||
deploy_others site, deployed
|
deploy_others
|
||||||
notify_usuaries site, deployed
|
notify_usuaries
|
||||||
|
@site.update_attribute :status, 'waiting'
|
||||||
site.update_attribute :status, 'waiting'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# rubocop:enable Metrics/MethodLength
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def deploy_local(site)
|
def deploy_local
|
||||||
site.deploys.find_by(type: 'DeployLocal').deploy
|
@deploy_local ||= @site.deploys.find_by(type: 'DeployLocal')
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_others(site, deployed)
|
def deploy_locally
|
||||||
site.deploys.where.not(type: 'DeployLocal').find_each do |d|
|
deploy_local.deploy
|
||||||
deployed[d.type.underscore.to_sym] = d.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
|
||||||
end
|
end
|
||||||
|
|
||||||
def notify_usuaries(site, deployed)
|
def notify_usuaries
|
||||||
# TODO: existe site.usuaries_ids?
|
# TODO: existe site.usuaries_ids?
|
||||||
site.usuaries.find_each do |usuarie|
|
@site.usuaries.find_each do |usuarie|
|
||||||
DeployMailer.with(usuarie: usuarie.id, site: site.id)
|
DeployMailer.with(usuarie: usuarie.id, site: @site.id)
|
||||||
.deployed(deployed)
|
.deployed(@deployed)
|
||||||
.deliver_now
|
.deliver_now
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -65,7 +65,7 @@ class Deploy < ApplicationRecord
|
||||||
stat.bytes = size
|
stat.bytes = size
|
||||||
stat.save
|
stat.save
|
||||||
|
|
||||||
r.try :exited?
|
r.try :success?
|
||||||
end
|
end
|
||||||
# rubocop:enable Metrics/MethodLength
|
# rubocop:enable Metrics/MethodLength
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue