Skip to content

Add driver API check #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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