Skip to content

Commit

Permalink
usability: add driver API check
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LeonidVas authored and Totktonada committed Aug 13, 2020
1 parent c844e06 commit 88a33c9
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions queue/abstract.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,34 @@ end
-- methods
local method = {}

-- List of required driver methods.
local required_driver_methods = {
'normalize_task',
'put',
'take',
'delete',
'release',
'bury',
'kick',
'peek',
'touch',
'truncate',
'tasks_by_state'
}

-- gh-126 Check the driver API.
local function check_driver_api(tube_impl, tube_type)
for _, v in pairs(required_driver_methods) do
if tube_impl[v] == nil then
error(string.format('The "%s" driver does not have an ' ..
'implementation of method "%s".', tube_type, v))
end
end
end

-- Cache of already verified drivers.
local checked_drivers = {}

local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
opts = opts or {}
local self
Expand Down Expand Up @@ -362,6 +390,12 @@ local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
}, {
__index = tube
})

if checked_drivers[tube_type] == nil then
check_driver_api(self.raw, tube_type)
checked_drivers[tube_type] = true
end

self:on_task_change(opts.on_task_change)
queue.tube[tube_name] = self

Expand Down

0 comments on commit 88a33c9

Please sign in to comment.