wslc-wip 0.17.3 → 0.17.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c00368614ae5c01c7f514957368d9533f2faf9be114cfd17c676fc70ebfec138
4
- data.tar.gz: 86d094ead585366c91633a963d0436a0c68af10f5bda3dace5ab46485f714a4a
3
+ metadata.gz: 0c7d06fb49766e980be92c2d70d3a0c86dc68b16c0c2b5d84e05d5baa1dd40f1
4
+ data.tar.gz: 61ad143b173b17849427d03efdaa451849b0e58d16a3eb97c55855d641ced273
5
5
  SHA512:
6
- metadata.gz: 99cd7c6e59ccd6b64667ab7a179c240d96577f24296a93b801484f994570d6262ccc30d1535853a6cd7b4fb2a31f5e8145fa227aa637d7d9960f0aa794756a67
7
- data.tar.gz: 13a319d2b312f709a5937711bb65d69a560e098bed809e3f5f76fc83bae419983f5f4dbb0ae541e5afa3c93b9a7fd290b9c963378b6f405cd4bb0ceb3900e274
6
+ metadata.gz: c1accaef0df664f9d35659d08cb8782c1e54ea9a56cae60e1bd53ddd347c2736501e1fc785be9667541c225f88340e448fd8b2fab32a4f41171f613863533ea4
7
+ data.tar.gz: 235f4c9ad2997138d262eaac4098edfe0582db8bf56dc8743250a17d10fac14df96fdea3ab575faef91f096e4f091ad2a1ffb06931da59aa5e683eaf40327c03
@@ -14,9 +14,8 @@ module Wip
14
14
  @ignore = ignore || DockerIgnore.load(@root.join('.dockerignore'))
15
15
  end
16
16
 
17
- # on_progress fires once per file copied, as `|count, total|` — so a caller
18
- # can show that staging a large context (thousands of small files can take
19
- # tens of seconds) is still moving instead of looking hung.
17
+ # on_progress fires before copying and after each file, as `|count, total|`,
18
+ # so a caller can report elapsed progress even while copying one large file.
20
19
  def stage(on_progress: nil)
21
20
  return yield @root.to_s if @ignore.empty?
22
21
 
@@ -30,6 +29,7 @@ module Wip
30
29
 
31
30
  def copy_included_files(destination, on_progress)
32
31
  files = included_files
32
+ on_progress&.call(0, files.size)
33
33
  files.each_with_index do |relative_path, index|
34
34
  target = destination.join(relative_path)
35
35
  FileUtils.mkdir_p(target.dirname)
@@ -1,35 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wip
4
- # Prints a self-overwriting "copying build context files: N/total" line, at
5
- # most every half second, while a slow, silent step (staging a large build
6
- # context file by file can take tens of seconds) is still moving so it
7
- # doesn't read as hung.
4
+ # Prints a self-overwriting "copying build context files: N/total" line
5
+ # every half second while a slow, silent step is running. Reporting runs on
6
+ # its own thread so a single large file does not make progress appear hung.
8
7
  class StagingProgress
9
8
  def initialize(out: $stderr, interval: 0.5)
10
9
  @out = out
11
10
  @interval = interval
12
- # Backdated so the very first tick always prints immediately, rather
13
- # than waiting a full interval before the first sign of life.
14
- @last = Process.clock_gettime(Process::CLOCK_MONOTONIC) - interval
15
- @printed = false
11
+ @mutex = Mutex.new
12
+ @condition = ConditionVariable.new
13
+ @worker = nil
14
+ @stopped = false
16
15
  end
17
16
 
18
17
  def tick(count, total)
19
- now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
20
- return if now - @last < @interval && count != total
21
-
22
- @last = now
23
- @printed = true
24
- @out.print "\rwip: copying build context files: #{count}/#{total}"
18
+ @mutex.synchronize do
19
+ @count = count
20
+ @total = total
21
+ print_progress if @worker.nil? || count == total
22
+ unless @worker
23
+ @stopped = false
24
+ @worker = Thread.new { report_on_interval }
25
+ end
26
+ end
25
27
  end
26
28
 
27
29
  # Idempotent: a caller can't know in advance whether tick ever fired.
28
30
  def finish
29
- return unless @printed
31
+ worker = @mutex.synchronize do
32
+ return unless @worker
33
+
34
+ @stopped = true
35
+ @condition.broadcast
36
+ @worker
37
+ end
38
+ worker.join
39
+
40
+ @mutex.synchronize do
41
+ @worker = nil
42
+ @out.puts
43
+ @out.flush
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def report_on_interval
50
+ @mutex.synchronize do
51
+ until @stopped
52
+ @condition.wait(@mutex, @interval)
53
+ print_progress unless @stopped
54
+ end
55
+ end
56
+ end
30
57
 
31
- @printed = false
32
- @out.puts
58
+ def print_progress
59
+ @out.print "\rwip: copying build context files: #{@count}/#{@total}"
60
+ @out.flush
33
61
  end
34
62
  end
35
63
  end
data/lib/wip/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wip
4
- VERSION = '0.17.3'
4
+ VERSION = '0.17.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wslc-wip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.3
4
+ version: 0.17.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wip contributors