@@ -75,6 +75,16 @@ local function tube_release_all_tasks(tube)
75
75
log .info (prefix .. (' released %d tasks' ):format (released ))
76
76
end
77
77
78
+ --- Check whether the task has been taken in a session with
79
+ -- connection id == "conn_id".
80
+ -- Throw an error if task is not take in the session.
81
+ local function check_task_is_taken (tube_id , task_id , conn_id )
82
+ local _taken = box .space ._queue_taken :get {conn_id , tube_id , task_id }
83
+ if _taken == nil then
84
+ error (" Task was not taken in the session" )
85
+ end
86
+ end
87
+
78
88
-- tube methods
79
89
local tube = {}
80
90
@@ -140,10 +150,7 @@ function tube.touch(self, id, delta)
140
150
return
141
151
end
142
152
143
- local _taken = box .space ._queue_taken :get {connection .id (), self .tube_id , id }
144
- if _taken == nil then
145
- error (" Task was not taken in the session" )
146
- end
153
+ check_task_is_taken (self .tube_id , id , connection .id ())
147
154
148
155
local space_name = box .space ._queue :get {self .name }[3 ]
149
156
queue .stat [space_name ]:inc (' touch' )
153
160
154
161
function tube .ack (self , id )
155
162
local conn_id = connection .id ()
156
- local _taken = box .space ._queue_taken :get {conn_id , self .tube_id , id }
157
- if _taken == nil then
158
- error (" Task was not taken in the session" )
159
- end
163
+ check_task_is_taken (self .tube_id , id , conn_id )
160
164
local tube = box .space ._queue :get {self .name }
161
165
local space_name = tube [3 ]
162
166
174
178
175
179
local function tube_release_internal (self , id , opts , connection_id )
176
180
opts = opts or {}
177
- local _taken = box .space ._queue_taken :get {connection_id , self .tube_id , id }
178
- if _taken == nil then
179
- error (" Task was not taken in the session" )
180
- end
181
+ check_task_is_taken (self .tube_id , id , connection_id )
181
182
182
183
box .space ._queue_taken :delete {connection_id , self .tube_id , id }
183
184
self :peek (id )
198
199
199
200
function tube .bury (self , id )
200
201
local task = self :peek (id )
201
- local _taken = box .space ._queue_taken :get {connection .id (), self .tube_id , id }
202
- if _taken ~= nil then
203
- box .space ._queue_taken :delete {connection .id (), self .tube_id , id }
202
+ local conn_id = connection .id ()
203
+ local is_taken , _ = pcall (check_task_is_taken , self .tube_id , id , conn_id )
204
+ if is_taken then
205
+ box .space ._queue_taken :delete {conn_id , self .tube_id , id }
204
206
end
205
207
if task [2 ] == state .BURIED then
206
208
return task
0 commit comments