mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 15:46:21 +00:00
Merge branch 'timeout-deploys' into 'rails'
Cancelar la tarea pendiente si tomó mas de 10 minutos See merge request sutty/sutty!51
This commit is contained in:
commit
35ca1ee91c
1 changed files with 17 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue