feedx 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ad83b2f9b53fb7574dc5bb90b39e9157a0f6f3bdbcc08065935cf9ffd97bb4f
4
- data.tar.gz: d8e41fb163afd5d9b301b064a2f437ba8ebfb8850bcb3fd1e3497045c9c46a2e
3
+ metadata.gz: a1ed7080e3ec08c76cba3676907b7946b72e3611a8abd32a7f61dcd0cb0df29a
4
+ data.tar.gz: f4d4aaa22f712c3c3e333c95e3a7b702ea2ceef7c4f7277aa8c26a6f474764ad
5
5
  SHA512:
6
- metadata.gz: 54a9d0f4269c11533576abedd48fc8180fc0de67d0e5d8008f5d82074a200ea2ba0644039ffd8dda6f4495956224e62f20410243da303911ed11dfa563dec10a
7
- data.tar.gz: 9f9a46443a06d5f1d5ef95144414b90a5163db8086fc56b6a81d934fc1dc0f9df8ed33289cc4fbadb8ec06c4f065401106d35ed414c2a055395f6ca02cff52f2
6
+ metadata.gz: 02a12dd77a8c89fe9f549d1bea0d2de675df7e39d67ea1b5c47edc64e6e9a03710b062c948e5c1a9842c6f54fc5b848177355a65be7a6eebfd15710931e05ba2
7
+ data.tar.gz: a61d6510fa25780f2a8157a18e5a73196c502b6d1ac792c1d0e11030d09bffb45f5a1ebb0decbfed74419c7f77c72f3d3bf2393237fe64fb0e98443647a4b3af
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- feedx (0.5.2)
4
+ feedx (0.5.3)
5
5
  bfs (>= 0.3.4)
6
6
 
7
7
  GEM
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'feedx'
3
- s.version = '0.5.2'
3
+ s.version = '0.5.3'
4
4
  s.authors = ['Black Square Media Ltd']
5
5
  s.email = ['info@blacksquaremedia.com']
6
6
  s.summary = %(Exchange data between components via feeds)
data/go.mod CHANGED
@@ -7,5 +7,5 @@ require (
7
7
  github.com/onsi/ginkgo v1.8.0
8
8
  github.com/onsi/gomega v1.5.0
9
9
  golang.org/x/net v0.0.0-20190514140710-3ec191127204 // indirect
10
- golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f // indirect
10
+ golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 // indirect
11
11
  )
data/go.sum CHANGED
@@ -126,8 +126,8 @@ golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5h
126
126
  golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
127
127
  golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
128
128
  golang.org/x/sys v0.0.0-20190429094411-2cc0cad0ac78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
129
- golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f h1:Xab8gg26GrI/x3RNdVhVkHHM1XLyGeRBEvz4Q5x4YW8=
130
- golang.org/x/sys v0.0.0-20190514135907-3a4b5fb9f71f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
129
+ golang.org/x/sys v0.0.0-20190515120540-06a5c4944438 h1:khxRGsvPk4n2y8I/mLLjp7e5dMTJmH75wvqS6nMwUtY=
130
+ golang.org/x/sys v0.0.0-20190515120540-06a5c4944438/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
131
131
  golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
132
132
  golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
