Skip to content

Commit 8a3bf9e

Browse files
committed
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 66c9ca6 commit 8a3bf9e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

queue/abstract.lua

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,45 @@ end
314314
-- methods
315315
local method = {}
316316

317+
-- Original list of required driver methods.
318+
local required_driver_methods = {
319+
'normalize_task',
320+
'put',
321+
'take',
322+
'delete',
323+
'release',
324+
'bury',
325+
'kick',
326+
'peek',
327+
'truncate'
328+
}
329+
330+
-- List of driver methods that were added to the original list.
331+
local new_driver_methods = {
332+
'tasks_by_state'
333+
}
334+
335+
-- gh-126 Check the driver API.
336+
local function check_driver_api(tube_impl, tube_type)
337+
for _, v in pairs(required_driver_methods) do
338+
if tube_impl[v] == nil then
339+
error('The "' .. tube_type ..'" driver does not have an'
340+
.. ' implementation of method "' .. v ..'".')
341+
end
342+
end
343+
344+
for _, v in pairs(new_driver_methods) do
345+
if tube_impl[v] == nil then
346+
log.warn('The "' .. tube_type ..'" driver doesn\'t have an'
347+
.. ' implementation of method "' .. v ..'". Some queue'
348+
.. ' functionality may not work properly.')
349+
end
350+
end
351+
end
352+
353+
-- Cache of already verified drivers.
354+
local checked_drivers = {}
355+
317356
local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
318357
opts = opts or {}
319358
local self
@@ -368,6 +407,12 @@ local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
368407
}, {
369408
__index = tube
370409
})
410+
411+
if checked_drivers[tube_type] == nil then
412+
check_driver_api(self.raw, tube_type)
413+
checked_drivers[tube_type] = true
414+
end
415+
371416
self:on_task_change(opts.on_task_change)
372417
queue.tube[tube_name] = self
373418

0 commit comments

Comments
 (0)