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
|
2019-07-26 00:36:33 +00:00
|
|
|
def perform(site)
|
2019-09-18 19:28:30 +00:00
|
|
|
ActiveRecord::Base.connection_pool.with_connection do
|
|
|
|
site = Site.find(site)
|
|
|
|
site.update_attribute :status, 'building'
|
|
|
|
# Asegurarse que DeployLocal sea el primero!
|
|
|
|
deployed = { deploy_local: deploy_local(site) }
|
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_attribute :status, 'waiting'
|
|
|
|
raise
|
|
|
|
end
|
2019-07-26 00:36:33 +00:00
|
|
|
|
2019-09-18 19:28:30 +00:00
|
|
|
deploy_others site, deployed
|
|
|
|
notify_usuaries site, deployed
|
2019-07-26 01:11:01 +00:00
|
|
|
|
2019-09-18 19:28:30 +00:00
|
|
|
site.update_attribute :status, 'waiting'
|
|
|
|
end
|
2019-07-26 00:36:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def deploy_local(site)
|
|
|
|
site.deploys.find_by(type: 'DeployLocal').deploy
|
|
|
|
end
|
|
|
|
|
|
|
|
def deploy_others(site, deployed)
|
|
|
|
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)
|
|
|
|
# TODO: existe site.usuaries_ids?
|
|
|
|
site.usuaries.find_each do |usuarie|
|
|
|
|
DeployMailer.with(usuarie: usuarie.id, site: site.id)
|
|
|
|
.deployed(deployed)
|
|
|
|
.deliver_now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|