88
88
local tube = {}
89
89
90
90
-- This check must be called from all public tube methods.
91
- local function check_state ()
91
+ local function check_state (method )
92
92
if queue_state .get () ~= queue_state .states .RUNNING then
93
- log .error ((' Queue is in %s state' ):format (queue_state .show ()))
93
+ log .error ((' %s: queue is in %s state' ):format (method , queue_state .show ()))
94
94
return false
95
95
end
96
96
97
97
return true
98
98
end
99
99
100
100
function tube .put (self , data , opts )
101
- if not check_state () then
101
+ if not check_state (" put " ) then
102
102
return nil
103
103
end
104
104
opts = opts or {}
@@ -110,7 +110,7 @@ local conds = {}
110
110
local releasing_connections = {}
111
111
112
112
function tube .take (self , timeout )
113
- if not check_state () then
113
+ if not check_state (" take " ) then
114
114
return nil
115
115
end
116
116
timeout = util .time (timeout or util .TIMEOUT_INFINITY )
@@ -151,7 +151,7 @@ function tube.take(self, timeout)
151
151
end
152
152
153
153
function tube .touch (self , id , delta )
154
- if not check_state () then
154
+ if not check_state (" touch " ) then
155
155
return
156
156
end
157
157
if delta == nil then
@@ -177,7 +177,7 @@ function tube.touch(self, id, delta)
177
177
end
178
178
179
179
function tube .ack (self , id )
180
- if not check_state () then
180
+ if not check_state (" ack " ) then
181
181
return nil
182
182
end
183
183
check_task_is_taken (self .tube_id , id )
@@ -206,15 +206,15 @@ local function tube_release_internal(self, id, opts, session_uuid)
206
206
end
207
207
208
208
function tube .release (self , id , opts )
209
- if not check_state () then
209
+ if not check_state (" release " ) then
210
210
return nil
211
211
end
212
212
return tube_release_internal (self , id , opts )
213
213
end
214
214
215
215
-- Release all tasks.
216
216
function tube .release_all (self )
217
- if not check_state () then
217
+ if not check_state (" tube " ) then
218
218
return
219
219
end
220
220
local prefix = (' queue: [tube "%s"] ' ):format (self .name )
@@ -229,7 +229,7 @@ function tube.release_all(self)
229
229
end
230
230
231
231
function tube .peek (self , id )
232
- if not check_state () then
232
+ if not check_state (" peek " ) then
233
233
return nil
234
234
end
235
235
local task = self .raw :peek (id )
@@ -240,7 +240,7 @@ function tube.peek(self, id)
240
240
end
241
241
242
242
function tube .bury (self , id )
243
- if not check_state () then
243
+ if not check_state (" bury " ) then
244
244
return nil
245
245
end
246
246
local task = self :peek (id )
@@ -255,15 +255,15 @@ function tube.bury(self, id)
255
255
end
256
256
257
257
function tube .kick (self , count )
258
- if not check_state () then
258
+ if not check_state (" kick " ) then
259
259
return nil
260
260
end
261
261
count = count or 1
262
262
return self .raw :kick (count )
263
263
end
264
264
265
265
function tube .delete (self , id )
266
- if not check_state () then
266
+ if not check_state (" delete " ) then
267
267
return nil
268
268
end
269
269
self :peek (id )
272
272
273
273
-- drop tube
274
274
function tube .drop (self )
275
- if not check_state () then
275
+ if not check_state (" drop " ) then
276
276
return nil
277
277
end
278
278
local tube_name = self .name
309
309
-- truncate tube
310
310
-- (delete everything from tube)
311
311
function tube .truncate (self )
312
- if not check_state () then
312
+ if not check_state (" truncate " ) then
313
313
return
314
314
end
315
315
self .raw :truncate ()
@@ -322,7 +322,7 @@ function tube.on_task_change(self, cb)
322
322
end
323
323
324
324
function tube .grant (self , user , args )
325
- if not check_state () then
325
+ if not check_state (" grant " ) then
326
326
return
327
327
end
328
328
local function tube_grant_space (user , name , tp )
583
583
---- ---------------------------------------------------------------------------
584
584
-- create tube
585
585
function method .create_tube (tube_name , tube_type , opts )
586
- if not check_state () then
586
+ if not check_state (" create_tube " ) then
587
587
return
588
588
end
589
589
opts = opts or {}
0 commit comments