filewatch-ext 1.0.0 → 1.1.0
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 +4 -4
- data/lib/filewatch/ext/progress_tail.rb +19 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c2f601c3875a6526e3d94d73a160d4a2c5345e0
|
4
|
+
data.tar.gz: 66a06cf9f623d99c0c3c93f5965ed5b8b51a5bbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4ff38b663a5b97fa4846aece1a924792229e655eb9201c73e201a61a66cfd37438553b67a5015bc45376fce4b040d67754b1bf7ad2b08644a5aaa3741769f32
|
7
|
+
data.tar.gz: 9d3bff0679f839020dc8babd8e3eb1915dad0823ceba2d3d2db4a6713d8d0e6a954186480b06fec40227b5e797cef81689ccde25e53e3a57c9fafe2a7d8da187
|
@@ -4,6 +4,13 @@ module FileWatch
|
|
4
4
|
module Ext
|
5
5
|
class ProgressTail < FileWatch::ObservingTail
|
6
6
|
|
7
|
+
public
|
8
|
+
def initialize(opts={})
|
9
|
+
super
|
10
|
+
@opts[:progress_write_interval] = 500 unless @opts.include?(:progress_write_interval)
|
11
|
+
@progress_last_write = 0
|
12
|
+
end
|
13
|
+
|
7
14
|
private
|
8
15
|
def observe_read_file(watched_file, listener)
|
9
16
|
changed = false
|
@@ -11,15 +18,24 @@ module FileWatch
|
|
11
18
|
begin
|
12
19
|
data = watched_file.file_read(32768)
|
13
20
|
changed = true
|
21
|
+
|
14
22
|
watched_file.buffer_extract(data).each do |line|
|
15
|
-
listener.accept(line)
|
16
23
|
@sincedb[watched_file.inode] += (line.bytesize + @delimiter_byte_size)
|
24
|
+
size = watched_file.filestat.size
|
25
|
+
pos = @sincedb[watched_file.inode]
|
26
|
+
|
27
|
+
now = Time.now.to_f
|
28
|
+
delta = now - @progress_last_write
|
29
|
+
if delta * 1000 >= @opts[:progress_write_interval] or size == pos
|
30
|
+
listener.accept(line, size, pos)
|
31
|
+
@progress_last_write = now
|
32
|
+
else
|
33
|
+
listener.accept(line, nil, nil)
|
34
|
+
end
|
17
35
|
end
|
18
36
|
# watched_file bytes_read tracks the sincedb entry
|
19
37
|
# see TODO in watch.rb
|
20
38
|
watched_file.update_bytes_read(@sincedb[watched_file.inode])
|
21
|
-
|
22
|
-
_progressdb_send(watched_file, listener)
|
23
39
|
rescue EOFError
|
24
40
|
listener.eof
|
25
41
|
watched_file.unwatch if @opts[:eof_close]
|
@@ -45,17 +61,6 @@ module FileWatch
|
|
45
61
|
end
|
46
62
|
end # def _read_file
|
47
63
|
|
48
|
-
|
49
|
-
private
|
50
|
-
def _progressdb_send watched_file, listener
|
51
|
-
path = watched_file.path
|
52
|
-
sincedb_key = watched_file.inode
|
53
|
-
stat = watched_file.filestat
|
54
|
-
|
55
|
-
line = [sincedb_key, stat.size, @sincedb[sincedb_key]].flatten.join(" ")
|
56
|
-
|
57
|
-
listener.progress(line)
|
58
|
-
end
|
59
64
|
end # module ProgressTail
|
60
65
|
end # module Ext
|
61
66
|
end # module FileWatch
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filewatch-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Signify
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filewatch
|