fake_go_up 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fake_go_up/task.rb +12 -16
- data/lib/fake_go_up/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8abfd9b0f85dd9abf41d8027f25307a97ebd294f
|
4
|
+
data.tar.gz: f35e2d685e67d2b205ca3b72c73cc5f523d34504
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a2edb9edbf3defef8f41a8979306a708a1ae88928632a9e3d6fc0907e1d5925013cd985d218d329d3e9dd23bf702ce3bf5585cd549a5968eaeb9b5fbc0017f9
|
7
|
+
data.tar.gz: e999f3460f3fee43400f7d522c59b6c978795ae37d8b9ce20f73589769b9425103a633980990739b90c76bcb205a8675085942c5e3e9afba10167f447ba52d8b
|
data/lib/fake_go_up/task.rb
CHANGED
@@ -4,8 +4,8 @@ module FakeGoUp
|
|
4
4
|
attr_reader :cur_step
|
5
5
|
|
6
6
|
MAX_INTERVAL = 24 * 60 * 60
|
7
|
-
|
8
|
-
|
7
|
+
@max_fake_count = 20
|
8
|
+
@interval = 1
|
9
9
|
@@subclass = []
|
10
10
|
|
11
11
|
def initialize
|
@@ -21,7 +21,7 @@ module FakeGoUp
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def go_up
|
24
|
-
return unless self.cur_step % self.interval == 0
|
24
|
+
return unless self.cur_step % self.class.interval == 0
|
25
25
|
FakeGoUp.redis.hkeys(self.class.hash_key).each do |field|
|
26
26
|
go_up_one_field(field)
|
27
27
|
end
|
@@ -30,7 +30,7 @@ module FakeGoUp
|
|
30
30
|
|
31
31
|
def go_up_one_field(field)
|
32
32
|
remain_count = FakeGoUp.redis.hget(self.class.hash_key, field).to_i
|
33
|
-
fake_count = rand(
|
33
|
+
fake_count = rand(self.class.max_fake_count)
|
34
34
|
if remain_count < fake_count
|
35
35
|
fake_count = remain_count
|
36
36
|
FakeGoUp.redis.hdel(self.class.hash_key, field)
|
@@ -48,23 +48,11 @@ module FakeGoUp
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def interval
|
52
|
-
@@interval
|
53
|
-
end
|
54
|
-
|
55
51
|
def next_step
|
56
52
|
@cur_step = (@cur_step + 1) % MAX_INTERVAL
|
57
53
|
end
|
58
54
|
|
59
55
|
class << self
|
60
|
-
def interval(i)
|
61
|
-
@@interval = i
|
62
|
-
end
|
63
|
-
|
64
|
-
def max_fake_count(count)
|
65
|
-
@@max_fake_count = count
|
66
|
-
end
|
67
|
-
|
68
56
|
def queue_up(item, count)
|
69
57
|
field = item_to_field(item)
|
70
58
|
FakeGoUp.redis.hset(self.hash_key, field, count)
|
@@ -75,6 +63,14 @@ module FakeGoUp
|
|
75
63
|
FakeGoUp.redis.hget(self.hash_key, field).to_i
|
76
64
|
end
|
77
65
|
|
66
|
+
def interval
|
67
|
+
@interval
|
68
|
+
end
|
69
|
+
|
70
|
+
def max_fake_count
|
71
|
+
@max_fake_count
|
72
|
+
end
|
73
|
+
|
78
74
|
def running?(item)
|
79
75
|
field = item_to_field(item)
|
80
76
|
FakeGoUp.redis.hkeys(self.hash_key).include?(field)
|
data/lib/fake_go_up/version.rb
CHANGED