5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 06:36:22 +00:00
panel/app/jobs/deploy_job.rb

62 lines
1.5 KiB
Ruby
Raw Normal View History

2019-07-26 00:36:33 +00:00
# frozen_string_literal: true
# Realiza el deploy de un sitio
2019-09-16 16:44:29 +00:00
class DeployJob < ApplicationJob
class DeployException < StandardError; end
# rubocop:disable Metrics/MethodLength
2021-04-11 19:45:26 +00:00
def perform(site, notify = true)
2019-09-18 19:28:30 +00:00
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'
2019-09-18 19:28:30 +00:00
# Asegurarse que DeployLocal sea el primero!
@deployed = { deploy_local: deploy_locally }
2019-07-26 00:36:33 +00:00
2019-09-18 19:28:30 +00:00
# No es opcional
unless @deployed[:deploy_local]
@site.update status: 'waiting'
2021-04-11 19:45:26 +00:00
notify_usuaries if notify
2020-01-24 15:12:49 +00:00
# Hacer fallar la tarea
raise DeployException, deploy_local.build_stats.last.log
2019-09-18 19:28:30 +00:00
end
2019-07-26 00:36:33 +00:00
deploy_others
2021-04-11 19:45:26 +00:00
notify_usuaries if notify
@site.update status: 'waiting'
2019-09-18 19:28:30 +00:00
end
2019-07-26 00:36:33 +00:00
end
# rubocop:enable Metrics/MethodLength
2019-07-26 00:36:33 +00:00
private
def deploy_local
@deploy_local ||= @site.deploys.find_by(type: 'DeployLocal')
end
def deploy_locally
deploy_local.deploy
2019-07-26 00:36:33 +00:00
end
def deploy_others
@site.deploys.where.not(type: 'DeployLocal').find_each do |d|
@deployed[d.type.underscore.to_sym] = d.deploy
2019-07-26 00:36:33 +00:00
end
end
def notify_usuaries
2020-04-06 22:03:49 +00:00
@site.roles.where(rol: 'usuarie', temporal: false).pluck(:usuarie_id).each do |usuarie|
DeployMailer.with(usuarie: usuarie, site: @site.id)
.deployed(@deployed)
2019-07-26 00:36:33 +00:00
.deliver_now
end
end
end