From d456feac8e70418f52c962e82a40b58559858a4e Mon Sep 17 00:00:00 2001 From: f Date: Thu, 29 Jul 2021 14:46:29 -0300 Subject: [PATCH] =?UTF-8?q?Cancelar=20la=20tarea=20pendiente=20si=20tom?= =?UTF-8?q?=C3=B3=20mas=20de=2010=20minutos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si la tarea se reintentó durante 10 minutos, lo más probable es que haya quedado trabada en algún lado. Este cambio permite volver a compilar sitios al cambiar el estado a espera y cancelarse a sí misma. --- app/jobs/deploy_job.rb | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index f1ceca9..70997ce 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -5,13 +5,23 @@ class DeployJob < ApplicationJob class DeployException < StandardError; end # rubocop:disable Metrics/MethodLength - def perform(site, notify = true) + def perform(site, notify = true, time = Time.now) ActiveRecord::Base.connection_pool.with_connection do @site = Site.find(site) - # Si ya hay una tarea corriendo, aplazar esta + # Si ya hay una tarea corriendo, aplazar esta. Si estuvo + # esperando más de 10 minutos, recuperar el estado anterior. + # + # Como el trabajo actual se aplaza al siguiente, arrastrar la + # hora original para poder ir haciendo timeouts. if @site.building? - DeployJob.perform_in(60, site, notify) + if 10.minutes.ago >= time + @site.update status: 'waiting' + raise DeployException, + "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" + end + + DeployJob.perform_in(60, site, notify, time) return end @@ -29,8 +39,11 @@ class DeployJob < ApplicationJob end deploy_others - notify_usuaries if notify + + # Volver a la espera @site.update status: 'waiting' + + notify_usuaries if notify end end # rubocop:enable Metrics/MethodLength