Skip to content

Commit 8faec74

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 c844e06 commit 8faec74

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

queue/abstract.lua

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,33 @@ 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+
'truncate',
322+
'tasks_by_state'
323+
}
324+
325+
-- gh-126 Check the driver API.
326+
local function check_driver_api(tube_impl, tube_type)
327+
for _, v in pairs(required_driver_methods) do
328+
if tube_impl[v] == nil then
329+
error(string.format('The "%s" driver does not have an ' ..
330+
'implementation of method "%s".', tube_type, v))
331+
end
332+
end
333+
end
334+
335+
-- Cache of already verified drivers.
336+
local checked_drivers = {}
337+
311338
local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
312339
opts = opts or {}
313340
local self
@@ -362,6 +389,12 @@ local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
362389
}, {
363390
__index = tube
364391
})
392+
393+
if checked_drivers[tube_type] == nil then
394+
check_driver_api(self.raw, tube_type)
395+
checked_drivers[tube_type] = true
396+
end
397+
365398
self:on_task_change(opts.on_task_change)
366399
queue.tube[tube_name] = self
367400

0 commit comments

Comments
 (0)