sutty/app/workers/deploy_worker.rb

40 lines
924 B
Ruby
Raw Normal View History

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)
# 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