Class: KamalBackup::CommandOutput
- Inherits:
-
Object
- Object
- KamalBackup::CommandOutput
- Defined in:
- lib/kamal_backup/command.rb
Instance Method Summary collapse
- #command_exit(context, status) ⇒ Object
- #command_output(context, _stream, data, redactor:) ⇒ Object
- #command_start(spec, redactor:) ⇒ Object
- #info(message, redactor:) ⇒ Object
-
#initialize(io: $stdout) ⇒ CommandOutput
constructor
A new instance of CommandOutput.
Constructor Details
#initialize(io: $stdout) ⇒ CommandOutput
Returns a new instance of CommandOutput.
30 31 32 33 34 |
# File 'lib/kamal_backup/command.rb', line 30 def initialize(io: $stdout) @io = io @mutex = Mutex.new @buffers = {} end |
Instance Method Details
#command_exit(context, status) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/kamal_backup/command.rb', line 62 def command_exit(context, status) runtime = Process.clock_gettime(Process::CLOCK_MONOTONIC) - context.fetch(:started_at) result = status.to_i.zero? ? "successful" : "failed" synchronize do flush_output_buffers(context) @io.puts(" INFO [#{context.fetch(:id)}] Finished in #{format("%.3f seconds", runtime)} with exit status #{status} (#{result}).") end end |
#command_output(context, _stream, data, redactor:) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/kamal_backup/command.rb', line 51 def command_output(context, _stream, data, redactor:) raw = data.to_s return if raw.empty? synchronize do key = [context.fetch(:id), _stream] @buffers[key] = "#{@buffers[key]}#{raw}" flush_complete_output_lines(context, key, redactor: redactor) end end |
#command_start(spec, redactor:) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kamal_backup/command.rb', line 40 def command_start(spec, redactor:) id = SecureRandom.hex(4) started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) display = spec.display(redactor) write_line(" INFO [#{id}] Running #{display} locally") write_line(" DEBUG [#{id}] Command: #{display}") { id: id, started_at: started_at, redactor: redactor } end |
#info(message, redactor:) ⇒ Object
36 37 38 |
# File 'lib/kamal_backup/command.rb', line 36 def info(, redactor:) write_line(" INFO #{redactor.redact_string()}") end |