mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 19:26:21 +00:00
feat: generar el sitio en orden #10464
This commit is contained in:
parent
607f19f680
commit
e5f96c435d
6 changed files with 48 additions and 56 deletions
|
@ -30,28 +30,30 @@ class DeployJob < ApplicationJob
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@deployed = {}
|
||||||
@site.update status: 'building'
|
@site.update status: 'building'
|
||||||
# Asegurarse que DeployLocal sea el primero!
|
@site.deployment_list.each do |d|
|
||||||
@deployed = {
|
begin
|
||||||
deploy_local: {
|
raise DeployException, 'Una dependencia falló' if failed_dependencies? d
|
||||||
status: deploy_locally,
|
|
||||||
seconds: deploy_local.build_stats.last.seconds,
|
status = d.deploy
|
||||||
size: deploy_local.size,
|
seconds = d.build_stats.last.try(:seconds)
|
||||||
urls: [deploy_local.url]
|
rescue StandardError => e
|
||||||
|
status = false
|
||||||
|
seconds = 0
|
||||||
|
|
||||||
|
notify_exception e, d
|
||||||
|
end
|
||||||
|
|
||||||
|
@deployed[d.type.underscore.to_sym] = {
|
||||||
|
status: status,
|
||||||
|
seconds: seconds || 0,
|
||||||
|
size: d.size,
|
||||||
|
urls: d.respond_to?(:urls) ? d.urls : [d.url].compact
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
# No es opcional
|
|
||||||
unless @deployed[:deploy_local][:status]
|
|
||||||
# Hacer fallar la tarea
|
|
||||||
raise DeployException, "#{@site.name}: Falló la compilación"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
deploy_others
|
|
||||||
rescue DeployTimedOutException => e
|
rescue DeployTimedOutException => e
|
||||||
notify_exception e
|
notify_exception e
|
||||||
rescue DeployException => e
|
|
||||||
notify_exception e, deploy_local
|
|
||||||
ensure
|
ensure
|
||||||
@site&.update status: 'waiting'
|
@site&.update status: 'waiting'
|
||||||
|
|
||||||
|
@ -62,47 +64,37 @@ class DeployJob < ApplicationJob
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Detecta si un método de publicación tiene dependencias fallidas
|
||||||
|
#
|
||||||
|
# @param :deploy [Deploy]
|
||||||
|
# @return [Boolean]
|
||||||
|
def failed_dependencies?(deploy)
|
||||||
|
failed_dependencies(deploy).present?
|
||||||
|
end
|
||||||
|
|
||||||
|
# Obtiene las dependencias fallidas de un deploy
|
||||||
|
#
|
||||||
|
# @param :deploy [Deploy]
|
||||||
|
# @return [Array]
|
||||||
|
def failed_dependencies(deploy)
|
||||||
|
deploy.class::DEPENDENCIES & (@deployed.reject do |_, v|
|
||||||
|
v[:status]
|
||||||
|
end.keys)
|
||||||
|
end
|
||||||
|
|
||||||
# @param :exception [StandardError]
|
# @param :exception [StandardError]
|
||||||
# @param :deploy [Deploy]
|
# @param :deploy [Deploy]
|
||||||
def notify_exception(exception, deploy = nil)
|
def notify_exception(exception, deploy = nil)
|
||||||
data = {
|
data = {
|
||||||
site: @site.id,
|
site: @site.id,
|
||||||
deploy: deploy&.type,
|
deploy: deploy&.type,
|
||||||
log: deploy&.build_stats&.last&.log
|
log: deploy&.build_stats&.last&.log,
|
||||||
|
failed_dependencies: (failed_dependencies(deploy) if deploy)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExceptionNotifier.notify_exception(exception, data: data)
|
ExceptionNotifier.notify_exception(exception, data: data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy_local
|
|
||||||
@deploy_local ||= @site.deploys.find_by(type: 'DeployLocal')
|
|
||||||
end
|
|
||||||
|
|
||||||
def deploy_locally
|
|
||||||
deploy_local.deploy(output: @output)
|
|
||||||
end
|
|
||||||
|
|
||||||
def deploy_others
|
|
||||||
@site.deploys.where.not(type: 'DeployLocal').find_each do |d|
|
|
||||||
begin
|
|
||||||
status = d.deploy(output: @output)
|
|
||||||
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: seconds || 0,
|
|
||||||
size: d.size,
|
|
||||||
urls: d.respond_to?(:urls) ? d.urls : [d.url].compact
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def notify_usuaries
|
def notify_usuaries
|
||||||
@site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id).each do |usuarie|
|
@site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id).each do |usuarie|
|
||||||
DeployMailer.with(usuarie: usuarie, site: @site.id)
|
DeployMailer.with(usuarie: usuarie, site: @site.id)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
class DeployAlternativeDomain < Deploy
|
class DeployAlternativeDomain < Deploy
|
||||||
store :values, accessors: %i[hostname], coder: JSON
|
store :values, accessors: %i[hostname], coder: JSON
|
||||||
|
|
||||||
DEPENDENCIES = %i[local]
|
DEPENDENCIES = %i[deploy_local]
|
||||||
|
|
||||||
# Generar un link simbólico del sitio principal al alternativo
|
# Generar un link simbólico del sitio principal al alternativo
|
||||||
def deploy(**)
|
def deploy(**)
|
||||||
|
|
|
@ -6,11 +6,11 @@ class DeployRsync < Deploy
|
||||||
store :values, accessors: %i[destination host_keys], coder: JSON
|
store :values, accessors: %i[destination host_keys], coder: JSON
|
||||||
|
|
||||||
DEPENDENCIES = %i[
|
DEPENDENCIES = %i[
|
||||||
alternative_domain
|
deploy_alternative_domain
|
||||||
hidden_service
|
deploy_hidden_service
|
||||||
local
|
deploy_local
|
||||||
www
|
deploy_www
|
||||||
zip
|
deploy_zip
|
||||||
]
|
]
|
||||||
|
|
||||||
def deploy(output: false)
|
def deploy(output: false)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
class DeployWww < Deploy
|
class DeployWww < Deploy
|
||||||
store :values, accessors: %i[], coder: JSON
|
store :values, accessors: %i[], coder: JSON
|
||||||
|
|
||||||
DEPENDENCIES = %i[local]
|
DEPENDENCIES = %i[deploy_local]
|
||||||
|
|
||||||
before_destroy :remove_destination!
|
before_destroy :remove_destination!
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ require 'zip'
|
||||||
class DeployZip < Deploy
|
class DeployZip < Deploy
|
||||||
store :values, accessors: %i[], coder: JSON
|
store :values, accessors: %i[], coder: JSON
|
||||||
|
|
||||||
DEPENDENCIES = %i[local]
|
DEPENDENCIES = %i[deploy_local]
|
||||||
|
|
||||||
# Una vez que el sitio está generado, tomar todos los archivos y
|
# Una vez que el sitio está generado, tomar todos los archivos y
|
||||||
# y generar un zip accesible públicamente.
|
# y generar un zip accesible públicamente.
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Site
|
||||||
|
|
||||||
deploys.each do |deploy|
|
deploys.each do |deploy|
|
||||||
deploy.class::DEPENDENCIES.each do |dependency|
|
deploy.class::DEPENDENCIES.each do |dependency|
|
||||||
deploys.where(type: "Deploy#{dependency.to_s.classify}").each do |deploy_dependency|
|
deploys.where(type: dependency.to_s.classify).each do |deploy_dependency|
|
||||||
graph.add_edge deploy_dependency, deploy
|
graph.add_edge deploy_dependency, deploy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue