5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-14 05:42:19 +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) @gems_dir ||= Rails.root.join('_storage', 'gems', site.name)
end end
# Corre un comando y devuelve true si terminó correctamente # Corre un comando, lo registra en la base de datos y devuelve el
# rubocop:disable Metrics/MethodLength # estado.
#
# @param [String]
# @return [Boolean]
def run(cmd) 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 r = nil
lines = []
time_start time_start
Dir.chdir(site.path) do Dir.chdir(site.path) do
Open3.popen2e(env, cmd, unsetenv_others: true) do |_, o, t| Open3.popen2e(env, cmd, unsetenv_others: true) do |_, o, t|
r = t.value 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
end end
time_stop time_stop
stat.seconds = time_spent_in_seconds build_stats.create action: readable_cmd(cmd),
stat.bytes = size log: lines.join,
stat.save seconds: time_spent_in_seconds,
bytes: size,
status: r&.success?
r&.success? r&.success?
end end
# rubocop:enable Metrics/MethodLength
private
# @param [String]
# @return [String]
def readable_cmd(cmd)
cmd.split(' -', 2).first.tr(' ', '_')
end
end end

View file

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