133
133
  golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -19,6 +19,10 @@ type ProducerOptions struct {
19
19
  // Default: 1m
20
20
  Interval time.Duration
21
21
 
22
+ // LastModCheck this function will be called before each push attempt
23
+ // to dynamically determine the last modified time.
24
+ LastModCheck func(context.Context) (time.Time, error)
25
+
22
26
  // AfterPush callbacks are triggered after each push cycle, receiving
23
27
  // an error (if occurred).
24
28
  AfterPush func(error)
@@ -117,12 +121,20 @@ func (p *Producer) Close() error {
117
121
  }
118
122
 
119
123
  func (p *Producer) push() error {
120
- now := timestampFromTime(time.Now()).Millis()
121
- defer func() {
122
- atomic.StoreInt64(&p.lastPush, now)
123
- }()
124
+ start := time.Now()
125
+ atomic.StoreInt64(&p.lastPush, timestampFromTime(start).Millis())
126
+
127
+ wopt := p.opt.WriterOptions
128
+ wopt.LastMod = start
129
+ if p.opt.LastModCheck != nil {
130
+ modTime, err := p.opt.LastModCheck(p.ctx)
131
+ if err != nil {
132
+ return err
133
+ }
134
+ wopt.LastMod = modTime
135
+ }
124
136
 
125
- writer, err := NewWriter(p.ctx, p.remote, &p.opt.WriterOptions)
137
+ writer, err := NewWriter(p.ctx, p.remote, &wopt)
126
138
  if err != nil {
127
139
  return err
128
140
  }
@@ -141,7 +153,7 @@ func (p *Producer) push() error {
141
153
  }
142
154
 
143
155
  atomic.StoreInt64(&p.numWritten, int64(writer.NumWritten()))
144
- atomic.StoreInt64(&p.lastMod, now)
156
+ atomic.StoreInt64(&p.lastMod, timestampFromTime(wopt.LastMod).Millis())
145
157
  return nil
146
158
  }
147
159
 
@@ -15,11 +15,9 @@ var _ = Describe("Producer", func() {
15
15
  var obj *bfs.Object
16
16
  var ctx = context.Background()
17
17
 
18
- BeforeEach(func() {
19
- obj = bfs.NewInMemObject("path/to/file.jsonz")
20
-
18
+ setup := func(o *feedx.ProducerOptions) {
21
19
  var err error
22
- subject, err = feedx.NewProducerForRemote(ctx, obj, nil, func(enc feedx.FormatPureEncoder) error {
20
+ subject, err = feedx.NewProducerForRemote(ctx, obj, o, func(enc feedx.FormatPureEncoder) error {
23
21
  for i := 0; i < 10; i++ {
24
22
  fix := fixture
25
23
  if err := enc.Encode(&fix); err != nil {
@@ -29,16 +27,43 @@ var _ = Describe("Producer", func() {
29
27
  return nil
30
28
  })
31
29
  Expect(err).NotTo(HaveOccurred())
30
+ }
31
+
32
+ BeforeEach(func() {
33
+ obj = bfs.NewInMemObject("path/to/file.jsonz")
32
34
  })
33
35
 
34
36
  AfterEach(func() {
35
- Expect(subject.Close()).To(Succeed())
37
+ if subject != nil {
38
+ Expect(subject.Close()).To(Succeed())
39
+ }
36
40
  })
37
41
 
38
42
  It("should produce", func() {
43
+ setup(nil)
44
+
39
45
  Expect(subject.LastPush()).To(BeTemporally("~", time.Now(), time.Second))
40
- Expect(subject.LastModified()).To(Equal(subject.LastPush()))
46
+ Expect(subject.LastModified()).To(BeTemporally("~", time.Now(), time.Second))
41
47
  Expect(subject.NumWritten()).To(Equal(10))
42
48
  Expect(subject.Close()).To(Succeed())
49
+
50
+ info, err := obj.Head(ctx)
51
+ Expect(err).NotTo(HaveOccurred())
52
+ Expect(info.Size).To(BeNumerically("~", 75, 10))
53
+ })
54
+
55
+ It("should produce with custom last-mod check", func() {
56
+ setup(&feedx.ProducerOptions{
57
+ LastModCheck: func(_ context.Context) (time.Time, error) { return time.Unix(1515151515, 0), nil },
58
+ })
59
+
60
+ Expect(subject.LastPush()).To(BeTemporally("~", time.Now(), time.Second))
61
+ Expect(subject.LastModified()).To(Equal(time.Unix(1515151515, 0)))
62
+ Expect(subject.NumWritten()).To(Equal(10))
63
+
64
+ info, err := obj.Head(ctx)
65
+ Expect(err).NotTo(HaveOccurred())
66
+ Expect(info.Size).To(BeNumerically("~", 75, 10))
67
+ Expect(info.Metadata).To(HaveKeyWithValue("x-feedx-last-modified", "1515151515000"))
43
68
  })
44
69
  })
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-14 00:00:00.000000000 Z
11
+ date: 2019-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bfs