mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-14 17:11:41 +00:00
39eb584a97
esto evita que se espamee el botón de publicar
61 lines
1.5 KiB
Ruby
61 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# Realiza el deploy de un sitio
|
|
class DeployJob < ApplicationJob
|
|
class DeployException < StandardError; end
|
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
def perform(site, notify = true)
|
|
ActiveRecord::Base.connection_pool.with_connection do
|
|
@site = Site.find(site)
|
|
|
|
# Si ya hay una tarea corriendo, aplazar esta
|
|
if @site.building?
|
|
DeployJob.perform_in(60, site, notify)
|
|
return
|
|
end
|
|
|
|
@site.update status: 'building'
|
|
# Asegurarse que DeployLocal sea el primero!
|
|
@deployed = { deploy_local: deploy_locally }
|
|
|
|
# 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
|
|
notify_usuaries if notify
|
|
@site.update status: 'waiting'
|
|
end
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
private
|
|
|
|
def deploy_local
|
|
@deploy_local ||= @site.deploys.find_by(type: 'DeployLocal')
|
|
end
|
|
|
|
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.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id).each do |usuarie|
|
|
DeployMailer.with(usuarie: usuarie, site: @site.id)
|
|
.deployed(@deployed)
|
|
.deliver_now
|
|
end
|
|
end
|
|
end
|