@@ -75,6 +75,12 @@ local function tube_release_all_tasks(tube)
75
75
return
76
76
end
77
77
78
+ -- Custom drivers may not have an implementation of
79
+ -- the "tasks_by_state" method.
80
+ if tube .raw [" tasks_by_state" ] == nil then
81
+ return
82
+ end
83
+
78
84
log .info (prefix .. ' releasing all taken task (may take a while)' )
79
85
local released = 0
80
86
for _ , task in tube .raw :tasks_by_state (state .TAKEN ) do
308
314
-- methods
309
315
local method = {}
310
316
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
+
311
356
local function make_self (driver , space , tube_name , tube_type , tube_id , opts )
312
357
opts = opts or {}
313
358
local self
@@ -362,6 +407,12 @@ local function make_self(driver, space, tube_name, tube_type, tube_id, opts)
362
407
}, {
363
408
__index = tube
364
409
})
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
+
365
416
self :on_task_change (opts .on_task_change )
366
417
queue .tube [tube_name ] = self
367
418
0 commit comments