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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d90286860b0a7594c9cdc2207024afa543e060c
4
- data.tar.gz: ef489fbfa4c8c4eb55ca5d0d6e48b9f369823e6c
3
+ metadata.gz: 45f0614036153baf8ab262ed0edb1a72b9833a02
4
+ data.tar.gz: 942e60bbb01bce170e36634253d21c0629cf73e1
5
5
  SHA512:
6
- metadata.gz: def16c19e043e1cc52b66832512e93a289d69ba8bd8364f59f5276151d7450afc427b58915e4f873e5443d8da855ff889581fe2e9847d2317be9727dacade246
7
- data.tar.gz: 103d09310207b8dd001f34bcdb444021ad8952130835a9546ae67a7f72f75711e5f118c86855748cc27a1ed0c5f4fc648d6a11bbe75136efd7ae55bdaa2c2c97
6
+ metadata.gz: 7461c41ad4b4138fbf2ff7501117cf8717a3aad1af94aa974be043611e188bb0d811c3edc10af88a0618d984aa28c1671b1db5d21774da76fef50791e1f61c34
7
+ data.tar.gz: a6504d9ff2c5fbfbcfddf90c9ac7488760b359eda1a441364f5beb31ec97de09c3e3263bd368f56c2e00ef8837b07e423a82ea1971883c6ce93970591eae55ac
@@ -52,7 +52,15 @@ class WorkBatcher
52
52
  end
53
53
 
54
54
  def add(work_object)
55
- add_multiple([work_object])
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
- @processor.call(@queue.values)
139
+ queue_copy = @queue.values
132
140
  else
133
- @processor.call(@queue.dup)
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)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'work_batcher'
3
- s.version = '1.0.0'
3
+ s.version = '1.0.1'
4
4
  s.summary = 'Library for batching work'
5
5
  s.description = 'Library for batching work.'
6
6
  s.email = 'info@phusion.nl'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_batcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hongli Lai