2019-07-26 00:36:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Realiza el deploy de un sitio
|
|
|
|
class DeployWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform(site)
|
|
|
|
site = Site.find(site)
|
2019-07-26 01:11:01 +00:00
|
|
|
site.update_attribute :status, 'building'
|
2019-07-26 00:36:33 +00:00
|
|
|
# Asegurarse que DeployLocal sea el primero!
|
|
|
|
deployed = { deploy_local: deploy_local(site) }
|
|
|
|
|
|
|
|
# No es opcional
|
2019-07-26 01:11:01 +00:00
|
|
|
unless deployed[:deploy_local]
|
|
|
|
site.update_attribute :status, 'waiting'
|
|
|
|
raise
|
|
|
|
end
|
2019-07-26 00:36:33 +00:00
|
|
|
|
|
|
|
deploy_others site, deployed
|
|
|
|
notify_usuaries site, deployed
|
2019-07-26 01:11:01 +00:00
|
|
|
|
|
|
|
site.update_attribute :status, 'waiting'
|
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
|