5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 23:36:21 +00:00
panel/app/workers/deploy_worker.rb

45 lines
1.1 KiB
Ruby

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