progressrus 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/progressrus.rb +8 -2
- data/lib/progressrus/version.rb +1 -1
- data/test/progressrus_test.rb +33 -1
- 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: da06f31d91136e8fb18839704dd7fd49950de7ca
|
4
|
+
data.tar.gz: fb38d959dd85e11e03004db451ac17dced021f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fd4c0fd5e258a5723f24494d234eef4d3ac451d5fb98b29855196fd029a7cfef2a335c7cbcd1df72235e49e57a95aaed107e05182e492d1a4f19530c0794071
|
7
|
+
data.tar.gz: 95bbe8161d40db2e10976aece2dc7b89584109b2eaf471d4f695cf03c0f77fb21d42c50cc055a924c08651d31306e5f17e4cc3df489a1bc1af419eca33101ffb
|
data/lib/progressrus.rb
CHANGED
@@ -28,7 +28,7 @@ class Progressrus
|
|
28
28
|
end
|
29
29
|
|
30
30
|
attr_reader :name, :scope, :total, :id, :params, :store, :count,
|
31
|
-
:started_at, :completed_at, :failed_at, :stores, :error_count
|
31
|
+
:started_at, :completed_at, :failed_at, :expires_at, :stores, :error_count
|
32
32
|
|
33
33
|
alias_method :completed?, :completed_at
|
34
34
|
alias_method :started?, :started_at
|
@@ -39,7 +39,7 @@ class Progressrus
|
|
39
39
|
def initialize(scope: "progressrus", total: nil, name: nil,
|
40
40
|
id: SecureRandom.uuid, params: {}, stores: Progressrus.stores,
|
41
41
|
completed_at: nil, started_at: nil, count: 0, failed_at: nil,
|
42
|
-
error_count: 0, persist: false)
|
42
|
+
error_count: 0, persist: false, expires_at: nil)
|
43
43
|
|
44
44
|
raise ArgumentError, "Total cannot be zero or negative." if total && total <= 0
|
45
45
|
|
@@ -55,6 +55,7 @@ class Progressrus
|
|
55
55
|
@started_at = parse_time(started_at)
|
56
56
|
@completed_at = parse_time(completed_at)
|
57
57
|
@failed_at = parse_time(failed_at)
|
58
|
+
@expires_at = parse_time(expires_at)
|
58
59
|
|
59
60
|
persist(force: true) if persist
|
60
61
|
end
|
@@ -109,6 +110,7 @@ class Progressrus
|
|
109
110
|
started_at: started_at,
|
110
111
|
completed_at: completed_at,
|
111
112
|
failed_at: failed_at,
|
113
|
+
expires_at: expires_at,
|
112
114
|
count: count,
|
113
115
|
total: total,
|
114
116
|
params: params,
|
@@ -142,6 +144,10 @@ class Progressrus
|
|
142
144
|
now + seconds_to_finished
|
143
145
|
end
|
144
146
|
|
147
|
+
def expired?(now: Time.now)
|
148
|
+
expires_at && expires_at < now
|
149
|
+
end
|
150
|
+
|
145
151
|
private
|
146
152
|
def persist(force: false)
|
147
153
|
stores.each { |store| store.persist(self, force: force) }
|
data/lib/progressrus/version.rb
CHANGED
data/test/progressrus_test.rb
CHANGED
@@ -152,7 +152,8 @@ class ProgressrusTest < Minitest::Unit::TestCase
|
|
152
152
|
completed_at: nil,
|
153
153
|
failed_at: nil,
|
154
154
|
count: 0,
|
155
|
-
error_count: 0
|
155
|
+
error_count: 0,
|
156
|
+
expires_at: nil
|
156
157
|
}
|
157
158
|
|
158
159
|
assert_equal serialization, progress.to_serializeable
|
@@ -374,4 +375,35 @@ class ProgressrusTest < Minitest::Unit::TestCase
|
|
374
375
|
|
375
376
|
assert @progress.running?
|
376
377
|
end
|
378
|
+
|
379
|
+
def test_expired_returns_false_when_nil
|
380
|
+
progress = Progressrus.new(
|
381
|
+
id: 'oemg',
|
382
|
+
scope: ['walruses', 'forall']
|
383
|
+
)
|
384
|
+
|
385
|
+
refute progress.expired?
|
386
|
+
end
|
387
|
+
|
388
|
+
def test_expired_returns_true_if_expires_at_in_past
|
389
|
+
time = Time.now
|
390
|
+
progress = Progressrus.new(
|
391
|
+
id: 'oemg',
|
392
|
+
scope: ['walruses', 'forall'],
|
393
|
+
expires_at: time - 3600
|
394
|
+
)
|
395
|
+
|
396
|
+
assert progress.expired?(now: time)
|
397
|
+
end
|
398
|
+
|
399
|
+
def test_expired_returns_false_if_expires_at_in_the_future
|
400
|
+
time = Time.now
|
401
|
+
progress = Progressrus.new(
|
402
|
+
id: 'oemg',
|
403
|
+
scope: ['walruses', 'forall'],
|
404
|
+
expires_at: time + 3600
|
405
|
+
)
|
406
|
+
|
407
|
+
refute progress.expired?(now: time)
|
408
|
+
end
|
377
409
|
end
|
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.
|
4
|
+
version: 0.0.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:
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|