progressrus 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: e9443b1b626649e1d9e17aa2ed9ef9354312bc78
4
- data.tar.gz: 4e9bd7b04d2f47975bfc9bbfa96f36ced10e3ccf
3
+ metadata.gz: 1b088dbba839ff6037add109dc9e9a9ea52074a4
4
+ data.tar.gz: 67204fed60013d7b12819474868562766fe17d41
5
5
  SHA512:
6
- metadata.gz: f8093bed5b344ff65be4f5bc8b0ec207eb1984c4fb7f45ea629e0c6d7306f2a6fbfc0cf645bd7d73940b3ec8368ffb87235edac040c2805fe28c0113d70b9908
7
- data.tar.gz: 71e0a98fc087451ad400f72c16d3c461873a93c75ba27ec90231dae1610ecc5b724e346603a51b06f6de64889360dc9769e441d3dec69c7130ff7500a8d38b49
6
+ metadata.gz: 7599e3adfaa638985adccd88c2acf4fbccca9f90e5bc5d2ac7262cd9a9fd4982d94916f031df244a236e31e75685f97b29a7ae7501fe7c978e032f932fb82106
7
+ data.tar.gz: af39e6cc6e04afa0c2bcd491dc23876586f278e439b8fd6ca44ae3b010c8136996ee0cd712b98dd4c93cfd1671db89466fa78973c5e8e878b07ae1d733b00b82
@@ -40,7 +40,7 @@ class Progressrus
40
40
  def initialize(scope: "progressrus", total: nil, name: nil,
41
41
  id: SecureRandom.uuid, params: {}, stores: Progressrus.stores,
42
42
  completed_at: nil, started_at: nil, count: 0, failed_at: nil,
43
- error_count: 0, persist: false, expires_at: nil)
43
+ error_count: 0, persist: false, expires_at: nil, persisted: false)
44
44
 
45
45
  raise ArgumentError, "Total cannot be negative." if total && total < 0
46
46
 
@@ -57,6 +57,7 @@ class Progressrus
57
57
  @completed_at = parse_time(completed_at)
58
58
  @failed_at = parse_time(failed_at)
59
59
  @expires_at = parse_time(expires_at)
60
+ @persisted = persisted
60
61
 
61
62
  persist(force: true) if persist
62
63
  end
@@ -122,6 +123,8 @@ class Progressrus
122
123
  def total=(new_total)
123
124
  raise ArgumentError, "Total cannot be negative." if new_total < 0
124
125
  @total = new_total
126
+ persist(force: true) if persisted?
127
+ @total
125
128
  end
126
129
 
127
130
  def total
@@ -153,6 +156,10 @@ class Progressrus
153
156
  expires_at && expires_at < now
154
157
  end
155
158
 
159
+ def persisted?
160
+ @persisted
161
+ end
162
+
156
163
  private
157
164
 
158
165
  def persist(force: false)
@@ -162,6 +169,7 @@ class Progressrus
162
169
  rescue Progressrus::Store::BackendError => e
163
170
  end
164
171
  end
172
+ @persisted = true
165
173
  end
166
174
 
167
175
  def parse_time(time)
@@ -63,7 +63,7 @@ class Progressrus
63
63
  end
64
64
 
65
65
  def deserialize(value)
66
- JSON.parse(value, symbolize_names: true)
66
+ JSON.parse(value, symbolize_names: true).merge(persisted: true)
67
67
  end
68
68
 
69
69
  def outdated?(progress, now: Time.now)
@@ -1,3 +1,3 @@
1
1
  class Progressrus
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -21,6 +21,14 @@ class IntegrationTest < Minitest::Test
21
21
  assert_equal 1, tick.count
22
22
  end
23
23
 
24
+ def test_setting_total_after_persist_persists_total
25
+ progress = Progressrus.new(scope: ["walrus"], total: 0, persist: true, id: '123')
26
+ assert_equal 0, progress.total
27
+ progress.total = 20
28
+ progress = Progressrus.find(["walrus"], '123')
29
+ assert_equal 20, progress.total
30
+ end
31
+
24
32
  def test_create_multiple_ticks_and_see_them_in_redis
25
33
  @progress.tick
26
34
 
@@ -38,12 +38,14 @@ class RedisStoreTest < Minitest::Test
38
38
  end
39
39
 
40
40
  def test_scope_should_return_progressruses_indexed_by_id
41
- @store.persist(@progress)
42
- @store.persist(@another_progress)
43
- actual = @store.scope(@scope)
41
+ @store.persist(@progress)
42
+ @store.persist(@another_progress)
43
+ actual = @store.scope(@scope)
44
44
 
45
- assert_equal @progress.id, actual['oemg'].id
46
- assert_equal @another_progress.id, actual['oemg-two'].id
45
+ assert_equal @progress.id, actual['oemg'].id
46
+ assert actual['oemg'].persisted?
47
+ assert_equal @another_progress.id, actual['oemg-two'].id
48
+ assert actual['oemg-two'].persisted?
47
49
  end
48
50
 
49
51
  def test_scope_should_return_an_empty_hash_if_nothing_is_found
@@ -51,9 +53,10 @@ class RedisStoreTest < Minitest::Test
51
53
  end
52
54
 
53
55
  def test_find_should_return_a_single_progressrus_for_scope_and_id
54
- @store.persist(@progress)
55
-
56
- assert_equal @progress.id, @store.find(@scope, 'oemg').id
56
+ @store.persist(@progress)
57
+ stored_progress = @store.find(@scope, 'oemg')
58
+ assert_equal @progress.id, stored_progress.id
59
+ assert stored_progress.persisted?
57
60
  end
58
61
 
59
62
  def test_find_should_return_nil_if_nothing_is_found
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-08 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.2.3
189
+ rubygems_version: 2.6.10
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Monitor the progress of remote, long-running jobs.