mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 04:21:41 +00:00
40 lines
924 B
Ruby
40 lines
924 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
# Realiza el deploy de un sitio
|
||
|
class DeployWorker
|
||
|
include Sidekiq::Worker
|
||
|
|
||
|
def perform(site)
|
||
|
site = Site.find(site)
|
||
|
# Asegurarse que DeployLocal sea el primero!
|
||
|
deployed = { deploy_local: deploy_local(site) }
|
||
|
|
||
|
# No es opcional
|
||
|
raise unless deployed[:deploy_local]
|
||
|
|
||
|
deploy_others site, deployed
|
||
|
notify_usuaries site, deployed
|
||
|
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
|