Skip to content

Commit c3cdc7b

Browse files
0x501DLeonidVas
authored andcommitted
abstract: check_state verbose error logging
1 parent 03177cc commit c3cdc7b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

queue/abstract.lua

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,17 @@ end
8888
local tube = {}
8989

9090
-- This check must be called from all public tube methods.
91-
local function check_state()
91+
local function check_state(method)
9292
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()))
9494
return false
9595
end
9696

9797
return true
9898
end
9999

100100
function tube.put(self, data, opts)
101-
if not check_state() then
101+
if not check_state("put") then
102102
return nil
103103
end
104104
opts = opts or {}
@@ -110,7 +110,7 @@ local conds = {}
110110
local releasing_connections = {}
111111

112112
function tube.take(self, timeout)
113-
if not check_state() then
113+
if not check_state("take") then
114114
return nil
115115
end
116116
timeout = util.time(timeout or util.TIMEOUT_INFINITY)
@@ -151,7 +151,7 @@ function tube.take(self, timeout)
151151
end
152152

153153
function tube.touch(self, id, delta)
154-
if not check_state() then
154+
if not check_state("touch") then
155155
return
156156
end
157157
if delta == nil then
@@ -177,7 +177,7 @@ function tube.touch(self, id, delta)
177177
end
178178

179179
function tube.ack(self, id)
180-
if not check_state() then
180+
if not check_state("ack") then
181181
return nil
182182
end
183183
check_task_is_taken(self.tube_id, id)
@@ -206,15 +206,15 @@ local function tube_release_internal(self, id, opts, session_uuid)
206206
end
207207

208208
function tube.release(self, id, opts)
209-
if not check_state() then
209+
if not check_state("release") then
210210
return nil
211211
end
212212
return tube_release_internal(self, id, opts)
213213
end
214214

215215
-- Release all tasks.
216216
function tube.release_all(self)
217-
if not check_state() then
217+
if not check_state("tube") then
218218
return
219219
end
220220
local prefix = ('queue: [tube "%s"] '):format(self.name)
@@ -229,7 +229,7 @@ function tube.release_all(self)
229229
end
230230

231231
function tube.peek(self, id)
232-
if not check_state() then
232+
if not check_state("peek") then
233233
return nil
234234
end
235235
local task = self.raw:peek(id)
@@ -240,7 +240,7 @@ function tube.peek(self, id)
240240
end
241241

242242
function tube.bury(self, id)
243-
if not check_state() then
243+
if not check_state("bury") then
244244
return nil
245245
end
246246
local task = self:peek(id)
@@ -255,15 +255,15 @@ function tube.bury(self, id)
255255
end
256256

257257
function tube.kick(self, count)
258-
if not check_state() then
258+
if not check_state("kick") then
259259
return nil
260260
end
261261
count = count or 1
262262
return self.raw:kick(count)
263263
end
264264

265265
function tube.delete(self, id)
266-
if not check_state() then
266+
if not check_state("delete") then
267267
return nil
268268
end
269269
self:peek(id)
@@ -272,7 +272,7 @@ end
272272

273273
-- drop tube
274274
function tube.drop(self)
275-
if not check_state() then
275+
if not check_state("drop") then
276276
return nil
277277
end
278278
local tube_name = self.name
@@ -309,7 +309,7 @@ end
309309
-- truncate tube
310310
-- (delete everything from tube)
311311
function tube.truncate(self)
312-
if not check_state() then
312+
if not check_state("truncate") then
313313
return
314314
end
315315
self.raw:truncate()
@@ -322,7 +322,7 @@ function tube.on_task_change(self, cb)
322322
end
323323

324324
function tube.grant(self, user, args)
325-
if not check_state() then
325+
if not check_state("grant") then
326326
return
327327
end
328328
local function tube_grant_space(user, name, tp)
@@ -583,7 +583,7 @@ end
583583
-------------------------------------------------------------------------------
584584
-- create tube
585585
function method.create_tube(tube_name, tube_type, opts)
586-
if not check_state() then
586+
if not check_state("create_tube") then
587587
return
588588
end
589589
opts = opts or {}

0 commit comments

Comments
 (0)