5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-05-17 06:00:48 +00:00

registrar si falló la compilación. no colgar la io.

This commit is contained in:
f 2021-04-14 13:09:03 -03:00
parent 1d8eda67a9
commit f3ed882ca4
3 changed files with 34 additions and 14 deletions

View file

@ -43,29 +43,43 @@ class Deploy < ApplicationRecord
@gems_dir ||= Rails.root.join('_storage', 'gems', site.name)
end
# Corre un comando y devuelve true si terminó correctamente
# rubocop:disable Metrics/MethodLength
# Corre un comando, lo registra en la base de datos y devuelve el
# estado.
#
# @param [String]
# @return [Boolean]
def run(cmd)
# XXX: prestar atención a la concurrencia de sqlite3, se podría
# enviar los datos directamente a una API para que se manejen desde
# el proceso principal de rails y evitar problemas.
stat = build_stats.build action: cmd.split(' -', 2).first.tr(' ', '_')
r = nil
lines = []
time_start
Dir.chdir(site.path) do
Open3.popen2e(env, cmd, unsetenv_others: true) do |_, o, t|
r = t.value
stat.log = o.read
# XXX: Tenemos que leer línea por línea porque en salidas largas
# se cuelga la IO
# TODO: Enviar a un websocket para ver el proceso en vivo?
o.each do |line|
lines << line
end
end
end
time_stop
stat.seconds = time_spent_in_seconds
stat.bytes = size
stat.save
build_stats.create action: readable_cmd(cmd),
log: lines.join,
seconds: time_spent_in_seconds,
bytes: size,
status: r&.success?
r&.success?
end
# rubocop:enable Metrics/MethodLength
private
# @param [String]
# @return [String]
def readable_cmd(cmd)
cmd.split(' -', 2).first.tr(' ', '_')
end
end

View file

@ -57,8 +57,6 @@ class DeployLocal < Deploy
{
'HOME' => home_dir,
'PATH' => paths.join(':'),
'SPREE_API_KEY' => site.tienda_api_key,
'SPREE_URL' => site.tienda_url,
'AIRBRAKE_PROJECT_ID' => site.id.to_s,
'AIRBRAKE_PROJECT_KEY' => site.airbrake_api_key,
'JEKYLL_ENV' => Rails.env,
@ -94,7 +92,7 @@ class DeployLocal < Deploy
end
def jekyll_build
run %(bundle exec jekyll build --trace --destination "#{escaped_destination}")
run %(bundle exec jekyll build --trace --profile --destination "#{escaped_destination}")
end
# no debería haber espacios ni caracteres especiales, pero por si

View file

@ -0,0 +1,8 @@
# frozen_string_literal: true
# Registra el estado de las compilaciones
class AddStatusToBuildStats < ActiveRecord::Migration[6.1]
def change
add_column :build_stats, :status, :boolean, default: false
end
end