Skip to content

Add ability to pass args to start_key function #114

@ArtDu

Description

@ArtDu

expirationd/expirationd.lua

Lines 691 to 698 in c3b86c8

-- check start_key
if options.start_key ~= nil or options.start_key == box.NULL then
if type(options.start_key) == "function" then
task.start_key = function() return options.start_key() end
else
task.start_key = function() return options.start_key end
end
end

expirationd/expirationd.lua

Lines 382 to 390 in c3b86c8

-- default iterate_with function
local function default_iterate_with(task)
return task.index:pairs(task.start_key(), { iterator = task.iterator_type })
:take_while(
function()
return task:process_while()
end
)
end

Should be rewritten to:

-- check start_key 
 if options.start_key ~= nil or options.start_key == box.NULL then 
     if type(options.start_key) == "function" then 
         task.start_key = function(...) return options.start_key(...) end 
     else 
         task.start_key = function() return options.start_key end 
     end 
 end 
-- default iterate_with function
local function default_iterate_with(task)
    return task.index:pairs(task.start_key(task.args), { iterator = task.iterator_type })
       :take_while(
            function()
                return task:process_while()
            end
        )
end

Or should we pass task as it says in README?

expirationd/README.md

Lines 94 to 129 in c3b86c8

```lua
expirationd.start(job_name, space.id, is_expired, {
-- name or id of the index in the specified space to iterate over
index = "exp",
-- one transaction per batch
-- default is false
atomic_iteration = true,
-- delete data that was added a year ago
-- default is nil
start_key = function( task )
return clock.time() - (365*24*60*60)
end,
-- delete it from the oldest to the newest
-- default is ALL
iterator_type = "GE",
-- stop full_scan if delete a lot
-- returns true by default
process_while = function( task )
if task.args.max_expired_tuples >= task.expired_tuples_count then
task.expired_tuples_count = 0
return false
end
return true
end,
-- this function must return an iterator over the tuples
iterate_with = function( task )
return task.index:pairs({ task.start_key() }, { iterator = task.iterator_type })
:take_while( function( tuple )
return task:process_while()
end )
end,
args = {
max_expired_tuples = 1000
}
})
```

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions