Skip to content

Commit 88a33c9

Browse files
LeonidVasTotktonada
authored andcommitted
usability: add driver API check
In addition to the core queue drivers, customer drivers are exists. In the commit a check for a driver API implementation was added. Now, the consumer will be informed about the missing methods in the driver implementation. Closes #126
1 parent c844e06 commit 88a33c9

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Diff for: queue/abstract.lua

+34
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,34 @@ end
308308
-- methods
309309
local method = {}
310310

311+
-- List of required driver methods.
312+
local required_driver_methods = {
313+
'normalize_task',
314+
'put',
315+
'take',
316+
'delete',
317+
'release',
318+
'bury',
319+
'kick',
320+
'peek',
321+
'touch',
322+
'truncate',
323+
'tasks_by_state'
324+
}
325+
326+
-- gh-126 Check the driver API.
327+
local function check_driver_api(tube_impl, tube_type)
328+
for _, v in pairs(required_driver_methods) do
329+
if tube_impl[v] == nil then
330+
error(string.format('The "%s" driver does not have an ' ..
331+
'implementation of method "%s".', tube_type, v))
332+
end
333+
end
334+
end
335+
336+
-- Cache of already verified drivers.
337+
local checked_drivers = {}
338+
311339
local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
312340
opts = opts or {}
313341
local self
@@ -362,6 +390,12 @@ local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
362390
}, {
363391
__index = tube
364392
})
393+
394+
if checked_drivers[tube_type] == nil then
395+
check_driver_api(self.raw, tube_type)
396+
checked_drivers[tube_type] = true
397+
end
398+
365399
self:on_task_change(opts.on_task_change)
366400
queue.tube[tube_name] = self
367401

0 commit comments

Comments
 (0)