work_batcher 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/work_batcher.rb +14 -3
- data/work_batcher.gemspec +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: 45f0614036153baf8ab262ed0edb1a72b9833a02
|
4
|
+
data.tar.gz: 942e60bbb01bce170e36634253d21c0629cf73e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7461c41ad4b4138fbf2ff7501117cf8717a3aad1af94aa974be043611e188bb0d811c3edc10af88a0618d984aa28c1671b1db5d21774da76fef50791e1f61c34
|
7
|
+
data.tar.gz: a6504d9ff2c5fbfbcfddf90c9ac7488760b359eda1a441364f5beb31ec97de09c3e3263bd368f56c2e00ef8837b07e423a82ea1971883c6ce93970591eae55ac
|
data/lib/work_batcher.rb
CHANGED
@@ -52,7 +52,15 @@ class WorkBatcher
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def add(work_object)
|
55
|
-
|
55
|
+
@mutex.synchronize do
|
56
|
+
if @deduplicate
|
57
|
+
key = @deduplicator.call(work_object)
|
58
|
+
@queue[key] = work_object
|
59
|
+
else
|
60
|
+
@queue << work_object
|
61
|
+
end
|
62
|
+
schedule_processing
|
63
|
+
end
|
56
64
|
end
|
57
65
|
|
58
66
|
def add_multiple(work_objects)
|
@@ -128,12 +136,15 @@ private
|
|
128
136
|
|
129
137
|
def process_queue
|
130
138
|
if @deduplicate
|
131
|
-
@
|
139
|
+
queue_copy = @queue.values
|
132
140
|
else
|
133
|
-
@
|
141
|
+
queue_copy = @queue.dup
|
134
142
|
end
|
135
143
|
@processed += @queue.size
|
136
144
|
@queue.clear
|
145
|
+
@executor.post do
|
146
|
+
@processor.call(queue_copy)
|
147
|
+
end
|
137
148
|
end
|
138
149
|
|
139
150
|
def default_deduplicator(work_object)
|
data/work_batcher.gemspec
CHANGED