progressrus 0.0.2 → 0.0.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
  SHA1:
3
- metadata.gz: da06f31d91136e8fb18839704dd7fd49950de7ca
4
- data.tar.gz: fb38d959dd85e11e03004db451ac17dced021f14
3
+ metadata.gz: 7742b5cfd79039be1c56599ef54db97ff88c65ca
4
+ data.tar.gz: 6dc36accb4003983466de0d90a9a34abb1a567ea
5
5
  SHA512:
6
- metadata.gz: 5fd4c0fd5e258a5723f24494d234eef4d3ac451d5fb98b29855196fd029a7cfef2a335c7cbcd1df72235e49e57a95aaed107e05182e492d1a4f19530c0794071
7
- data.tar.gz: 95bbe8161d40db2e10976aece2dc7b89584109b2eaf471d4f695cf03c0f77fb21d42c50cc055a924c08651d31306e5f17e4cc3df489a1bc1af419eca33101ffb
6
+ metadata.gz: 232a6041d91f72852c02ff376a0a08681b31ec583a00baeeac5e1be8c7296a88f22fb741d51996a11877607dcd0f9674ba6179802b552f1b7932d5c77e1617e8
7
+ data.tar.gz: 36ddb938cd4ccb27522082e0c5f397ceac5edce0f960a7c056fc82b2386aa187599621cf55dcc1f9dea52e5e0f70ae09ab20bc5c16bb6eba0842e241950f43ca
data/lib/progressrus.rb CHANGED
@@ -149,8 +149,14 @@ class Progressrus
149
149
  end
150
150
 
151
151
  private
152
+
152
153
  def persist(force: false)
153
- stores.each { |store| store.persist(self, force: force) }
154
+ stores.each do |store|
155
+ begin
156
+ store.persist(self, force: force)
157
+ rescue Progressrus::Store::BackendError => e
158
+ end
159
+ end
154
160
  end
155
161
 
156
162
  def parse_time(time)
@@ -1,6 +1,7 @@
1
1
  class Progressrus
2
2
  class Store
3
3
  class NotImplementedError < StandardError; end
4
+ class BackendError < StandardError; end
4
5
 
5
6
  class Base
6
7
  def persist(progress)
@@ -1,6 +1,8 @@
1
1
  class Progressrus
2
2
  class Store
3
3
  class Redis < Base
4
+ BACKEND_EXCEPTIONS = [ ::Redis::BaseError ]
5
+
4
6
  attr_reader :redis, :interval, :persisted_at, :prefix, :name
5
7
 
6
8
  def initialize(instance, prefix: "progressrus", interval: 1, now: Time.now)
@@ -16,6 +18,8 @@ class Progressrus
16
18
  redis.hset(key(progress.scope), progress.id, progress.to_serializeable.to_json)
17
19
  @persisted_ats[progress.scope][progress.id] = now
18
20
  end
21
+ rescue *BACKEND_EXCEPTIONS => e
22
+ raise Progressrus::Store::BackendError.new(e)
19
23
  end
20
24
 
21
25
  def scope(scope)
@@ -23,6 +27,8 @@ class Progressrus
23
27
  scope.each_pair { |id, value|
24
28
  scope[id] = Progressrus.new(deserialize(value))
25
29
  }
30
+ rescue *BACKEND_EXCEPTIONS => e
31
+ raise Progressrus::Store::BackendError.new(e)
26
32
  end
27
33
 
28
34
  def find(scope, id)
@@ -30,6 +36,8 @@ class Progressrus
30
36
  return unless value
31
37
 
32
38
  Progressrus.new(deserialize(value))
39
+ rescue *BACKEND_EXCEPTIONS => e
40
+ raise Progressrus::Store::BackendError.new(e)
33
41
  end
34
42
 
35
43
  def flush(scope, id = nil)
@@ -38,9 +46,12 @@ class Progressrus
38
46
  else
39
47
  redis.del(key(scope))
40
48
  end
49
+ rescue *BACKEND_EXCEPTIONS => e
50
+ raise Progressrus::Store::BackendError.new(e)
41
51
  end
42
52
 
43
53
  private
54
+
44
55
  def key(scope)
45
56
  "#{prefix}:#{scope.join(":")}"
46
57
  end
@@ -1,3 +1,3 @@
1
1
  class Progressrus
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -192,6 +192,13 @@ class ProgressrusTest < Minitest::Unit::TestCase
192
192
  @progress.tick
193
193
  end
194
194
 
195
+ def test_tick_and_complete_dont_raise_if_store_is_unavailable
196
+ store = Progressrus.stores.first
197
+ store.redis.expects(:hset).at_least_once.raises(::Redis::BaseError)
198
+ @progress.tick
199
+ @progress.complete
200
+ end
201
+
195
202
  def test_should_not_be_able_to_initialize_with_total_0
196
203
  assert_raises ArgumentError do
197
204
  Progressrus.new(total: 0)
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.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Eskildsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-09 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis