From a58936b22ecc2e70903c89d8dcf8e501d00f6642 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 10 Apr 2023 13:28:32 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20retomar=20la=20publicaci=C3=B3n=20de=20c?= =?UTF-8?q?ambios=20#12958?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/deploy_job.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/jobs/deploy_job.rb b/app/jobs/deploy_job.rb index aeb0f4b6..a7f59afb 100644 --- a/app/jobs/deploy_job.rb +++ b/app/jobs/deploy_job.rb @@ -4,9 +4,23 @@ class DeployJob < ApplicationJob class DeployException < StandardError; end class DeployTimedOutException < DeployException; end + class DeployAlreadyRunningException < DeployException; end discard_on ActiveRecord::RecordNotFound + # Lanzar lo antes posible + self.priority = 10 + # Intentar dentro de un minuto + self.retry_interval = 60 + + def handle_error(error) + case error + when DeployAlreadyRunningException then retry_in 1.minute + when DeployTimedOutException then expire + else super + end + end + # rubocop:disable Metrics/MethodLength def perform(site, notify: true, time: Time.now, output: false) @output = output @@ -20,14 +34,14 @@ class DeployJob < ApplicationJob # Como el trabajo actual se aplaza al siguiente, arrastrar la # hora original para poder ir haciendo timeouts. if @site.building? + notify = false + if 10.minutes.ago >= time - notify = false raise DeployTimedOutException, "#{@site.name} la tarea estuvo más de 10 minutos esperando, volviendo al estado original" + else + raise DeployAlreadyRunningException end - - DeployJob.perform_in(60, site, notify: notify, time: time, output: output) - return end @deployed = {} @@ -67,8 +81,6 @@ class DeployJob < ApplicationJob t << ([type.to_s] + row.values) end end) - rescue DeployTimedOutException => e - notify_exception e ensure if @site.present? @site.update status: 'waiting'