3
3
from threading import Thread , Lock , Event
4
4
from multiprocessing import cpu_count
5
5
from six import PY2
6
+
7
+ from riak .riak_object import RiakObject
8
+ from riak .ts_object import TsObject
9
+
6
10
if PY2 :
7
11
from Queue import Queue
8
12
else :
20
24
POOL_SIZE = 6
21
25
22
26
#: A :class:`namedtuple` for tasks that are fed to workers in the
23
- #: multi pool.
24
- Task = namedtuple (
25
- 'Task' ,
26
- ['client' , 'outq' ,
27
- 'bucket_type' , 'bucket' , 'key' ,
28
- 'object' , 'options' ])
27
+ #: multi get pool.
28
+ Task = namedtuple ('Task' ,
29
+ ['client' , 'outq' , 'bucket_type' , 'bucket' , 'key' ,
30
+ 'object' , 'options' ])
31
+
32
+
33
+ #: A :class:`namedtuple` for tasks that are fed to workers in the
34
+ #: multi put pool.
35
+ PutTask = namedtuple ('PutTask' ,
36
+ ['client' , 'outq' , 'object' , 'options' ])
29
37
30
38
31
39
class MultiPool (object ):
@@ -55,7 +63,7 @@ def enq(self, task):
55
63
stopping.
56
64
57
65
:param task: the Task object
58
- :type task: Task
66
+ :type task: Task or PutTask
59
67
"""
60
68
if not self ._stop .is_set ():
61
69
self ._inq .put (task )
@@ -164,8 +172,13 @@ def _worker_method(self):
164
172
while not self ._should_quit ():
165
173
task = self ._inq .get ()
166
174
try :
167
- robj = task .object
168
- rv = task .client .put (robj , ** task .options )
175
+ obj = task .object
176
+ if isinstance (obj , RiakObject ):
177
+ rv = task .client .put (obj , ** task .options )
178
+ elif isinstance (obj , TsObject ):
179
+ rv = task .client .ts_put (obj , ** task .options )
180
+ else :
181
+ raise ValueError ('unknown obj type: %s' .format (type (obj )))
169
182
task .outq .put (rv )
170
183
except KeyboardInterrupt :
171
184
raise
@@ -236,8 +249,9 @@ def multiput(client, objs, **options):
236
249
237
250
:param client: the client to use
238
251
:type client: :class:`RiakClient <riak.client.RiakClient>`
239
- :param objs: the Riak Objects to store in parallel
240
- :type keys: list of `RiakObject <riak.riak_object.RiakObject>`
252
+ :param objs: the objects to store in parallel
253
+ :type objs: list of `RiakObject <riak.riak_object.RiakObject>` or
254
+ `TsObject <riak.ts_object.TsObject>`
241
255
:param options: request options to
242
256
:meth:`RiakClient.put <riak.client.RiakClient.put>`
243
257
:type options: dict
@@ -252,11 +266,8 @@ def multiput(client, objs, **options):
252
266
pool = RIAK_MULTIPUT_POOL
253
267
254
268
pool .start ()
255
- for robj in objs :
256
- bucket_type = robj .bucket .bucket_type
257
- bucket = robj .bucket .name
258
- key = robj .key
259
- task = Task (client , outq , bucket_type , bucket , key , robj , options )
269
+ for obj in objs :
270
+ task = PutTask (client , outq , obj , options )
260
271
pool .enq (task )
261
272
262
273
results = []
0 commit comments