Class: Wip::StagingProgress
- Inherits:
-
Object
- Object
- Wip::StagingProgress
- Defined in:
- lib/wip/staging_progress.rb
Overview
Prints a self-overwriting "copying build context files: N/total" line, at most every half second, while a slow, silent step (staging a large build context file by file can take tens of seconds) is still moving — so it doesn't read as hung.
Instance Method Summary collapse
-
#finish ⇒ Object
Idempotent: a caller can't know in advance whether tick ever fired.
-
#initialize(out: $stderr, interval: 0.5) ⇒ StagingProgress
constructor
A new instance of StagingProgress.
- #tick(count, total) ⇒ Object
Constructor Details
#initialize(out: $stderr, interval: 0.5) ⇒ StagingProgress
Returns a new instance of StagingProgress.
9 10 11 12 13 14 15 16 |
# File 'lib/wip/staging_progress.rb', line 9 def initialize(out: $stderr, interval: 0.5) @out = out @interval = interval # Backdated so the very first tick always prints immediately, rather # than waiting a full interval before the first sign of life. @last = Process.clock_gettime(Process::CLOCK_MONOTONIC) - interval @printed = false end |
Instance Method Details
#finish ⇒ Object
Idempotent: a caller can't know in advance whether tick ever fired.
28 29 30 31 32 33 |
# File 'lib/wip/staging_progress.rb', line 28 def finish return unless @printed @printed = false @out.puts end |
#tick(count, total) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/wip/staging_progress.rb', line 18 def tick(count, total) now = Process.clock_gettime(Process::CLOCK_MONOTONIC) return if now - @last < @interval && count != total @last = now @printed = true @out.print "\rwip: copying build context files: #{count}/#{total}" end |