5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 14:31:42 +00:00

feat: guardar un log y mostrarlo en output también

This commit is contained in:
f 2023-02-08 17:08:02 -03:00
parent 975bf39c2e
commit 4e1f14a528
2 changed files with 40 additions and 6 deletions

View file

@ -22,19 +22,32 @@ class DeployDistributedPress < Deploy
# @param :output [Bool]
# @return [Bool]
def deploy
status = false
log = []
time_start
status = false
site_client.tap do |c|
stdout = Thread.new(publisher.logger_out) do |io|
until io.eof?
line = io.gets
puts line if output
log << line
end
end
update remote_info: c.show(publishing_site).to_h
status = c.publish(publishing_site, deploy_local.destination)
publisher.logger.close
stdout.join
end
time_stop
create_stat! status
create_stat! status, log.join
status
end
@ -95,9 +108,10 @@ class DeployDistributedPress < Deploy
# Registra lo que sucedió
#
# @param status [Bool]
# @param log [String]
# @return [nil]
def create_stat!(status)
build_stats.create action: publisher.to_s, seconds: time_spent_in_seconds, bytes: size, status: status
def create_stat!(status, log)
build_stats.create action: publisher.to_s,log: log, seconds: time_spent_in_seconds, bytes: size, status: status
nil
end
end

View file

@ -8,6 +8,11 @@ class DistributedPressPublisher < ApplicationRecord
# Cifrar la información del token en la base de datos
has_encrypted :token
# La salida del log
#
# @return [IO]
attr_reader :logger_out
# La instancia es única
validates_uniqueness_of :instance
@ -27,7 +32,7 @@ class DistributedPressPublisher < ApplicationRecord
#
# @return [DistributedPress::V1::Client]
def client
@client ||= DistributedPress::V1::Client.new(url: instance, token: token)
@client ||= DistributedPress::V1::Client.new(url: instance, token: token, logger: logger)
end
# @return [String]
@ -35,8 +40,23 @@ class DistributedPressPublisher < ApplicationRecord
"Distributed Press <#{instance}>"
end
# @return [Logger]
def logger
@logger ||=
begin
@logger_out, @logger_in = IO.pipe
::Logger.new @logger_in, formatter: formatter
end
end
private
def formatter
@formatter ||= lambda do |_, _, _, msg|
"#{msg}\n"
end
end
# Actualiza o desactiva la fecha de vencimiento a partir de la
# información del token.
#