@@ -23,13 +23,11 @@ class TTask(object):
23
23
24
24
Don't instantiate it with your bare hands
25
25
"""
26
- def __init__ (self , queue , space = 0 , task_id = 0 ,
27
- tube = "" , status = "" , raw_data = None ):
26
+ def __init__ (self , queue , task_id = 0 ,
27
+ tube = "" , raw_data = None ):
28
28
self .task_id = unpack_long_long (task_id )
29
29
self .tube = tube
30
- self .status = status
31
30
self .raw_data = raw_data
32
- self .space = space
33
31
self .queue = queue
34
32
self .modified = False
35
33
@@ -74,12 +72,12 @@ def data(self):
74
72
75
73
def __str__ (self ):
76
74
args = (
77
- self .task_id , self .tube , self .status , self .space
75
+ self .task_id , self .tube , self .queue .space
78
76
)
79
- return "Task (id: {0}, tube:{1}, status: {2}, space:{3 })" .format (* args )
77
+ return "Task (id: {0}, tube:{1}, space:{2 })" .format (* args )
80
78
81
79
def __del__ (self ):
82
- if self . status == 'taken' and not self .modified :
80
+ if not self .modified :
83
81
self .release ()
84
82
85
83
@classmethod
@@ -89,12 +87,12 @@ def from_tuple(cls, queue, the_tuple):
89
87
if the_tuple .rowcount < 1 :
90
88
raise TQueue .ZeroTupleException ('error creating task' )
91
89
row = the_tuple [0 ]
90
+ if len (row ) < 9 :
91
+ raise TQueue .NoDataException ('no data in the task' )
92
92
return cls (
93
93
queue ,
94
- space = queue .space ,
95
94
task_id = row [0 ],
96
95
tube = row [4 ],
97
- status = row [3 ],
98
96
raw_data = row [8 ],
99
97
)
100
98
@@ -110,6 +108,7 @@ class TTube(object):
110
108
"""
111
109
def __init__ (self , queue , name , ** kwargs ):
112
110
self .queue = queue
111
+ self .tube = name
113
112
self .opt = {
114
113
'delay' : 0 ,
115
114
'limits' : 500000 ,
@@ -195,7 +194,7 @@ def put(self, data, **kwargs):
195
194
str (opt ["retry" ]),
196
195
self .serialize (data ))
197
196
)
198
- return the_tuple [0 ][0 ]
197
+ return unpack_long_long ( the_tuple [0 ][0 ])
199
198
200
199
def take (self , timeout = 0 ):
201
200
"""
@@ -255,6 +254,9 @@ class BadConfigException(Exception):
255
254
class ZeroTupleException (Exception ):
256
255
pass
257
256
257
+ class NoDataException (Exception ):
258
+ pass
259
+
258
260
@staticmethod
259
261
def basic_serialize (data ):
260
262
return msgpack .packb (data )
@@ -395,11 +397,6 @@ def _release(self, task_id, prio=0x7fff, delay=0, ttr=300, ttl=0, retry=5):
395
397
the_tuple = self .tnt .call ("box.queue.release" , (
396
398
str (self .space ),
397
399
str (task_id ),
398
- str (prio ),
399
- str (delay ),
400
- str (ttr ),
401
- str (ttl ),
402
- str (retry )
403
400
))
404
401
return TTask .from_tuple (self , the_tuple )
405
402
0 commit comments